OLD | NEW |
| (Empty) |
1 description("Test the behavior of isPointInStroke in Canvas with path object"); | |
2 var ctx = document.createElement('canvas').getContext('2d'); | |
3 | |
4 document.body.appendChild(ctx.canvas); | |
5 | |
6 ctx.strokeStyle = '#0ff'; | |
7 | |
8 // Create new path. | |
9 var path = new Path2D(); | |
10 path.rect(20,20,100,100); | |
11 | |
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)"); | |
31 debug(""); | |
32 | |
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)"); | |
38 debug(""); | |
39 | |
40 debug("Set lineWidth = 10.0"); | |
41 ctx.lineWidth = 10; | |
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)"); | |
54 debug(""); | |
55 | |
56 debug("Check lineJoin = 'bevel'"); | |
57 path = new Path2D(); | |
58 path.moveTo(10,10); | |
59 path.lineTo(110,20); | |
60 path.lineTo(10,30); | |
61 ctx.lineJoin = "bevel"; | |
62 shouldBeFalse("ctx.isPointInStroke(path,113,20)"); | |
63 debug(""); | |
64 | |
65 debug("Check lineJoin = 'miter'"); | |
66 ctx.miterLimit = 40.0; | |
67 ctx.lineJoin = "miter"; | |
68 shouldBeTrue("ctx.isPointInStroke(path,113,20)"); | |
69 debug(""); | |
70 | |
71 debug("Check miterLimit = 2.0"); | |
72 ctx.miterLimit = 2.0; | |
73 shouldBeFalse("ctx.isPointInStroke(path,113,20)"); | |
74 debug(""); | |
75 | |
76 debug("Check lineCap = 'butt'"); | |
77 path = new Path2D(); | |
78 path.moveTo(10,10); | |
79 path.lineTo(110,10); | |
80 ctx.lineCap = "butt"; | |
81 shouldBeFalse("ctx.isPointInStroke(path,112,10)"); | |
82 debug(""); | |
83 | |
84 debug("Check lineCap = 'round'"); | |
85 ctx.lineCap = "round"; | |
86 shouldBeTrue("ctx.isPointInStroke(path,112,10)"); | |
87 shouldBeFalse("ctx.isPointInStroke(path,117,10)"); | |
88 debug(""); | |
89 | |
90 debug("Check lineCap = 'square'"); | |
91 ctx.lineCap = "square"; | |
92 shouldBeTrue("ctx.isPointInStroke(path,112,10)"); | |
93 shouldBeFalse("ctx.isPointInStroke(path,117,10)"); | |
94 debug(""); | |
95 | |
96 debug("Check setLineDash([10,10])"); | |
97 ctx.lineCap = "butt"; | |
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)"); | |
102 debug(""); | |
103 | |
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)"); | |
OLD | NEW |