2d.path.isPointInPath.basic.worker.js (2222B)
1 // DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. 2 // OffscreenCanvas test in a worker:2d.path.isPointInPath.basic 3 // Description:Verify the winding rule in isPointInPath works for for rect path. 4 // Note: 5 6 importScripts("/resources/testharness.js"); 7 importScripts("/html/canvas/resources/canvas-tests.js"); 8 9 var t = async_test("Verify the winding rule in isPointInPath works for for rect path."); 10 var t_pass = t.done.bind(t); 11 var t_fail = t.step_func(function(reason) { 12 throw reason; 13 }); 14 t.step(function() { 15 16 var canvas = new OffscreenCanvas(100, 50); 17 var ctx = canvas.getContext('2d'); 18 19 canvas.width = 200; 20 canvas.height = 200; 21 22 // Testing default isPointInPath 23 ctx.beginPath(); 24 ctx.rect(0, 0, 100, 100); 25 ctx.rect(25, 25, 50, 50); 26 _assertSame(ctx.isPointInPath(50, 50), true, "ctx.isPointInPath(50, 50)", "true"); 27 _assertSame(ctx.isPointInPath(NaN, 50), false, "ctx.isPointInPath(NaN, 50)", "false"); 28 _assertSame(ctx.isPointInPath(50, NaN), false, "ctx.isPointInPath(50, NaN)", "false"); 29 30 // Testing nonzero isPointInPath 31 ctx.beginPath(); 32 ctx.rect(0, 0, 100, 100); 33 ctx.rect(25, 25, 50, 50); 34 _assertSame(ctx.isPointInPath(50, 50, 'nonzero'), true, "ctx.isPointInPath(50, 50, 'nonzero')", "true"); 35 36 // Testing evenodd isPointInPath 37 ctx.beginPath(); 38 ctx.rect(0, 0, 100, 100); 39 ctx.rect(25, 25, 50, 50); 40 _assertSame(ctx.isPointInPath(50, 50, 'evenodd'), false, "ctx.isPointInPath(50, 50, 'evenodd')", "false"); 41 42 // Testing extremely large scale 43 ctx.save(); 44 ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE); 45 ctx.beginPath(); 46 ctx.rect(-10, -10, 20, 20); 47 _assertSame(ctx.isPointInPath(0, 0, 'nonzero'), true, "ctx.isPointInPath(0, 0, 'nonzero')", "true"); 48 _assertSame(ctx.isPointInPath(0, 0, 'evenodd'), true, "ctx.isPointInPath(0, 0, 'evenodd')", "true"); 49 ctx.restore(); 50 51 // Check with non-invertible ctm. 52 ctx.save(); 53 ctx.scale(0, 0); 54 ctx.beginPath(); 55 ctx.rect(-10, -10, 20, 20); 56 _assertSame(ctx.isPointInPath(0, 0, 'nonzero'), false, "ctx.isPointInPath(0, 0, 'nonzero')", "false"); 57 _assertSame(ctx.isPointInPath(0, 0, 'evenodd'), false, "ctx.isPointInPath(0, 0, 'evenodd')", "false"); 58 ctx.restore(); 59 t.done(); 60 }); 61 done();