OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 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 test(function(){ |
5 </head> | 5 |
6 <body> | 6 ctx = document.createElement("canvas").getContext("2d"); |
7 <canvas id="canvas"></canvas> | 7 ctx.save(); |
8 <script src="pointInPath.js"></script> | 8 // Rectangle at (0,0) 20x20 |
9 </body> | 9 ctx.rect(0, 0, 20, 20); |
10 </html> | 10 assert_true(ctx.isPointInPath(5, 5)); |
| 11 assert_true(ctx.isPointInPath(10, 10)); |
| 12 assert_true(ctx.isPointInPath(19, 19)); |
| 13 assert_false(ctx.isPointInPath(30, 30)); |
| 14 assert_false(ctx.isPointInPath(-1, 10)); |
| 15 assert_false(ctx.isPointInPath(10, -1)); |
| 16 |
| 17 // Translate context (10,10) |
| 18 ctx.translate(10,10); |
| 19 assert_true(ctx.isPointInPath(5, 5)); |
| 20 assert_true(ctx.isPointInPath(10, 10)); |
| 21 assert_true(ctx.isPointInPath(19, 19)); |
| 22 assert_false(ctx.isPointInPath(30, 30)); |
| 23 assert_false(ctx.isPointInPath(-1, 10)); |
| 24 assert_false(ctx.isPointInPath(10, -1)); |
| 25 |
| 26 // Collapse ctm to non-invertible matrix |
| 27 ctx.scale(0,0); |
| 28 assert_false(ctx.isPointInPath(5, 5)); |
| 29 assert_false(ctx.isPointInPath(10, 10)); |
| 30 assert_false(ctx.isPointInPath(20, 20)); |
| 31 assert_false(ctx.isPointInPath(30, 30)); |
| 32 assert_false(ctx.isPointInPath(-1, 10)); |
| 33 assert_false(ctx.isPointInPath(10, -1)); |
| 34 // Resetting context to a clean state |
| 35 ctx.restore(); |
| 36 |
| 37 ctx.save(); |
| 38 ctx.beginPath(); |
| 39 // Translate context (10,10) |
| 40 ctx.translate(10,10); |
| 41 // Rectangle at (0,0) 20x20 |
| 42 ctx.rect(0, 0, 20, 20); |
| 43 assert_false(ctx.isPointInPath(5, 5)); |
| 44 assert_true(ctx.isPointInPath(10, 10)); |
| 45 assert_true(ctx.isPointInPath(20, 20)); |
| 46 assert_true(ctx.isPointInPath(29, 29)); |
| 47 assert_false(ctx.isPointInPath(-1, 10)); |
| 48 assert_false(ctx.isPointInPath(10, -1)); |
| 49 ctx.restore(); |
| 50 |
| 51 ctx.save(); |
| 52 ctx.beginPath(); |
| 53 // Translate context (10,20) |
| 54 ctx.translate(10,20); |
| 55 // Transform context (1, 0, 0, -1, 0, 0) |
| 56 ctx.transform(1, 0, 0, -1, 0, 0); |
| 57 // Rectangle at (0,0) 20x20 |
| 58 ctx.rect(0, 0, 20, 20); |
| 59 // After the flip, rect is actually 10, 0, 20, 20 |
| 60 assert_false(ctx.isPointInPath(5, 5)); |
| 61 assert_true(ctx.isPointInPath(10, 0)); |
| 62 assert_true(ctx.isPointInPath(29, 0)); |
| 63 assert_true(ctx.isPointInPath(10, 19)); |
| 64 assert_true(ctx.isPointInPath(21, 10)); |
| 65 assert_true(ctx.isPointInPath(29, 19)); |
| 66 ctx.strokeStyle = 'green'; |
| 67 ctx.stroke(); |
| 68 ctx.restore(); |
| 69 |
| 70 }, "Series of tests for Canvas.isPointInPath"); |
| 71 </script> |
OLD | NEW |