OLD | NEW |
1 <!doctype html> | 1 <script src="../../resources/testharness.js"></script> |
2 <html> | 2 <script src="../../resources/testharnessreport.js"></script> |
3 <head> | 3 <script> |
4 <script src="../../resources/js-test.js"></script> | 4 |
5 </head> | 5 var canvas = document.createElement('canvas'); |
6 <body> | 6 canvas.width = 200; |
7 <script src="script-tests/canvas-isPointInPath-winding.js"></script> | 7 canvas.height = 200; |
8 </body> | 8 ctx = canvas.getContext('2d'); |
| 9 |
| 10 test(function(t) { |
| 11 // Testing default isPointInPath'); |
| 12 ctx.beginPath(); |
| 13 ctx.rect(0, 0, 100, 100); |
| 14 ctx.rect(25, 25, 50, 50); |
| 15 assert_true(ctx.isPointInPath(50, 50)); |
| 16 assert_false(ctx.isPointInPath(NaN, 50)); |
| 17 assert_false(ctx.isPointInPath(50, NaN)); |
| 18 |
| 19 // Testing nonzero isPointInPath'); |
| 20 ctx.beginPath(); |
| 21 ctx.rect(0, 0, 100, 100); |
| 22 ctx.rect(25, 25, 50, 50); |
| 23 assert_true(ctx.isPointInPath(50, 50, 'nonzero')); |
| 24 |
| 25 // Testing evenodd isPointInPath'); |
| 26 ctx.beginPath(); |
| 27 ctx.rect(0, 0, 100, 100); |
| 28 ctx.rect(25, 25, 50, 50); |
| 29 assert_false(ctx.isPointInPath(50, 50, 'evenodd')); |
| 30 |
| 31 // reset path in context |
| 32 ctx.beginPath(); |
| 33 |
| 34 // Testing default isPointInPath with Path object'); |
| 35 path = new Path2D(); |
| 36 path.rect(0, 0, 100, 100); |
| 37 path.rect(25, 25, 50, 50); |
| 38 assert_true(ctx.isPointInPath(path, 50, 50)); |
| 39 assert_true(ctx.isPointInPath(path, 50, 50, undefined)); |
| 40 assert_false(ctx.isPointInPath(path, NaN, 50)); |
| 41 assert_false(ctx.isPointInPath(path, 50, NaN)); |
| 42 |
| 43 // Testing nonzero isPointInPath with Path object'); |
| 44 path = new Path2D(); |
| 45 path.rect(0, 0, 100, 100); |
| 46 path.rect(25, 25, 50, 50); |
| 47 assert_true(ctx.isPointInPath(path, 50, 50, 'nonzero')); |
| 48 |
| 49 // Testing evenodd isPointInPath with Path object'); |
| 50 path = new Path2D(); |
| 51 path.rect(0, 0, 100, 100); |
| 52 path.rect(25, 25, 50, 50); |
| 53 assert_false(ctx.isPointInPath(path, 50, 50, 'evenodd')); |
| 54 |
| 55 // Testing invalid enumeration isPointInPath (w/ and w/o Path object'); |
| 56 assert_throws(null, function(){ ctx.isPointInPath(path, 50, 50, 'gazonk');})
; |
| 57 assert_throws(null, function(){ ctx.isPointInPath(50, 50, 'gazonk');}); |
| 58 |
| 59 // Testing invalid type isPointInPath with Path object'); |
| 60 assert_throws(null, function(){ ctx.isPointInPath(null, 50, 50);}); |
| 61 assert_throws(null, function(){ ctx.isPointInPath(null, 50, 50, 'nonzero');}
); |
| 62 assert_throws(null, function(){ ctx.isPointInPath(null, 50, 50, 'evenodd');}
); |
| 63 assert_throws(null, function(){ ctx.isPointInPath(null, 50, 50, null);}); |
| 64 assert_throws(null, function(){ ctx.isPointInPath(path, 50, 50, null);}); |
| 65 assert_throws(null, function(){ ctx.isPointInPath(undefined, 50, 50);}); |
| 66 assert_throws(null, function(){ ctx.isPointInPath(undefined, 50, 50, 'nonzer
o');}); |
| 67 assert_throws(null, function(){ ctx.isPointInPath(undefined, 50, 50, 'evenod
d');}); |
| 68 assert_throws(null, function(){ ctx.isPointInPath(undefined, 50, 50, undefin
ed);}); |
| 69 assert_throws(null, function(){ ctx.isPointInPath([], 50, 50);}); |
| 70 assert_throws(null, function(){ ctx.isPointInPath([], 50, 50, 'nonzero');}); |
| 71 assert_throws(null, function(){ ctx.isPointInPath([], 50, 50, 'evenodd');}); |
| 72 assert_throws(null, function(){ ctx.isPointInPath({}, 50, 50);}); |
| 73 assert_throws(null, function(){ ctx.isPointInPath({}, 50, 50, 'nonzero');}); |
| 74 assert_throws(null, function(){ ctx.isPointInPath({}, 50, 50, 'evenodd');}); |
| 75 |
| 76 // Testing extremely large scale |
| 77 ctx.save(); |
| 78 ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE); |
| 79 ctx.beginPath(); |
| 80 ctx.rect(-10, -10, 20, 20); |
| 81 assert_true(ctx.isPointInPath(0, 0, 'nonzero')); |
| 82 assert_true(ctx.isPointInPath(0, 0, 'evenodd')); |
| 83 ctx.restore(); |
| 84 |
| 85 // Check with non-invertible ctm. |
| 86 ctx.save(); |
| 87 ctx.scale(0, 0); |
| 88 ctx.beginPath(); |
| 89 ctx.rect(-10, -10, 20, 20); |
| 90 assert_false(ctx.isPointInPath(0, 0, 'nonzero')); |
| 91 assert_false(ctx.isPointInPath(0, 0, 'evenodd')); |
| 92 ctx.restore(); |
| 93 }, "Series of tests to ensure correct results of the winding rule in isPointInPa
th."); |
| 94 |
| 95 </script> |
OLD | NEW |