1 description("Series of tests to ensure correct results of the winding rule in isPointInPath.");
3 var tmpimg = document.createElement('canvas');
6 ctx = tmpimg.getContext('2d');
9 function prepareTestScenario() {
10 debug('Testing default isPointInPath');
12 ctx.rect(0, 0, 100, 100);
13 ctx.rect(25, 25, 50, 50);
14 shouldBeTrue("ctx.isPointInPath(50, 50)");
15 shouldBeFalse("ctx.isPointInPath(NaN, 50)");
16 shouldBeFalse("ctx.isPointInPath(50, NaN)");
19 debug('Testing nonzero isPointInPath');
21 ctx.rect(0, 0, 100, 100);
22 ctx.rect(25, 25, 50, 50);
23 shouldBeTrue("ctx.isPointInPath(50, 50, 'nonzero')");
26 debug('Testing evenodd isPointInPath');
28 ctx.rect(0, 0, 100, 100);
29 ctx.rect(25, 25, 50, 50);
30 shouldBeFalse("ctx.isPointInPath(50, 50, 'evenodd')");
33 // reset path in context
36 debug('Testing default isPointInPath with Path object');
38 path.rect(0, 0, 100, 100);
39 path.rect(25, 25, 50, 50);
40 shouldBeTrue("ctx.isPointInPath(path, 50, 50)");
41 shouldBeFalse("ctx.isPointInPath(path, NaN, 50)");
42 shouldBeFalse("ctx.isPointInPath(path, 50, NaN)");
45 debug('Testing nonzero isPointInPath with Path object');
47 path.rect(0, 0, 100, 100);
48 path.rect(25, 25, 50, 50);
49 shouldBeTrue("ctx.isPointInPath(path, 50, 50, 'nonzero')");
52 debug('Testing evenodd isPointInPath with Path object');
54 path.rect(0, 0, 100, 100);
55 path.rect(25, 25, 50, 50);
56 shouldBeFalse("ctx.isPointInPath(path, 50, 50, 'evenodd')");
59 debug('Testing invalid enumeration isPointInPath (w/ and w/o Path object');
60 shouldThrow("ctx.isPointInPath(path, 50, 50, 'gazonk')");
61 shouldThrow("ctx.isPointInPath(50, 50, 'gazonk')");
64 debug('Testing invalid type isPointInPath with Path object');
65 shouldThrow("ctx.isPointInPath(null, 50, 50)");
66 shouldThrow("ctx.isPointInPath(null, 50, 50, 'nonzero')");
67 shouldThrow("ctx.isPointInPath(null, 50, 50, 'evenodd')");
68 shouldThrow("ctx.isPointInPath(null, 50, 50, null)");
69 shouldThrow("ctx.isPointInPath(path, 50, 50, null)");
70 shouldThrow("ctx.isPointInPath(undefined, 50, 50)");
71 shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'nonzero')");
72 shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'evenodd')");
73 shouldThrow("ctx.isPointInPath(undefined, 50, 50, undefined)");
74 shouldThrow("ctx.isPointInPath(path, 50, 50, undefined)");
75 shouldThrow("ctx.isPointInPath([], 50, 50)");
76 shouldThrow("ctx.isPointInPath([], 50, 50, 'nonzero')");
77 shouldThrow("ctx.isPointInPath([], 50, 50, 'evenodd')");
78 shouldThrow("ctx.isPointInPath({}, 50, 50)");
79 shouldThrow("ctx.isPointInPath({}, 50, 50, 'nonzero')");
80 shouldThrow("ctx.isPointInPath({}, 50, 50, 'evenodd')");
83 debug("Testing extremely large scale")
85 ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE);
87 ctx.rect(-10, -10, 20, 20);
88 shouldBeTrue("ctx.isPointInPath(0, 0, 'nonzero')");
89 shouldBeTrue("ctx.isPointInPath(0, 0, 'evenodd')");
92 debug("Check with non-invertible ctm.")
96 ctx.rect(-10, -10, 20, 20);
97 shouldBeFalse("ctx.isPointInPath(0, 0, 'nonzero')");
98 shouldBeFalse("ctx.isPointInPath(0, 0, 'evenodd')");
102 // Run test and allow variation of results.
103 prepareTestScenario();