OLD | NEW |
(Empty) | |
| 1 description("Test addPath() method."); |
| 2 var ctx = document.createElement('canvas').getContext('2d'); |
| 3 |
| 4 debug("Test addPath() with transform as identity matrix.") |
| 5 ctx.beginPath(); |
| 6 var p1 = new Path(); |
| 7 p1.rect(0,0,100,100); |
| 8 var p2 = new Path(); |
| 9 p2.rect(0,100,100,100); |
| 10 var m = ctx.currentTransform; |
| 11 p1.addPath(p2, m); |
| 12 ctx.fillStyle = 'yellow'; |
| 13 ctx.currentPath = p1; |
| 14 ctx.fill(); |
| 15 var imageData = ctx.getImageData(0, 100, 100, 100); |
| 16 var imgdata = imageData.data; |
| 17 shouldBe("imgdata[4]", "255"); |
| 18 shouldBe("imgdata[5]", "255"); |
| 19 shouldBe("imgdata[6]", "0"); |
| 20 shouldBe("imgdata[7]", "255"); |
| 21 debug(""); |
| 22 |
| 23 debug("Test addPath() with transform as translate(100, -100).") |
| 24 ctx.beginPath(); |
| 25 var p3 = new Path(); |
| 26 p3.rect(0,0,100,100); |
| 27 var p4 = new Path(); |
| 28 p4.rect(0,100,100,100); |
| 29 m.a = 1; m.b = 0; |
| 30 m.c = 0; m.d = 1; |
| 31 m.e = 100; m.f = -100; |
| 32 p3.addPath(p4, m); |
| 33 ctx.fillStyle = 'yellow'; |
| 34 ctx.currentPath = p3; |
| 35 ctx.fill(); |
| 36 imageData = ctx.getImageData(100, 0, 100, 100); |
| 37 imgdata = imageData.data; |
| 38 shouldBe("imgdata[4]", "255"); |
| 39 shouldBe("imgdata[5]", "255"); |
| 40 shouldBe("imgdata[6]", "0"); |
| 41 shouldBe("imgdata[7]", "255"); |
| 42 debug(""); |
| 43 |
| 44 debug("Test addPath() with non-invertible transform.") |
| 45 ctx.beginPath(); |
| 46 var p5 = new Path(); |
| 47 p5.rect(0,0,100,100); |
| 48 var p6 = new Path(); |
| 49 p6.rect(100,100,100,100); |
| 50 m.a = 0; m.b = 0; |
| 51 m.c = 0; m.d = 0; |
| 52 m.e = 0; m.f = 0; |
| 53 p5.addPath(p6, m); |
| 54 ctx.fillStyle = 'yellow'; |
| 55 ctx.currentPath = p5; |
| 56 ctx.fill(); |
| 57 imageData = ctx.getImageData(100, 100, 100, 100); |
| 58 imgdata = imageData.data; |
| 59 shouldNotBe("imgdata[4]", "255"); |
| 60 shouldNotBe("imgdata[5]", "255"); |
| 61 shouldBe("imgdata[6]", "0"); |
| 62 shouldNotBe("imgdata[7]", "255"); |
| 63 debug(""); |
| 64 |
| 65 debug("Test addPath() with transform as null or invalid type.") |
| 66 ctx.beginPath(); |
| 67 var p7 = new Path(); |
| 68 p7.rect(0,0,100,100); |
| 69 var p8 = new Path(); |
| 70 p8.rect(100,100,100,100); |
| 71 p7.addPath(p8, null); |
| 72 p7.addPath(p8, []); |
| 73 p7.addPath(p8, {}); |
| 74 ctx.fillStyle = 'red'; |
| 75 ctx.currentPath = p7; |
| 76 ctx.fill(); |
| 77 imageData = ctx.getImageData(100, 100, 100, 100); |
| 78 imgdata = imageData.data; |
| 79 shouldBe("imgdata[4]", "255"); |
| 80 shouldBe("imgdata[5]", "0"); |
| 81 shouldBe("imgdata[6]", "0"); |
| 82 shouldBe("imgdata[7]", "255"); |
| 83 debug(""); |
| 84 |
| 85 debug("Test addPath() with path as null and invalid type"); |
| 86 var p9 = new Path(); |
| 87 p9.rect(0,0,100,100); |
| 88 shouldThrow("p7.addPath(null, m)"); |
| 89 shouldThrow("p7.addPath([], m)"); |
| 90 shouldThrow("p7.addPath({}, m)"); |
| 91 debug(""); |
OLD | NEW |