1 description("Test the behavior of isPointInStroke in Canvas with path object");
2 var ctx = document.createElement('canvas').getContext('2d');
4 document.body.appendChild(ctx.canvas);
6 ctx.strokeStyle = '#0ff';
9 var path = new Path2D();
10 path.rect(20,20,100,100);
12 debug("Initial behavior: lineWidth = 1.0")
13 shouldBeTrue("ctx.isPointInStroke(path,20,20)");
14 shouldBeTrue("ctx.isPointInStroke(path,120,20)");
15 shouldBeTrue("ctx.isPointInStroke(path,20,120)");
16 shouldBeTrue("ctx.isPointInStroke(path,120,120)");
17 shouldBeTrue("ctx.isPointInStroke(path,70,20)");
18 shouldBeTrue("ctx.isPointInStroke(path,20,70)");
19 shouldBeTrue("ctx.isPointInStroke(path,120,70)");
20 shouldBeTrue("ctx.isPointInStroke(path,70,120)");
21 shouldBeFalse("ctx.isPointInStroke(path,22,22)");
22 shouldBeFalse("ctx.isPointInStroke(path,118,22)");
23 shouldBeFalse("ctx.isPointInStroke(path,22,118)");
24 shouldBeFalse("ctx.isPointInStroke(path,118,118)");
25 shouldBeFalse("ctx.isPointInStroke(path,70,18)");
26 shouldBeFalse("ctx.isPointInStroke(path,122,70)");
27 shouldBeFalse("ctx.isPointInStroke(path,70,122)");
28 shouldBeFalse("ctx.isPointInStroke(path,18,70)");
29 shouldBeFalse("ctx.isPointInStroke(path,NaN,122)");
30 shouldBeFalse("ctx.isPointInStroke(path,18,NaN)");
33 debug("Check invalid type");
34 shouldThrow("ctx.isPointInStroke(null,70,20)");
35 shouldThrow("ctx.isPointInStroke(undefined,70,20)");
36 shouldThrow("ctx.isPointInStroke([],20,70)");
37 shouldThrow("ctx.isPointInStroke({},120,70)");
40 debug("Set lineWidth = 10.0");
42 shouldBeTrue("ctx.isPointInStroke(path,22,22)");
43 shouldBeTrue("ctx.isPointInStroke(path,118,22)");
44 shouldBeTrue("ctx.isPointInStroke(path,22,118)");
45 shouldBeTrue("ctx.isPointInStroke(path,118,118)");
46 shouldBeTrue("ctx.isPointInStroke(path,70,18)");
47 shouldBeTrue("ctx.isPointInStroke(path,122,70)");
48 shouldBeTrue("ctx.isPointInStroke(path,70,122)");
49 shouldBeTrue("ctx.isPointInStroke(path,18,70)");
50 shouldBeFalse("ctx.isPointInStroke(path,26,70)");
51 shouldBeFalse("ctx.isPointInStroke(path,70,26)");
52 shouldBeFalse("ctx.isPointInStroke(path,70,114)");
53 shouldBeFalse("ctx.isPointInStroke(path,114,70)");
56 debug("Check lineJoin = 'bevel'");
61 ctx.lineJoin = "bevel";
62 shouldBeFalse("ctx.isPointInStroke(path,113,20)");
65 debug("Check lineJoin = 'miter'");
66 ctx.miterLimit = 40.0;
67 ctx.lineJoin = "miter";
68 shouldBeTrue("ctx.isPointInStroke(path,113,20)");
71 debug("Check miterLimit = 2.0");
73 shouldBeFalse("ctx.isPointInStroke(path,113,20)");
76 debug("Check lineCap = 'butt'");
81 shouldBeFalse("ctx.isPointInStroke(path,112,10)");
84 debug("Check lineCap = 'round'");
85 ctx.lineCap = "round";
86 shouldBeTrue("ctx.isPointInStroke(path,112,10)");
87 shouldBeFalse("ctx.isPointInStroke(path,117,10)");
90 debug("Check lineCap = 'square'");
91 ctx.lineCap = "square";
92 shouldBeTrue("ctx.isPointInStroke(path,112,10)");
93 shouldBeFalse("ctx.isPointInStroke(path,117,10)");
96 debug("Check setLineDash([10,10])");
98 ctx.setLineDash([10,10]);
99 shouldBeTrue("ctx.isPointInStroke(path,15,10)");
100 shouldBeFalse("ctx.isPointInStroke(path,25,10)");
101 shouldBeTrue("ctx.isPointInStroke(path,35,10)");
104 debug("Check dashOffset = 10");
105 ctx.lineDashOffset = 10;
106 shouldBeFalse("ctx.isPointInStroke(path,15,10)");
107 shouldBeTrue("ctx.isPointInStroke(path,25,10)");
108 shouldBeFalse("ctx.isPointInStroke(path,35,10)");