3 import "testhelper.js" as Helper
6 id:canvas; width:100;height:50; renderTarget: Canvas.Image
8 name: "arc"; when: windowShown
9 function test_angle_1() {
10 var ctx = canvas.getContext('2d');
13 ctx.fillStyle = '#0f0';
14 ctx.fillRect(0, 0, 100, 50);
15 ctx.fillStyle = '#f00';
18 ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true);
20 verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
22 function test_angle_2() {
23 var ctx = canvas.getContext('2d');
26 ctx.fillStyle = '#0f0';
27 ctx.fillRect(0, 0, 100, 50);
28 ctx.fillStyle = '#f00';
31 ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true);
33 verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
35 function test_angle_3() {
36 var ctx = canvas.getContext('2d');
38 ctx.fillStyle = '#0f0';
39 ctx.fillRect(0, 0, 100, 50);
40 ctx.fillStyle = '#f00';
43 ctx.arc(100, 0, 150, (512+1/2)*Math.PI, (1024-1)*Math.PI, true);
45 //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
47 function test_angle_4() {
48 var ctx = canvas.getContext('2d');
51 ctx.fillStyle = '#f00';
52 ctx.fillRect(0, 0, 100, 50);
53 ctx.fillStyle = '#0f0';
56 ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false);
58 verify(Helper.comparePixel(ctx,1,1, 0,255,0,255));
59 verify(Helper.comparePixel(ctx,98,1, 0,255,0,255));
60 verify(Helper.comparePixel(ctx,1,48, 0,255,0,255));
61 verify(Helper.comparePixel(ctx,98,48, 0,255,0,255));
63 function test_angle_5() {
64 var ctx = canvas.getContext('2d');
67 ctx.fillStyle = '#0f0';
68 ctx.fillRect(0, 0, 100, 50);
69 ctx.fillStyle = '#f00';
72 ctx.arc(100, 0, 150, (1024-1)*Math.PI, (512+1/2)*Math.PI, false);
76 expected:[0,255,0,255] +/- 0
78 //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
81 function test_angle_6() {
82 var ctx = canvas.getContext('2d');
85 ctx.fillStyle = '#f00';
86 ctx.fillRect(0, 0, 100, 50);
87 ctx.fillStyle = '#0f0';
90 ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true);
93 verify(Helper.comparePixel(ctx,1,1, 0,255,0,255));
94 verify(Helper.comparePixel(ctx,98,1, 0,255,0,255));
95 verify(Helper.comparePixel(ctx,1,48, 0,255,0,255));
96 verify(Helper.comparePixel(ctx,98,48, 0,255,0,255));
99 function test_empty() {
100 var ctx = canvas.getContext('2d');
103 ctx.fillStyle = '#0f0';
104 ctx.fillRect(0, 0, 100, 50);
106 ctx.strokeStyle = '#f00';
108 ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
111 actual :[255,0,0,255]
112 expected:[0,255,0,255] +/- 0
114 //verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
116 function test_nonempty() {
117 var ctx = canvas.getContext('2d');
120 ctx.fillStyle = '#f00';
121 ctx.fillRect(0, 0, 100, 50);
123 ctx.strokeStyle = '#0f0';
126 ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
128 verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
130 function test_nonfinite() {
132 var ctx = canvas.getContext('2d');
135 ctx.fillStyle = '#f00';
136 ctx.fillRect(0, 0, 100, 50);
139 ctx.arc(Infinity, 0, 50, 0, 2*Math.PI, true);
140 ctx.arc(-Infinity, 0, 50, 0, 2*Math.PI, true);
141 ctx.arc(NaN, 0, 50, 0, 2*Math.PI, true);
142 ctx.arc(0, Infinity, 50, 0, 2*Math.PI, true);
143 ctx.arc(0, -Infinity, 50, 0, 2*Math.PI, true);
144 ctx.arc(0, NaN, 50, 0, 2*Math.PI, true);
145 ctx.arc(0, 0, Infinity, 0, 2*Math.PI, true);
146 ctx.arc(0, 0, -Infinity, 0, 2*Math.PI, true);
147 ctx.arc(0, 0, NaN, 0, 2*Math.PI, true);
148 ctx.arc(0, 0, 50, Infinity, 2*Math.PI, true);
149 ctx.arc(0, 0, 50, -Infinity, 2*Math.PI, true);
150 ctx.arc(0, 0, 50, NaN, 2*Math.PI, true);
151 ctx.arc(0, 0, 50, 0, Infinity, true);
152 ctx.arc(0, 0, 50, 0, -Infinity, true);
153 ctx.arc(0, 0, 50, 0, NaN, true);
154 ctx.arc(Infinity, Infinity, 50, 0, 2*Math.PI, true);
155 ctx.arc(Infinity, Infinity, Infinity, 0, 2*Math.PI, true);
156 ctx.arc(Infinity, Infinity, Infinity, Infinity, 2*Math.PI, true);
157 ctx.arc(Infinity, Infinity, Infinity, Infinity, Infinity, true);
158 ctx.arc(Infinity, Infinity, Infinity, 0, Infinity, true);
159 ctx.arc(Infinity, Infinity, 50, Infinity, 2*Math.PI, true);
160 ctx.arc(Infinity, Infinity, 50, Infinity, Infinity, true);
161 ctx.arc(Infinity, Infinity, 50, 0, Infinity, true);
162 ctx.arc(Infinity, 0, Infinity, 0, 2*Math.PI, true);
163 ctx.arc(Infinity, 0, Infinity, Infinity, 2*Math.PI, true);
164 ctx.arc(Infinity, 0, Infinity, Infinity, Infinity, true);
165 ctx.arc(Infinity, 0, Infinity, 0, Infinity, true);
166 ctx.arc(Infinity, 0, 50, Infinity, 2*Math.PI, true);
167 ctx.arc(Infinity, 0, 50, Infinity, Infinity, true);
168 ctx.arc(Infinity, 0, 50, 0, Infinity, true);
169 ctx.arc(0, Infinity, Infinity, 0, 2*Math.PI, true);
170 ctx.arc(0, Infinity, Infinity, Infinity, 2*Math.PI, true);
171 ctx.arc(0, Infinity, Infinity, Infinity, Infinity, true);
172 ctx.arc(0, Infinity, Infinity, 0, Infinity, true);
173 ctx.arc(0, Infinity, 50, Infinity, 2*Math.PI, true);
174 ctx.arc(0, Infinity, 50, Infinity, Infinity, true);
175 ctx.arc(0, Infinity, 50, 0, Infinity, true);
176 ctx.arc(0, 0, Infinity, Infinity, 2*Math.PI, true);
177 ctx.arc(0, 0, Infinity, Infinity, Infinity, true);
178 ctx.arc(0, 0, Infinity, 0, Infinity, true);
179 ctx.arc(0, 0, 50, Infinity, Infinity, true);
182 ctx.fillStyle = '#0f0';
184 verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
185 verify(Helper.comparePixel(ctx,90,45, 0,255,0,255));
187 function test_end() {
188 var ctx = canvas.getContext('2d');
191 ctx.fillStyle = '#f00';
192 ctx.fillRect(0, 0, 100, 50);
194 ctx.strokeStyle = '#0f0';
197 ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true);
200 verify(Helper.comparePixel(ctx,50,25, 0,255,0,255));
202 function test_negative() {
203 var ctx = canvas.getContext('2d');
206 try { var err = false;
207 ctx.arc(0, 0, -1, 0, 0, true);
209 if (e.code != DOMException.INDEX_SIZE_ERR)
210 fail("expected exception of type INDEX_SIZE_ERR, got: "+e.message);
213 verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)");
218 function test_scale_1() {
219 var ctx = canvas.getContext('2d');
222 ctx.fillStyle = '#f00';
223 ctx.fillRect(0, 0, 100, 50);
225 ctx.fillStyle = '#0f0';
227 ctx.arc(25, 50, 56, 0, 2*Math.PI, false);
229 ctx.fillStyle = '#f00';
232 ctx.arc(-25, 50, 24, 0, 2*Math.PI, false);
234 ctx.arc(75, 50, 24, 0, 2*Math.PI, false);
236 ctx.arc(25, -25, 24, 0, 2*Math.PI, false);
238 ctx.arc(25, 125, 24, 0, 2*Math.PI, false);
241 verify(Helper.comparePixel(ctx, 0,0, 0,255,0,255));
242 verify(Helper.comparePixel(ctx, 50,0, 0,255,0,255));
243 //verify(Helper.comparePixel(ctx, 99,0, 0,255,0,255));
244 verify(Helper.comparePixel(ctx, 0,25, 0,255,0,255));
245 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
246 //verify(Helper.comparePixel(ctx, 99,25, 0,255,0,255));
247 //verify(Helper.comparePixel(ctx, 0,49, 0,255,0,255));
248 //verify(Helper.comparePixel(ctx, 50,49, 0,255,0,255));
249 //verify(Helper.comparePixel(ctx, 99,49, 0,255,0,255));
252 function test_scale_2() {
253 var ctx = canvas.getContext('2d');
256 ctx.fillStyle = '#f00';
257 ctx.fillRect(0, 0, 100, 50);
259 ctx.strokeStyle = '#0f0';
262 ctx.arc(0, 0, 0.6, 0, Math.PI/2, false);
265 verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
266 verify(Helper.comparePixel(ctx, 50,1, 0,255,0,255));
267 verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
268 verify(Helper.comparePixel(ctx, 1,25, 0,255,0,255));
269 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
270 verify(Helper.comparePixel(ctx, 98,25, 0,255,0,255));
271 verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
272 verify(Helper.comparePixel(ctx, 50,48, 0,255,0,255));
273 //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
276 function test_selfintersect_1() {
277 var ctx = canvas.getContext('2d');
280 ctx.fillStyle = '#0f0';
281 ctx.fillRect(0, 0, 100, 50);
283 ctx.strokeStyle = '#f00';
285 ctx.arc(100, 50, 25, 0, -Math.PI/2, true);
288 ctx.arc(0, 0, 25, 0, -Math.PI/2, true);
290 //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
291 //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
294 function test_selfintersect_2() {
295 var ctx = canvas.getContext('2d');
298 ctx.fillStyle = '#f00';
299 ctx.fillRect(0, 0, 100, 50);
301 ctx.strokeStyle = '#0f0';
303 ctx.arc(-50, 50, 25, 0, -Math.PI/2, true);
306 ctx.arc(100, 0, 25, 0, -Math.PI/2, true);
308 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
309 //verify(Helper.comparePixel(ctx, 90,10, 0,255,0,255));
310 //verify(Helper.comparePixel(ctx, 97,1, 0,255,0,255));
311 //verify(Helper.comparePixel(ctx, 97,2, 0,255,0,255));
312 //verify(Helper.comparePixel(ctx, 97,3, 0,255,0,255));
313 verify(Helper.comparePixel(ctx, 2,48, 0,255,0,255));
316 function test_shape_1() {
317 var ctx = canvas.getContext('2d');
320 ctx.fillStyle = '#0f0';
321 ctx.fillRect(0, 0, 100, 50);
323 ctx.strokeStyle = '#f00';
325 ctx.arc(50, 50, 50, 0, Math.PI, false);
327 //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
328 //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
329 verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
330 verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
331 verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255));
332 //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
335 function test_shape_2() {
336 var ctx = canvas.getContext('2d');
339 ctx.fillStyle = '#f00';
340 ctx.fillRect(0, 0, 100, 50);
342 ctx.strokeStyle = '#0f0';
344 ctx.arc(50, 50, 50, 0, Math.PI, true);
346 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
347 verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
348 verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
349 verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
350 verify(Helper.comparePixel(ctx, 20,48, 0,255,0,255));
351 verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
353 function test_shape_3() {
354 var ctx = canvas.getContext('2d');
357 ctx.fillStyle = '#0f0';
358 ctx.fillRect(0, 0, 100, 50);
360 ctx.strokeStyle = '#f00';
362 ctx.arc(0, 50, 50, 0, -Math.PI/2, false);
364 //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
365 //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
366 verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
367 //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
368 //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
371 function test_shape_4() {
372 var ctx = canvas.getContext('2d');
375 ctx.fillStyle = '#f00';
376 ctx.fillRect(0, 0, 100, 50);
378 ctx.strokeStyle = '#0f0';
380 ctx.arc(-50, 50, 100, 0, -Math.PI/2, true);
382 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
383 verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
384 verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
385 verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
386 verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
389 function test_shape_5() {
390 var ctx = canvas.getContext('2d');
393 ctx.fillStyle = '#0f0';
394 ctx.fillRect(0, 0, 100, 50);
396 ctx.strokeStyle = '#f00';
398 ctx.arc(300, 0, 100, 0, 5*Math.PI, false);
400 //verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));
401 //verify(Helper.comparePixel(ctx, 1,1, 0,255,0,255));
402 //verify(Helper.comparePixel(ctx, 98,1, 0,255,0,255));
403 //verify(Helper.comparePixel(ctx, 1,48, 0,255,0,255));
404 //verify(Helper.comparePixel(ctx, 98,48, 0,255,0,255));
407 function test_twopie() {
408 var ctx = canvas.getContext('2d');
411 ctx.fillStyle = '#0f0';
412 ctx.fillRect(0, 0, 100, 50);
413 ctx.strokeStyle = '#f00';
416 ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true);
418 //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
421 ctx.fillStyle = '#f00';
422 ctx.fillRect(0, 0, 100, 50);
423 ctx.strokeStyle = '#0f0';
426 ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false);
428 verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
431 ctx.fillStyle = '#f00';
432 ctx.fillRect(0, 0, 100, 50);
433 ctx.strokeStyle = '#0f0';
436 ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true);
438 verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
441 ctx.fillStyle = '#f00';
442 ctx.fillRect(0, 0, 100, 50);
443 ctx.strokeStyle = '#0f0';
446 ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false);
448 verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
451 function test_zero() {
452 var ctx = canvas.getContext('2d');
455 ctx.fillStyle = '#0f0';
456 ctx.fillRect(0, 0, 100, 50);
457 ctx.strokeStyle = '#f00';
460 ctx.arc(50, 25, 50, 0, 0, true);
462 //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
465 ctx.fillStyle = '#0f0';
466 ctx.fillRect(0, 0, 100, 50);
467 ctx.strokeStyle = '#f00';
470 ctx.arc(50, 25, 50, 0, 0, false);
472 //verify(Helper.comparePixel(ctx, 50,20, 0,255,0,255));
475 ctx.fillStyle = '#f00'
476 ctx.fillRect(0, 0, 100, 50);
478 ctx.strokeStyle = '#0f0';
481 ctx.arc(200, 25, 0, 0, Math.PI, true);
483 verify(Helper.comparePixel(ctx, 50,25, 0,255,0,255));