| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| |
| var canvas = document.createElement('canvas'); |
| canvas.width = 200; |
| canvas.height = 200; |
| ctx = canvas.getContext('2d'); |
| |
| test(function(t) { |
| // Testing default isPointInPath'); |
| ctx.beginPath(); |
| ctx.rect(0, 0, 100, 100); |
| ctx.rect(25, 25, 50, 50); |
| assert_true(ctx.isPointInPath(50, 50)); |
| assert_false(ctx.isPointInPath(NaN, 50)); |
| assert_false(ctx.isPointInPath(50, NaN)); |
| |
| // Testing nonzero isPointInPath'); |
| ctx.beginPath(); |
| ctx.rect(0, 0, 100, 100); |
| ctx.rect(25, 25, 50, 50); |
| assert_true(ctx.isPointInPath(50, 50, 'nonzero')); |
| |
| // Testing evenodd isPointInPath'); |
| ctx.beginPath(); |
| ctx.rect(0, 0, 100, 100); |
| ctx.rect(25, 25, 50, 50); |
| assert_false(ctx.isPointInPath(50, 50, 'evenodd')); |
| |
| // reset path in context |
| ctx.beginPath(); |
| |
| // Testing default isPointInPath with Path object'); |
| path = new Path2D(); |
| path.rect(0, 0, 100, 100); |
| path.rect(25, 25, 50, 50); |
| assert_true(ctx.isPointInPath(path, 50, 50)); |
| assert_true(ctx.isPointInPath(path, 50, 50, undefined)); |
| assert_false(ctx.isPointInPath(path, NaN, 50)); |
| assert_false(ctx.isPointInPath(path, 50, NaN)); |
| |
| // Testing nonzero isPointInPath with Path object'); |
| path = new Path2D(); |
| path.rect(0, 0, 100, 100); |
| path.rect(25, 25, 50, 50); |
| assert_true(ctx.isPointInPath(path, 50, 50, 'nonzero')); |
| |
| // Testing evenodd isPointInPath with Path object'); |
| path = new Path2D(); |
| path.rect(0, 0, 100, 100); |
| path.rect(25, 25, 50, 50); |
| assert_false(ctx.isPointInPath(path, 50, 50, 'evenodd')); |
| |
| // Testing invalid enumeration isPointInPath (w/ and w/o Path object'); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(path, 50, 50, 'gazonk'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(50, 50, 'gazonk'); |
| }); |
| |
| // Testing invalid type isPointInPath with Path object'); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(null, 50, 50); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(null, 50, 50, 'nonzero'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(null, 50, 50, 'evenodd'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(null, 50, 50, null); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(path, 50, 50, null); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(undefined, 50, 50); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(undefined, 50, 50, 'nonzero'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(undefined, 50, 50, 'evenodd'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath(undefined, 50, 50, undefined); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath([], 50, 50); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath([], 50, 50, 'nonzero'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath([], 50, 50, 'evenodd'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath({}, 50, 50); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath({}, 50, 50, 'nonzero'); |
| }); |
| assert_throws(new TypeError(), function() { |
| ctx.isPointInPath({}, 50, 50, 'evenodd'); |
| }); |
| |
| // Testing extremely large scale |
| ctx.save(); |
| ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE); |
| ctx.beginPath(); |
| ctx.rect(-10, -10, 20, 20); |
| assert_true(ctx.isPointInPath(0, 0, 'nonzero')); |
| assert_true(ctx.isPointInPath(0, 0, 'evenodd')); |
| ctx.restore(); |
| |
| // Check with non-invertible ctm. |
| ctx.save(); |
| ctx.scale(0, 0); |
| ctx.beginPath(); |
| ctx.rect(-10, -10, 20, 20); |
| assert_false(ctx.isPointInPath(0, 0, 'nonzero')); |
| assert_false(ctx.isPointInPath(0, 0, 'evenodd')); |
| ctx.restore(); |
| }, "Series of tests to ensure correct results of the winding rule in isPointInPath."); |
| |
| </script> |