6 function init_data() { return testData("2d"); }
7 function test_angle_1(row) {
8 var canvas = createCanvasObject(row);
9 var ctx = canvas.getContext('2d');
12 ctx.fillStyle = '#0f0';
13 ctx.fillRect(0, 0, 100, 50);
14 ctx.fillStyle = '#f00';
17 ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true);
19 comparePixel(ctx,50,25, 0,255,0,255);
22 function test_angle_2(row) {
23 var canvas = createCanvasObject(row);
24 var ctx = canvas.getContext('2d');
27 ctx.fillStyle = '#0f0';
28 ctx.fillRect(0, 0, 100, 50);
29 ctx.fillStyle = '#f00';
32 ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true);
34 comparePixel(ctx,50,25, 0,255,0,255);
37 function test_angle_3(row) {
38 var canvas = createCanvasObject(row);
39 var ctx = canvas.getContext('2d');
41 ctx.fillStyle = '#0f0';
42 ctx.fillRect(0, 0, 100, 50);
43 ctx.fillStyle = '#f00';
46 ctx.arc(100, 0, 150, (512+1/2)*Math.PI, (1024-1)*Math.PI, true);
48 /*FIXME: from: http://www.w3.org/TR/2dcontext/#dom-context-2d-arc
49 If the anticlockwise argument is omitted or false and endAngle-startAngle is equal to or greater than 2π, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, then the arc is the whole circumference of this circle.
50 //comparePixel(ctx,50,25, 0,255,0,255);
54 function test_angle_4(row) {
55 var canvas = createCanvasObject(row);
56 var ctx = canvas.getContext('2d');
59 ctx.fillStyle = '#f00';
60 ctx.fillRect(0, 0, 100, 50);
61 ctx.fillStyle = '#0f0';
64 ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false);
66 comparePixel(ctx,1,1, 0,255,0,255);
67 comparePixel(ctx,98,1, 0,255,0,255);
68 comparePixel(ctx,1,48, 0,255,0,255);
69 comparePixel(ctx,98,48, 0,255,0,255);
72 function test_angle_5(row) {
73 var canvas = createCanvasObject(row);
74 var ctx = canvas.getContext('2d');
77 ctx.fillStyle = '#0f0';
78 ctx.fillRect(0, 0, 100, 50);
79 ctx.fillStyle = '#f00';
82 ctx.arc(100, 0, 150, (1024-1)*Math.PI, (512+1/2)*Math.PI, false);
84 /*FIXME: from: http://www.w3.org/TR/2dcontext/#dom-context-2d-arc
85 If the anticlockwise argument is omitted or false and endAngle-startAngle is equal to or greater than 2π, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, then the arc is the whole circumference of this circle.
86 //comparePixel(ctx,50,25, 0,255,0,255);
91 function test_angle_6(row) {
92 var canvas = createCanvasObject(row);
93 var ctx = canvas.getContext('2d');
96 ctx.fillStyle = '#f00';
97 ctx.fillRect(0, 0, 100, 50);
98 ctx.fillStyle = '#0f0';
101 ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true);
104 comparePixel(ctx,1,1, 0,255,0,255);
105 comparePixel(ctx,98,1, 0,255,0,255);
106 comparePixel(ctx,1,48, 0,255,0,255);
107 comparePixel(ctx,98,48, 0,255,0,255);
111 function test_empty(row) {
112 var canvas = createCanvasObject(row);
113 var ctx = canvas.getContext('2d');
116 ctx.fillStyle = '#0f0';
117 ctx.fillRect(0, 0, 100, 50);
119 ctx.strokeStyle = '#f00';
121 ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
123 comparePixel(ctx,50,25, 0,255,0,255);
126 function test_nonempty(row) {
127 var canvas = createCanvasObject(row);
128 var ctx = canvas.getContext('2d');
131 ctx.fillStyle = '#f00';
132 ctx.fillRect(0, 0, 100, 50);
134 ctx.strokeStyle = '#0f0';
137 ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
139 comparePixel(ctx,50,25, 0,255,0,255);
142 function test_nonfinite(row) {
143 var canvas = createCanvasObject(row);
144 var ctx = canvas.getContext('2d');
147 ctx.fillStyle = '#f00';
148 ctx.fillRect(0, 0, 100, 50);
151 ctx.arc(Infinity, 0, 50, 0, 2*Math.PI, true);
152 ctx.arc(-Infinity, 0, 50, 0, 2*Math.PI, true);
153 ctx.arc(NaN, 0, 50, 0, 2*Math.PI, true);
154 ctx.arc(0, Infinity, 50, 0, 2*Math.PI, true);
155 ctx.arc(0, -Infinity, 50, 0, 2*Math.PI, true);
156 ctx.arc(0, NaN, 50, 0, 2*Math.PI, true);
157 ctx.arc(0, 0, Infinity, 0, 2*Math.PI, true);
158 ctx.arc(0, 0, -Infinity, 0, 2*Math.PI, true);
159 ctx.arc(0, 0, NaN, 0, 2*Math.PI, true);
160 ctx.arc(0, 0, 50, Infinity, 2*Math.PI, true);
161 ctx.arc(0, 0, 50, -Infinity, 2*Math.PI, true);
162 ctx.arc(0, 0, 50, NaN, 2*Math.PI, true);
163 ctx.arc(0, 0, 50, 0, Infinity, true);
164 ctx.arc(0, 0, 50, 0, -Infinity, true);
165 ctx.arc(0, 0, 50, 0, NaN, true);
166 ctx.arc(Infinity, Infinity, 50, 0, 2*Math.PI, true);
167 ctx.arc(Infinity, Infinity, Infinity, 0, 2*Math.PI, true);
168 ctx.arc(Infinity, Infinity, Infinity, Infinity, 2*Math.PI, true);
169 ctx.arc(Infinity, Infinity, Infinity, Infinity, Infinity, true);
170 ctx.arc(Infinity, Infinity, Infinity, 0, Infinity, true);
171 ctx.arc(Infinity, Infinity, 50, Infinity, 2*Math.PI, true);
172 ctx.arc(Infinity, Infinity, 50, Infinity, Infinity, true);
173 ctx.arc(Infinity, Infinity, 50, 0, Infinity, true);
174 ctx.arc(Infinity, 0, Infinity, 0, 2*Math.PI, true);
175 ctx.arc(Infinity, 0, Infinity, Infinity, 2*Math.PI, true);
176 ctx.arc(Infinity, 0, Infinity, Infinity, Infinity, true);
177 ctx.arc(Infinity, 0, Infinity, 0, Infinity, true);
178 ctx.arc(Infinity, 0, 50, Infinity, 2*Math.PI, true);
179 ctx.arc(Infinity, 0, 50, Infinity, Infinity, true);
180 ctx.arc(Infinity, 0, 50, 0, Infinity, true);
181 ctx.arc(0, Infinity, Infinity, 0, 2*Math.PI, true);
182 ctx.arc(0, Infinity, Infinity, Infinity, 2*Math.PI, true);
183 ctx.arc(0, Infinity, Infinity, Infinity, Infinity, true);
184 ctx.arc(0, Infinity, Infinity, 0, Infinity, true);
185 ctx.arc(0, Infinity, 50, Infinity, 2*Math.PI, true);
186 ctx.arc(0, Infinity, 50, Infinity, Infinity, true);
187 ctx.arc(0, Infinity, 50, 0, Infinity, true);
188 ctx.arc(0, 0, Infinity, Infinity, 2*Math.PI, true);
189 ctx.arc(0, 0, Infinity, Infinity, Infinity, true);
190 ctx.arc(0, 0, Infinity, 0, Infinity, true);
191 ctx.arc(0, 0, 50, Infinity, Infinity, true);
194 ctx.fillStyle = '#0f0';
196 comparePixel(ctx,50,25, 0,255,0,255);
197 comparePixel(ctx,90,45, 0,255,0,255);
200 function test_end(row) {
201 var canvas = createCanvasObject(row);
202 var ctx = canvas.getContext('2d');
205 ctx.fillStyle = '#f00';
206 ctx.fillRect(0, 0, 100, 50);
208 ctx.strokeStyle = '#0f0';
211 ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true);
214 comparePixel(ctx,50,25, 0,255,0,255);
217 function test_negative(row) {
218 var canvas = createCanvasObject(row);
219 var ctx = canvas.getContext('2d');
222 try { var err = false;
223 ctx.arc(0, 0, -1, 0, 0, true);
225 if (e.code != DOMException.INDEX_SIZE_ERR)
226 fail("expected exception of type INDEX_SIZE_ERR, got: "+e.message);
229 verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)");
235 function test_scale_1(row) {
236 var canvas = createCanvasObject(row);
237 var ctx = canvas.getContext('2d');
240 ctx.fillStyle = '#f00';
241 ctx.fillRect(0, 0, 100, 50);
243 ctx.fillStyle = '#0f0';
245 ctx.arc(25, 50, 56, 0, 2*Math.PI, false);
247 ctx.fillStyle = '#f00';
250 ctx.arc(-25, 50, 24, 0, 2*Math.PI, false);
252 ctx.arc(75, 50, 24, 0, 2*Math.PI, false);
254 ctx.arc(25, -25, 24, 0, 2*Math.PI, false);
256 ctx.arc(25, 125, 24, 0, 2*Math.PI, false);
259 comparePixel(ctx, 0,0, 0,255,0,255);
260 comparePixel(ctx, 50,0, 0,255,0,255);
261 comparePixel(ctx, 99,0, 0,255,0,255);
262 comparePixel(ctx, 0,25, 0,255,0,255);
263 comparePixel(ctx, 50,25, 0,255,0,255);
264 comparePixel(ctx, 99,25, 0,255,0,255);
265 comparePixel(ctx, 0,49, 0,255,0,255);
266 comparePixel(ctx, 50,49, 0,255,0,255);
267 comparePixel(ctx, 99,49, 0,255,0,255);
271 function test_scale_2(row) {
272 var canvas = createCanvasObject(row);
273 var ctx = canvas.getContext('2d');
276 ctx.fillStyle = '#f00';
277 ctx.fillRect(0, 0, 100, 50);
279 ctx.strokeStyle = '#0f0';
282 ctx.arc(0, 0, 0.6, 0, Math.PI/2, false);
285 comparePixel(ctx, 1,1, 0,255,0,255);
286 comparePixel(ctx, 50,1, 0,255,0,255);
287 comparePixel(ctx, 98,1, 0,255,0,255);
288 comparePixel(ctx, 1,25, 0,255,0,255);
289 comparePixel(ctx, 50,25, 0,255,0,255);
290 comparePixel(ctx, 98,25, 0,255,0,255);
291 comparePixel(ctx, 1,48, 0,255,0,255);
292 comparePixel(ctx, 50,48, 0,255,0,255);
293 comparePixel(ctx, 98,48, 0,255,0,255);
297 function test_selfintersect_1(row) {
298 var canvas = createCanvasObject(row);
299 var ctx = canvas.getContext('2d');
302 ctx.fillStyle = '#0f0';
303 ctx.fillRect(0, 0, 100, 50);
305 ctx.strokeStyle = '#f00';
307 ctx.arc(100, 50, 25, 0, -Math.PI/2, true);
310 ctx.arc(0, 0, 25, 0, -Math.PI/2, true);
312 comparePixel(ctx, 1,1, 0,255,0,255);
313 comparePixel(ctx, 50,25, 0,255,0,255);
317 function test_selfintersect_2(row) {
318 var canvas = createCanvasObject(row);
319 var ctx = canvas.getContext('2d');
322 ctx.fillStyle = '#f00';
323 ctx.fillRect(0, 0, 100, 50);
325 ctx.strokeStyle = '#0f0';
327 ctx.arc(-50, 50, 25, 0, -Math.PI/2, true);
330 ctx.arc(100, 0, 25, 0, -Math.PI/2, true);
332 comparePixel(ctx, 50,25, 0,255,0,255);
333 comparePixel(ctx, 90,10, 0,255,0,255);
334 comparePixel(ctx, 97,1, 0,255,0,255);
335 comparePixel(ctx, 97,2, 0,255,0,255);
336 comparePixel(ctx, 97,3, 0,255,0,255);
337 comparePixel(ctx, 2,48, 0,255,0,255);
341 function test_shape_1(row) {
342 var canvas = createCanvasObject(row);
343 var ctx = canvas.getContext('2d');
346 ctx.fillStyle = '#0f0';
347 ctx.fillRect(0, 0, 100, 50);
349 ctx.strokeStyle = '#f00';
351 ctx.arc(50, 50, 50, 0, Math.PI, false);
353 comparePixel(ctx, 50,25, 0,255,0,255);
354 comparePixel(ctx, 1,1, 0,255,0,255);
355 comparePixel(ctx, 98,1, 0,255,0,255);
356 comparePixel(ctx, 1,48, 0,255,0,255);
357 comparePixel(ctx, 20,48, 0,255,0,255);
358 comparePixel(ctx, 98,48, 0,255,0,255);
362 function test_shape_2(row) {
363 var canvas = createCanvasObject(row);
364 var ctx = canvas.getContext('2d');
367 ctx.fillStyle = '#f00';
368 ctx.fillRect(0, 0, 100, 50);
370 ctx.strokeStyle = '#0f0';
372 ctx.arc(50, 50, 50, 0, Math.PI, true);
374 comparePixel(ctx, 50,25, 0,255,0,255);
375 comparePixel(ctx, 1,1, 0,255,0,255);
376 comparePixel(ctx, 98,1, 0,255,0,255);
377 comparePixel(ctx, 1,48, 0,255,0,255);
378 comparePixel(ctx, 20,48, 0,255,0,255);
379 comparePixel(ctx, 98,48, 0,255,0,255);
382 function test_shape_3(row) {
383 var canvas = createCanvasObject(row);
384 var ctx = canvas.getContext('2d');
387 ctx.fillStyle = '#0f0';
388 ctx.fillRect(0, 0, 100, 50);
390 ctx.strokeStyle = '#f00';
392 ctx.arc(0, 50, 50, 0, -Math.PI/2, false);
394 comparePixel(ctx, 50,25, 0,255,0,255);
395 comparePixel(ctx, 1,1, 0,255,0,255);
396 comparePixel(ctx, 98,1, 0,255,0,255);
397 comparePixel(ctx, 1,48, 0,255,0,255);
398 comparePixel(ctx, 98,48, 0,255,0,255);
402 function test_shape_4(row) {
403 var canvas = createCanvasObject(row);
404 var ctx = canvas.getContext('2d');
407 ctx.fillStyle = '#f00';
408 ctx.fillRect(0, 0, 100, 50);
410 ctx.strokeStyle = '#0f0';
412 ctx.arc(-50, 50, 100, 0, -Math.PI/2, true);
414 comparePixel(ctx, 50,25, 0,255,0,255);
415 comparePixel(ctx, 1,1, 0,255,0,255);
416 comparePixel(ctx, 98,1, 0,255,0,255);
417 comparePixel(ctx, 1,48, 0,255,0,255);
418 comparePixel(ctx, 98,48, 0,255,0,255);
422 function test_shape_5(row) {
423 var canvas = createCanvasObject(row);
424 var ctx = canvas.getContext('2d');
427 ctx.fillStyle = '#0f0';
428 ctx.fillRect(0, 0, 100, 50);
430 ctx.strokeStyle = '#f00';
432 ctx.arc(300, 0, 100, 0, 5*Math.PI, false);
434 comparePixel(ctx, 50,25, 0,255,0,255);
435 comparePixel(ctx, 1,1, 0,255,0,255);
436 comparePixel(ctx, 98,1, 0,255,0,255);
437 comparePixel(ctx, 1,48, 0,255,0,255);
438 comparePixel(ctx, 98,48, 0,255,0,255);
442 function test_twopie(row) {
443 var canvas = createCanvasObject(row);
444 var ctx = canvas.getContext('2d');
447 ctx.fillStyle = '#0f0';
448 ctx.fillRect(0, 0, 100, 50);
449 ctx.strokeStyle = '#f00';
452 ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true);
454 comparePixel(ctx, 50,20, 0,255,0,255);
457 ctx.fillStyle = '#f00';
458 ctx.fillRect(0, 0, 100, 50);
459 ctx.strokeStyle = '#0f0';
462 ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false);
464 comparePixel(ctx, 50,20, 0,255,0,255);
467 ctx.fillStyle = '#f00';
468 ctx.fillRect(0, 0, 100, 50);
469 ctx.strokeStyle = '#0f0';
472 ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true);
474 //FIXME:still different behavior from browsers, > 2pi span issue
475 //comparePixel(ctx, 50,20, 0,255,0,255);
478 ctx.fillStyle = '#f00';
479 ctx.fillRect(0, 0, 100, 50);
480 ctx.strokeStyle = '#0f0';
483 ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false);
485 comparePixel(ctx, 50,20, 0,255,0,255);
489 function test_zero(row) {
490 var canvas = createCanvasObject(row);
491 var ctx = canvas.getContext('2d');
494 ctx.fillStyle = '#0f0';
495 ctx.fillRect(0, 0, 100, 50);
496 ctx.strokeStyle = '#f00';
499 ctx.arc(50, 25, 50, 0, 0, true);
501 comparePixel(ctx, 50,20, 0,255,0,255);
504 ctx.fillStyle = '#0f0';
505 ctx.fillRect(0, 0, 100, 50);
506 ctx.strokeStyle = '#f00';
509 ctx.arc(50, 25, 50, 0, 0, false);
511 comparePixel(ctx, 50,20, 0,255,0,255);
514 ctx.fillStyle = '#f00'
515 ctx.fillRect(0, 0, 100, 50);
517 ctx.strokeStyle = '#0f0';
520 ctx.arc(200, 25, 0, 0, Math.PI, true);
522 comparePixel(ctx, 50,25, 0,255,0,255);