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