1 description("Series of tests for Canvas.isPointInPath");
3 ctx = document.getElementById("canvas").getContext("2d");
5 debug("Rectangle at (0,0) 20x20");
6 ctx.rect(0, 0, 20, 20);
7 shouldBe("ctx.isPointInPath(5, 5)", "true");
8 shouldBe("ctx.isPointInPath(10, 10)", "true");
9 shouldBe("ctx.isPointInPath(19, 19)", "true");
10 shouldBe("ctx.isPointInPath(30, 30)", "false");
11 shouldBe("ctx.isPointInPath(-1, 10)", "false");
12 shouldBe("ctx.isPointInPath(10, -1)", "false");
13 debug("Translate context (10,10)");
15 shouldBe("ctx.isPointInPath(5, 5)", "true");
16 shouldBe("ctx.isPointInPath(10, 10)", "true");
17 shouldBe("ctx.isPointInPath(19, 19)", "true");
18 shouldBe("ctx.isPointInPath(30, 30)", "false");
19 shouldBe("ctx.isPointInPath(-1, 10)", "false");
20 shouldBe("ctx.isPointInPath(10, -1)", "false");
21 debug("Collapse ctm to non-invertible matrix");
23 shouldBe("ctx.isPointInPath(5, 5)", "false");
24 shouldBe("ctx.isPointInPath(10, 10)", "false");
25 shouldBe("ctx.isPointInPath(20, 20)", "false");
26 shouldBe("ctx.isPointInPath(30, 30)", "false");
27 shouldBe("ctx.isPointInPath(-1, 10)", "false");
28 shouldBe("ctx.isPointInPath(10, -1)", "false");
29 debug("Resetting context to a clean state");
34 debug("Translate context (10,10)");
36 debug("Rectangle at (0,0) 20x20");
37 ctx.rect(0, 0, 20, 20);
38 shouldBe("ctx.isPointInPath(5, 5)", "false");
39 shouldBe("ctx.isPointInPath(10, 10)", "true");
40 shouldBe("ctx.isPointInPath(20, 20)", "true");
41 shouldBe("ctx.isPointInPath(29, 29)", "true");
42 shouldBe("ctx.isPointInPath(-1, 10)", "false");
43 shouldBe("ctx.isPointInPath(10, -1)", "false");
48 debug("Translate context (10,20)");
50 debug("Transform context (1, 0, 0, -1, 0, 0)");
51 ctx.transform(1, 0, 0, -1, 0, 0);
52 debug("Rectangle at (0,0) 20x20");
53 ctx.rect(0, 0, 20, 20);
54 // After the flip, rect is actually 10, 0, 20, 20
55 shouldBe("ctx.isPointInPath(5, 5)", "false");
56 shouldBe("ctx.isPointInPath(10, 0)", "true");
57 shouldBe("ctx.isPointInPath(29, 0)", "true");
58 shouldBe("ctx.isPointInPath(10, 19)", "true");
59 shouldBe("ctx.isPointInPath(21, 10)", "true");
60 shouldBe("ctx.isPointInPath(29, 19)", "true");
61 ctx.strokeStyle = 'green';