5 <canvas id=
"mycanvas" width=
"400" height=
"400"></canvas>
6 <script src=
"../../resources/js-test.js"></script>
8 description("This tests checks that ellipse can draw lines correctly in edge cases.");
9 var canvas
= document
.getElementById('mycanvas');
10 var ctx
= canvas
.getContext('2d');
14 ctx
.fillStyle
= 'rgb(255, 255, 255)';
15 ctx
.strokeStyle
= 'rgb(0, 0, 0)';
16 ctx
.fillRect(0, 0, canvas
.width
, canvas
.height
);
18 var imageData
= ctx
.getImageData(1, 1, 1, 1);
19 var data
= imageData
.data
;
20 shouldBe("imageData.data[1]", "255");
23 debug("moveTo + empty ellipse (swing == 0)");
28 ctx
.ellipse(80, 0, 10, 20, Math
.PI
/ 6, -Math
.PI
/ 2, -Math
.PI
/ 2 + zero
, false);
32 imageData
= ctx
.getImageData(23, 29, 1, 1);
33 shouldBe("imageData.data[1]", "0");
34 imageData
= ctx
.getImageData(85, 14, 1, 1);
35 shouldBe("imageData.data[1]", "0");
37 debug("moveTo + empty ellipse (radiusX == 0)");
42 ctx
.ellipse(80, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 2, Math
.PI
/ 2, false);
46 imageData
= ctx
.getImageData(22, 60, 1, 1);
47 shouldBe("imageData.data[1]", "0");
48 imageData
= ctx
.getImageData(86, 43, 1, 1);
49 shouldBe("imageData.data[1]", "0");
50 imageData
= ctx
.getImageData(71, 73, 1, 1);
51 shouldBe("imageData.data[1]", "0");
53 debug("moveTo + empty ellipse (radiusY == 0)");
58 ctx
.ellipse(80, 0, 10, zero
, Math
.PI
/ 6, -Math
.PI
/ 2, Math
.PI
/ 2, false);
62 imageData
= ctx
.getImageData(22, 90, 1, 1);
63 shouldBe("imageData.data[1]", "0");
64 imageData
= ctx
.getImageData(79, 90, 1, 1);
65 shouldBe("imageData.data[1]", "0");
66 imageData
= ctx
.getImageData(87, 94, 1, 1);
67 shouldBe("imageData.data[1]", "0");
69 debug("empty ellipse (swing == 0) + lineTo");
73 ctx
.ellipse(20, 0, 10, 20, Math
.PI
/ 6, -Math
.PI
/ 2, -Math
.PI
/ 2 + zero
, false);
78 imageData
= ctx
.getImageData(26, 101, 1, 1);
79 shouldBe("imageData.data[1]", "255");
80 imageData
= ctx
.getImageData(32, 103, 1, 1);
81 shouldBe("imageData.data[1]", "0");
82 imageData
= ctx
.getImageData(77, 119, 1, 1);
83 shouldBe("imageData.data[1]", "0");
85 debug("empty ellipse (radiusX == 0) + lineTo");
89 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 2, Math
.PI
/ 2, false);
94 imageData
= ctx
.getImageData(28, 135, 1, 1);
95 shouldBe("imageData.data[1]", "0");
96 imageData
= ctx
.getImageData(11, 166, 1, 1);
97 shouldBe("imageData.data[1]", "0");
98 imageData
= ctx
.getImageData(76, 151, 1, 1);
99 shouldBe("imageData.data[1]", "0");
101 debug("empty ellipse (radiusY == 0) + lineTo");
102 ctx
.translate(0, 30);
105 ctx
.ellipse(20, 0, 10, zero
, Math
.PI
/ 6, -Math
.PI
/ 2, Math
.PI
/ 2, false);
110 imageData
= ctx
.getImageData(27, 183, 1, 1);
111 shouldBe("imageData.data[1]", "0");
112 imageData
= ctx
.getImageData(21, 179, 1, 1);
113 shouldBe("imageData.data[1]", "0");
114 imageData
= ctx
.getImageData(77, 180, 1, 1);
115 shouldBe("imageData.data[1]", "0");
119 ctx
.translate(100, 0);
121 debug("lineTo + empty ellipse (radiusX == 0) + lineTo");
122 debug(" 1. sweepAngle < PI / 2");
123 ctx
.translate(0, 30);
127 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
/ 4, false);
132 imageData
= ctx
.getImageData(110, 29, 1, 1);
133 shouldBe("imageData.data[1]", "0");
134 imageData
= ctx
.getImageData(122, 22, 1, 1);
135 shouldBe("imageData.data[1]", "0");
136 imageData
= ctx
.getImageData(113, 42, 1, 1);
137 shouldBe("imageData.data[1]", "0");
138 imageData
= ctx
.getImageData(144, 38, 1, 1);
139 shouldBe("imageData.data[1]", "0");
141 debug(" 2. sweepAngle < PI");
142 ctx
.translate(0, 30);
146 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
/ 2, false);
151 imageData
= ctx
.getImageData(122, 54, 1, 1);
152 shouldBe("imageData.data[1]", "0");
153 imageData
= ctx
.getImageData(112, 76, 1, 1);
154 shouldBe("imageData.data[1]", "0");
155 imageData
= ctx
.getImageData(142, 70, 1, 1);
156 shouldBe("imageData.data[1]", "0");
158 debug(" 3. sweepAngle < 2PI");
159 ctx
.translate(0, 30);
163 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 3 / 2, false);
168 imageData
= ctx
.getImageData(115, 86, 1, 1);
169 shouldBe("imageData.data[1]", "0");
170 imageData
= ctx
.getImageData(110, 104, 1, 1);
171 shouldBe("imageData.data[1]", "0");
172 imageData
= ctx
.getImageData(138, 77, 1, 1);
173 shouldBe("imageData.data[1]", "0");
175 debug(" 4. sweepAngle < 4PI");
176 ctx
.translate(0, 30);
180 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 2, false);
185 imageData
= ctx
.getImageData(115, 116, 1, 1);
186 shouldBe("imageData.data[1]", "0");
187 imageData
= ctx
.getImageData(111, 136, 1, 1);
188 shouldBe("imageData.data[1]", "0");
189 imageData
= ctx
.getImageData(127, 106, 1, 1);
190 shouldBe("imageData.data[1]", "0");
191 imageData
= ctx
.getImageData(127, 121, 1, 1);
192 shouldBe("imageData.data[1]", "255");
194 debug(" 5. sweepAngle > 4PI");
195 ctx
.translate(0, 30);
199 ctx
.ellipse(20, 0, zero
, 20, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 16, false);
204 imageData
= ctx
.getImageData(115, 146, 1, 1);
205 shouldBe("imageData.data[1]", "0");
206 imageData
= ctx
.getImageData(111, 166, 1, 1);
207 shouldBe("imageData.data[1]", "0");
208 imageData
= ctx
.getImageData(127, 136, 1, 1);
209 shouldBe("imageData.data[1]", "0");
210 imageData
= ctx
.getImageData(127, 151, 1, 1);
211 shouldBe("imageData.data[1]", "255");
215 ctx
.translate(100, 0);
217 debug("lineTo + empty ellipse (radiusY == 0) + lineTo");
218 debug(" 1. sweepAngle < PI / 2");
219 ctx
.translate(0, 30);
223 ctx
.ellipse(20, 0, 20, zero
, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
/ 4, false);
228 imageData
= ctx
.getImageData(213, 32, 1, 1);
229 shouldBe("imageData.data[1]", "0");
230 imageData
= ctx
.getImageData(234, 39, 1, 1);
231 shouldBe("imageData.data[1]", "0");
232 imageData
= ctx
.getImageData(240, 36, 1, 1);
233 shouldBe("imageData.data[1]", "0");
235 debug(" 2. sweepAngle < PI");
236 ctx
.translate(0, 30);
240 ctx
.ellipse(20, 0, 20, zero
, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
/ 2, false);
245 imageData
= ctx
.getImageData(232, 69, 1, 1);
246 shouldBe("imageData.data[1]", "0");
247 imageData
= ctx
.getImageData(238, 72, 1, 1);
248 shouldBe("imageData.data[1]", "255");
249 imageData
= ctx
.getImageData(228, 65, 1, 1);
250 shouldBe("imageData.data[1]", "0");
251 imageData
= ctx
.getImageData(242, 61, 1, 1);
252 shouldBe("imageData.data[1]", "0");
254 debug(" 3. sweepAngle < 2PI");
255 ctx
.translate(0, 30);
259 ctx
.ellipse(20, 0, 20, zero
, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 3 / 2, false);
264 imageData
= ctx
.getImageData(204, 82, 1, 1);
265 shouldBe("imageData.data[1]", "0");
266 imageData
= ctx
.getImageData(234, 100, 1, 1);
267 shouldBe("imageData.data[1]", "0");
268 imageData
= ctx
.getImageData(212, 92, 1, 1);
269 shouldBe("imageData.data[1]", "0");
270 imageData
= ctx
.getImageData(240, 90, 1, 1);
271 shouldBe("imageData.data[1]", "0");
273 debug(" 4. sweepAngle < 4PI");
274 ctx
.translate(0, 30);
278 ctx
.ellipse(20, 0, 20, zero
, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 2, false);
283 imageData
= ctx
.getImageData(208, 114, 1, 1);
284 shouldBe("imageData.data[1]", "0");
285 imageData
= ctx
.getImageData(235, 130, 1, 1);
286 shouldBe("imageData.data[1]", "0");
287 imageData
= ctx
.getImageData(210, 120, 1, 1);
288 shouldBe("imageData.data[1]", "0");
289 imageData
= ctx
.getImageData(252, 124, 1, 1);
290 shouldBe("imageData.data[1]", "0");
292 debug(" 5. sweepAngle > 4PI");
293 ctx
.translate(0, 30);
297 ctx
.ellipse(20, 0, 20, zero
, Math
.PI
/ 6, -Math
.PI
/ 4, Math
.PI
* 16, false);
302 imageData
= ctx
.getImageData(208, 144, 1, 1);
303 shouldBe("imageData.data[1]", "0");
304 imageData
= ctx
.getImageData(235, 160, 1, 1);
305 shouldBe("imageData.data[1]", "0");
306 imageData
= ctx
.getImageData(210, 150, 1, 1);
307 shouldBe("imageData.data[1]", "0");
308 imageData
= ctx
.getImageData(252, 154, 1, 1);
309 shouldBe("imageData.data[1]", "0");