Update to 5.0.0-beta1
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickcanvasitem / data / tst_arc.qml
1 import QtQuick 2.0
2
3 CanvasTestCase {
4    id:testCase
5    name: "arc"
6    function init_data() { return testData("2d"); }
7        function test_angle_1(row) {
8            var canvas = createCanvasObject(row);
9            var ctx = canvas.getContext('2d');
10            ctx.reset();
11
12            ctx.fillStyle = '#0f0';
13            ctx.fillRect(0, 0, 100, 50);
14            ctx.fillStyle = '#f00';
15            ctx.beginPath();
16            ctx.moveTo(100, 0);
17            ctx.arc(100, 0, 150, Math.PI/2, -Math.PI, true);
18            ctx.fill();
19            comparePixel(ctx,50,25, 0,255,0,255);
20            canvas.destroy();
21         }
22        function test_angle_2(row) {
23            var canvas = createCanvasObject(row);
24            var ctx = canvas.getContext('2d');
25            ctx.reset();
26
27            ctx.fillStyle = '#0f0';
28            ctx.fillRect(0, 0, 100, 50);
29            ctx.fillStyle = '#f00';
30            ctx.beginPath();
31            ctx.moveTo(100, 0);
32            ctx.arc(100, 0, 150, -3*Math.PI/2, -Math.PI, true);
33            ctx.fill();
34            comparePixel(ctx,50,25, 0,255,0,255);
35            canvas.destroy();
36         }
37        function test_angle_3(row) {
38            var canvas = createCanvasObject(row);
39            var ctx = canvas.getContext('2d');
40            ctx.reset();
41            ctx.fillStyle = '#0f0';
42            ctx.fillRect(0, 0, 100, 50);
43            ctx.fillStyle = '#f00';
44            ctx.beginPath();
45            ctx.moveTo(100, 0);
46            ctx.arc(100, 0, 150, (512+1/2)*Math.PI, (1024-1)*Math.PI, true);
47            ctx.fill();
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);
51            */
52            canvas.destroy();
53         }
54        function test_angle_4(row) {
55            var canvas = createCanvasObject(row);
56            var ctx = canvas.getContext('2d');
57            ctx.reset();
58
59            ctx.fillStyle = '#f00';
60            ctx.fillRect(0, 0, 100, 50);
61            ctx.fillStyle = '#0f0';
62            ctx.beginPath();
63            ctx.moveTo(50, 25);
64            ctx.arc(50, 25, 60, (512+1/2)*Math.PI, (1024-1)*Math.PI, false);
65            ctx.fill();
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);
70            canvas.destroy();
71         }
72        function test_angle_5(row) {
73            var canvas = createCanvasObject(row);
74            var ctx = canvas.getContext('2d');
75            ctx.reset();
76
77            ctx.fillStyle = '#0f0';
78            ctx.fillRect(0, 0, 100, 50);
79            ctx.fillStyle = '#f00';
80            ctx.beginPath();
81            ctx.moveTo(100, 0);
82            ctx.arc(100, 0, 150, (1024-1)*Math.PI, (512+1/2)*Math.PI, false);
83            ctx.fill();
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);
87            */
88            canvas.destroy();
89         }
90
91        function test_angle_6(row) {
92            var canvas = createCanvasObject(row);
93            var ctx = canvas.getContext('2d');
94            ctx.reset();
95
96            ctx.fillStyle = '#f00';
97            ctx.fillRect(0, 0, 100, 50);
98            ctx.fillStyle = '#0f0';
99            ctx.beginPath();
100            ctx.moveTo(50, 25);
101            ctx.arc(50, 25, 60, (1024-1)*Math.PI, (512+1/2)*Math.PI, true);
102            ctx.fill();
103
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);
108            canvas.destroy();
109         }
110
111        function test_empty(row) {
112            var canvas = createCanvasObject(row);
113            var ctx = canvas.getContext('2d');
114            ctx.reset();
115
116            ctx.fillStyle = '#0f0';
117            ctx.fillRect(0, 0, 100, 50);
118            ctx.lineWidth = 50;
119            ctx.strokeStyle = '#f00';
120            ctx.beginPath();
121            ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
122            ctx.stroke();
123            comparePixel(ctx,50,25, 0,255,0,255);
124            canvas.destroy();
125         }
126        function test_nonempty(row) {
127            var canvas = createCanvasObject(row);
128            var ctx = canvas.getContext('2d');
129            ctx.reset();
130
131            ctx.fillStyle = '#f00';
132            ctx.fillRect(0, 0, 100, 50);
133            ctx.lineWidth = 50;
134            ctx.strokeStyle = '#0f0';
135            ctx.beginPath();
136            ctx.moveTo(0, 25);
137            ctx.arc(200, 25, 5, 0, 2*Math.PI, true);
138            ctx.stroke();
139            comparePixel(ctx,50,25, 0,255,0,255);
140            canvas.destroy();
141         }
142        function test_nonfinite(row) {
143            var canvas = createCanvasObject(row);
144            var ctx = canvas.getContext('2d');
145            ctx.reset();
146
147            ctx.fillStyle = '#f00';
148            ctx.fillRect(0, 0, 100, 50);
149            ctx.moveTo(0, 0);
150            ctx.lineTo(100, 0);
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);
192            ctx.lineTo(100, 50);
193            ctx.lineTo(0, 50);
194            ctx.fillStyle = '#0f0';
195            ctx.fill();
196            comparePixel(ctx,50,25, 0,255,0,255);
197            comparePixel(ctx,90,45, 0,255,0,255);
198            canvas.destroy();
199        }
200        function test_end(row) {
201            var canvas = createCanvasObject(row);
202            var ctx = canvas.getContext('2d');
203            ctx.reset();
204
205            ctx.fillStyle = '#f00';
206            ctx.fillRect(0, 0, 100, 50);
207            ctx.lineWidth = 50;
208            ctx.strokeStyle = '#0f0';
209            ctx.beginPath();
210            ctx.moveTo(-100, 0);
211            ctx.arc(-100, 0, 25, -Math.PI/2, Math.PI/2, true);
212            ctx.lineTo(100, 25);
213            ctx.stroke();
214            comparePixel(ctx,50,25, 0,255,0,255);
215            canvas.destroy();
216         }
217        function test_negative(row) {
218            var canvas = createCanvasObject(row);
219            var ctx = canvas.getContext('2d');
220            ctx.reset();
221
222            try { var err = false;
223              ctx.arc(0, 0, -1, 0, 0, true);
224            } catch (e) {
225                if (e.code != DOMException.INDEX_SIZE_ERR)
226                    fail("expected exception of type INDEX_SIZE_ERR, got: "+e.message);
227                err = true;
228            } finally {
229                verify(err, "should throw exception of type INDEX_SIZE_ERR: ctx.arc(0, 0, -1, 0, 0, true)");
230            }
231
232            canvas.destroy();
233        }
234
235        function test_scale_1(row) {
236            var canvas = createCanvasObject(row);
237            var ctx = canvas.getContext('2d');
238            ctx.reset();
239
240            ctx.fillStyle = '#f00';
241            ctx.fillRect(0, 0, 100, 50);
242            ctx.scale(2, 0.5);
243            ctx.fillStyle = '#0f0';
244            ctx.beginPath();
245            ctx.arc(25, 50, 56, 0, 2*Math.PI, false);
246            ctx.fill();
247            ctx.fillStyle = '#f00';
248            ctx.beginPath();
249            ctx.moveTo(-25, 50);
250            ctx.arc(-25, 50, 24, 0, 2*Math.PI, false);
251            ctx.moveTo(75, 50);
252            ctx.arc(75, 50, 24, 0, 2*Math.PI, false);
253            ctx.moveTo(25, -25);
254            ctx.arc(25, -25, 24, 0, 2*Math.PI, false);
255            ctx.moveTo(25, 125);
256            ctx.arc(25, 125, 24, 0, 2*Math.PI, false);
257            ctx.fill();
258
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);
268            canvas.destroy();
269        }
270
271        function test_scale_2(row) {
272            var canvas = createCanvasObject(row);
273            var ctx = canvas.getContext('2d');
274            ctx.reset();
275
276            ctx.fillStyle = '#f00';
277            ctx.fillRect(0, 0, 100, 50);
278            ctx.scale(100, 100);
279            ctx.strokeStyle = '#0f0';
280            ctx.lineWidth = 1.2;
281            ctx.beginPath();
282            ctx.arc(0, 0, 0.6, 0, Math.PI/2, false);
283            ctx.stroke();
284
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);
294            canvas.destroy();
295        }
296
297        function test_selfintersect_1(row) {
298            var canvas = createCanvasObject(row);
299            var ctx = canvas.getContext('2d');
300            ctx.reset();
301
302            ctx.fillStyle = '#0f0';
303            ctx.fillRect(0, 0, 100, 50);
304            ctx.lineWidth = 200;
305            ctx.strokeStyle = '#f00';
306            ctx.beginPath();
307            ctx.arc(100, 50, 25, 0, -Math.PI/2, true);
308            ctx.stroke();
309            ctx.beginPath();
310            ctx.arc(0, 0, 25, 0, -Math.PI/2, true);
311            ctx.stroke();
312            comparePixel(ctx, 1,1, 0,255,0,255);
313            comparePixel(ctx, 50,25, 0,255,0,255);
314            canvas.destroy();
315        }
316
317        function test_selfintersect_2(row) {
318            var canvas = createCanvasObject(row);
319            var ctx = canvas.getContext('2d');
320            ctx.reset();
321
322            ctx.fillStyle = '#f00';
323            ctx.fillRect(0, 0, 100, 50);
324            ctx.lineWidth = 180;
325            ctx.strokeStyle = '#0f0';
326            ctx.beginPath();
327            ctx.arc(-50, 50, 25, 0, -Math.PI/2, true);
328            ctx.stroke();
329            ctx.beginPath();
330            ctx.arc(100, 0, 25, 0, -Math.PI/2, true);
331            ctx.stroke();
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);
338            canvas.destroy();
339        }
340
341        function test_shape_1(row) {
342            var canvas = createCanvasObject(row);
343            var ctx = canvas.getContext('2d');
344            ctx.reset();
345
346            ctx.fillStyle = '#0f0';
347            ctx.fillRect(0, 0, 100, 50);
348            ctx.lineWidth = 50;
349            ctx.strokeStyle = '#f00';
350            ctx.beginPath();
351            ctx.arc(50, 50, 50, 0, Math.PI, false);
352            ctx.stroke();
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);
359            canvas.destroy();
360        }
361
362        function test_shape_2(row) {
363            var canvas = createCanvasObject(row);
364            var ctx = canvas.getContext('2d');
365            ctx.reset();
366
367            ctx.fillStyle = '#f00';
368            ctx.fillRect(0, 0, 100, 50);
369            ctx.lineWidth = 100;
370            ctx.strokeStyle = '#0f0';
371            ctx.beginPath();
372            ctx.arc(50, 50, 50, 0, Math.PI, true);
373            ctx.stroke();
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);
380            canvas.destroy();
381        }
382        function test_shape_3(row) {
383            var canvas = createCanvasObject(row);
384            var ctx = canvas.getContext('2d');
385            ctx.reset();
386
387            ctx.fillStyle = '#0f0';
388            ctx.fillRect(0, 0, 100, 50);
389            ctx.lineWidth = 100;
390            ctx.strokeStyle = '#f00';
391            ctx.beginPath();
392            ctx.arc(0, 50, 50, 0, -Math.PI/2, false);
393            ctx.stroke();
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);
399            canvas.destroy();
400        }
401
402        function test_shape_4(row) {
403            var canvas = createCanvasObject(row);
404            var ctx = canvas.getContext('2d');
405            ctx.reset();
406
407            ctx.fillStyle = '#f00';
408            ctx.fillRect(0, 0, 100, 50);
409            ctx.lineWidth = 150;
410            ctx.strokeStyle = '#0f0';
411            ctx.beginPath();
412            ctx.arc(-50, 50, 100, 0, -Math.PI/2, true);
413            ctx.stroke();
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);
419            canvas.destroy();
420        }
421
422        function test_shape_5(row) {
423            var canvas = createCanvasObject(row);
424            var ctx = canvas.getContext('2d');
425            ctx.reset();
426
427            ctx.fillStyle = '#0f0';
428            ctx.fillRect(0, 0, 100, 50);
429            ctx.lineWidth = 200;
430            ctx.strokeStyle = '#f00';
431            ctx.beginPath();
432            ctx.arc(300, 0, 100, 0, 5*Math.PI, false);
433            ctx.stroke();
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);
439            canvas.destroy();
440        }
441
442        function test_twopie(row) {
443            var canvas = createCanvasObject(row);
444            var ctx = canvas.getContext('2d');
445            ctx.reset();
446
447            ctx.fillStyle = '#0f0';
448            ctx.fillRect(0, 0, 100, 50);
449            ctx.strokeStyle = '#f00';
450            ctx.lineWidth = 100;
451            ctx.beginPath();
452            ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, true);
453            ctx.stroke();
454            comparePixel(ctx, 50,20, 0,255,0,255);
455            ctx.reset();
456
457            ctx.fillStyle = '#f00';
458            ctx.fillRect(0, 0, 100, 50);
459            ctx.strokeStyle = '#0f0';
460            ctx.lineWidth = 100;
461            ctx.beginPath();
462            ctx.arc(50, 25, 50, 0, 2*Math.PI - 1e-4, false);
463            ctx.stroke();
464            comparePixel(ctx, 50,20, 0,255,0,255);
465            ctx.reset();
466
467            ctx.fillStyle = '#f00';
468            ctx.fillRect(0, 0, 100, 50);
469            ctx.strokeStyle = '#0f0';
470            ctx.lineWidth = 100;
471            ctx.beginPath();
472            ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, true);
473            ctx.stroke();
474            //FIXME:still different behavior from browsers, > 2pi span issue
475            //comparePixel(ctx, 50,20, 0,255,0,255);
476            ctx.reset();
477
478            ctx.fillStyle = '#f00';
479            ctx.fillRect(0, 0, 100, 50);
480            ctx.strokeStyle = '#0f0';
481            ctx.lineWidth = 100;
482            ctx.beginPath();
483            ctx.arc(50, 25, 50, 0, 2*Math.PI + 1e-4, false);
484            ctx.stroke();
485            comparePixel(ctx, 50,20, 0,255,0,255);
486            canvas.destroy();
487        }
488
489        function test_zero(row) {
490            var canvas = createCanvasObject(row);
491            var ctx = canvas.getContext('2d');
492            ctx.reset();
493
494            ctx.fillStyle = '#0f0';
495            ctx.fillRect(0, 0, 100, 50);
496            ctx.strokeStyle = '#f00';
497            ctx.lineWidth = 100;
498            ctx.beginPath();
499            ctx.arc(50, 25, 50, 0, 0, true);
500            ctx.stroke();
501            comparePixel(ctx, 50,20, 0,255,0,255);
502            ctx.reset();
503
504            ctx.fillStyle = '#0f0';
505            ctx.fillRect(0, 0, 100, 50);
506            ctx.strokeStyle = '#f00';
507            ctx.lineWidth = 100;
508            ctx.beginPath();
509            ctx.arc(50, 25, 50, 0, 0, false);
510            ctx.stroke();
511            comparePixel(ctx, 50,20, 0,255,0,255);
512            ctx.reset();
513
514            ctx.fillStyle = '#f00'
515            ctx.fillRect(0, 0, 100, 50);
516            ctx.lineWidth = 50;
517            ctx.strokeStyle = '#0f0';
518            ctx.beginPath();
519            ctx.moveTo(0, 25);
520            ctx.arc(200, 25, 0, 0, Math.PI, true);
521            ctx.stroke();
522            comparePixel(ctx, 50,25, 0,255,0,255);
523            canvas.destroy();
524        }
525 }