| OLD | NEW |
| (Empty) |
| 1 description("Series of tests to ensure correct results of the winding rule in is
PointInPath."); | |
| 2 | |
| 3 var tmpimg = document.createElement('canvas'); | |
| 4 tmpimg.width = 200; | |
| 5 tmpimg.height = 200; | |
| 6 ctx = tmpimg.getContext('2d'); | |
| 7 | |
| 8 // Execute test. | |
| 9 function prepareTestScenario() { | |
| 10 debug('Testing default isPointInPath'); | |
| 11 ctx.beginPath(); | |
| 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)"); | |
| 17 debug(''); | |
| 18 | |
| 19 debug('Testing nonzero isPointInPath'); | |
| 20 ctx.beginPath(); | |
| 21 ctx.rect(0, 0, 100, 100); | |
| 22 ctx.rect(25, 25, 50, 50); | |
| 23 shouldBeTrue("ctx.isPointInPath(50, 50, 'nonzero')"); | |
| 24 debug(''); | |
| 25 | |
| 26 debug('Testing evenodd isPointInPath'); | |
| 27 ctx.beginPath(); | |
| 28 ctx.rect(0, 0, 100, 100); | |
| 29 ctx.rect(25, 25, 50, 50); | |
| 30 shouldBeFalse("ctx.isPointInPath(50, 50, 'evenodd')"); | |
| 31 debug(''); | |
| 32 | |
| 33 // reset path in context | |
| 34 ctx.beginPath(); | |
| 35 | |
| 36 debug('Testing default isPointInPath with Path object'); | |
| 37 path = new Path2D(); | |
| 38 path.rect(0, 0, 100, 100); | |
| 39 path.rect(25, 25, 50, 50); | |
| 40 shouldBeTrue("ctx.isPointInPath(path, 50, 50)"); | |
| 41 shouldBeTrue("ctx.isPointInPath(path, 50, 50, undefined)"); | |
| 42 shouldBeFalse("ctx.isPointInPath(path, NaN, 50)"); | |
| 43 shouldBeFalse("ctx.isPointInPath(path, 50, NaN)"); | |
| 44 debug(''); | |
| 45 | |
| 46 debug('Testing nonzero isPointInPath with Path object'); | |
| 47 path = new Path2D(); | |
| 48 path.rect(0, 0, 100, 100); | |
| 49 path.rect(25, 25, 50, 50); | |
| 50 shouldBeTrue("ctx.isPointInPath(path, 50, 50, 'nonzero')"); | |
| 51 debug(''); | |
| 52 | |
| 53 debug('Testing evenodd isPointInPath with Path object'); | |
| 54 path = new Path2D(); | |
| 55 path.rect(0, 0, 100, 100); | |
| 56 path.rect(25, 25, 50, 50); | |
| 57 shouldBeFalse("ctx.isPointInPath(path, 50, 50, 'evenodd')"); | |
| 58 debug(''); | |
| 59 | |
| 60 debug('Testing invalid enumeration isPointInPath (w/ and w/o Path object'); | |
| 61 shouldThrow("ctx.isPointInPath(path, 50, 50, 'gazonk')"); | |
| 62 shouldThrow("ctx.isPointInPath(50, 50, 'gazonk')"); | |
| 63 debug(''); | |
| 64 | |
| 65 debug('Testing invalid type isPointInPath with Path object'); | |
| 66 shouldThrow("ctx.isPointInPath(null, 50, 50)"); | |
| 67 shouldThrow("ctx.isPointInPath(null, 50, 50, 'nonzero')"); | |
| 68 shouldThrow("ctx.isPointInPath(null, 50, 50, 'evenodd')"); | |
| 69 shouldThrow("ctx.isPointInPath(null, 50, 50, null)"); | |
| 70 shouldThrow("ctx.isPointInPath(path, 50, 50, null)"); | |
| 71 shouldThrow("ctx.isPointInPath(undefined, 50, 50)"); | |
| 72 shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'nonzero')"); | |
| 73 shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'evenodd')"); | |
| 74 shouldThrow("ctx.isPointInPath(undefined, 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')"); | |
| 81 debug(''); | |
| 82 | |
| 83 debug("Testing extremely large scale") | |
| 84 ctx.save(); | |
| 85 ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE); | |
| 86 ctx.beginPath(); | |
| 87 ctx.rect(-10, -10, 20, 20); | |
| 88 shouldBeTrue("ctx.isPointInPath(0, 0, 'nonzero')"); | |
| 89 shouldBeTrue("ctx.isPointInPath(0, 0, 'evenodd')"); | |
| 90 ctx.restore(); | |
| 91 | |
| 92 debug("Check with non-invertible ctm.") | |
| 93 ctx.save(); | |
| 94 ctx.scale(0, 0); | |
| 95 ctx.beginPath(); | |
| 96 ctx.rect(-10, -10, 20, 20); | |
| 97 shouldBeFalse("ctx.isPointInPath(0, 0, 'nonzero')"); | |
| 98 shouldBeFalse("ctx.isPointInPath(0, 0, 'evenodd')"); | |
| 99 ctx.restore(); | |
| 100 } | |
| 101 | |
| 102 // Run test and allow variation of results. | |
| 103 prepareTestScenario(); | |
| OLD | NEW |