summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/pointInPath.js
blob: d678648a0db764c58218174aee5a5ccc49170871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
description("Series of tests for Canvas.isPointInPath");

ctx = document.getElementById("canvas").getContext("2d");
ctx.save();
debug("Rectangle at (0,0) 20x20");
ctx.rect(0, 0, 20, 20);
shouldBe("ctx.isPointInPath(5, 5)", "true");
shouldBe("ctx.isPointInPath(10, 10)", "true");
shouldBe("ctx.isPointInPath(19, 19)", "true");
shouldBe("ctx.isPointInPath(30, 30)", "false");
shouldBe("ctx.isPointInPath(-1, 10)", "false");
shouldBe("ctx.isPointInPath(10, -1)", "false");
debug("Translate context (10,10)");
ctx.translate(10,10);
shouldBe("ctx.isPointInPath(5, 5)", "true");
shouldBe("ctx.isPointInPath(10, 10)", "true");
shouldBe("ctx.isPointInPath(19, 19)", "true");
shouldBe("ctx.isPointInPath(30, 30)", "false");
shouldBe("ctx.isPointInPath(-1, 10)", "false");
shouldBe("ctx.isPointInPath(10, -1)", "false");
debug("Collapse ctm to non-invertible matrix");
ctx.scale(0,0);
shouldBe("ctx.isPointInPath(5, 5)", "false");
shouldBe("ctx.isPointInPath(10, 10)", "false");
shouldBe("ctx.isPointInPath(20, 20)", "false");
shouldBe("ctx.isPointInPath(30, 30)", "false");
shouldBe("ctx.isPointInPath(-1, 10)", "false");
shouldBe("ctx.isPointInPath(10, -1)", "false");
debug("Resetting context to a clean state");
ctx.restore();

ctx.save();
ctx.beginPath();
debug("Translate context (10,10)");
ctx.translate(10,10);
debug("Rectangle at (0,0) 20x20");
ctx.rect(0, 0, 20, 20);
shouldBe("ctx.isPointInPath(5, 5)", "false");
shouldBe("ctx.isPointInPath(10, 10)", "true");
shouldBe("ctx.isPointInPath(20, 20)", "true");
shouldBe("ctx.isPointInPath(29, 29)", "true");
shouldBe("ctx.isPointInPath(-1, 10)", "false");
shouldBe("ctx.isPointInPath(10, -1)", "false");
ctx.restore();

ctx.save();
ctx.beginPath();
debug("Translate context (10,20)");
ctx.translate(10,20);
debug("Transform context (1, 0, 0, -1, 0, 0)");
ctx.transform(1, 0, 0, -1, 0, 0);
debug("Rectangle at (0,0) 20x20");
ctx.rect(0, 0, 20, 20);
// After the flip, rect is actually 10, 0, 20, 20
shouldBe("ctx.isPointInPath(5, 5)", "false");
shouldBe("ctx.isPointInPath(10, 0)", "true");
shouldBe("ctx.isPointInPath(29, 0)", "true");
shouldBe("ctx.isPointInPath(10, 19)", "true");
shouldBe("ctx.isPointInPath(21, 10)", "true");
shouldBe("ctx.isPointInPath(29, 19)", "true");
ctx.strokeStyle = 'green';
ctx.stroke();
ctx.restore();