2 <title>Canvas test:
2d.path.arcTo.shape.curve1
</title>
3 <!-- Testing: arcTo() curves in the right kind of shape -->
4 <script src=
"/MochiKit/MochiKit.js"></script>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
8 <canvas id=
"c" width=
"100" height=
"50"><p class=
"fallback">FAIL (fallback content)
</p></canvas>
10 function isPixel(ctx
, x
,y
, r
,g
,b
,a
, pos
, colour
, d
) {
11 var pixel
= ctx
.getImageData(x
, y
, 1, 1);
12 var pr
= pixel
.data
[0],
16 ok(r
-d
<= pr
&& pr
<= r
+d
&&
17 g
-d
<= pg
&& pg
<= g
+d
&&
18 b
-d
<= pb
&& pb
<= b
+d
&&
19 a
-d
<= pa
&& pa
<= a
+d
,
20 "pixel "+pos
+" is "+pr
+","+pg
+","+pb
+","+pa
+"; expected "+colour
+" +/- "+d
);
22 function todo_isPixel(ctx
, x
,y
, r
,g
,b
,a
, pos
, colour
, d
) {
23 var pixel
= ctx
.getImageData(x
, y
, 1, 1);
24 var pr
= pixel
.data
[0],
28 todo(r
-d
<= pr
&& pr
<= r
+d
&&
29 g
-d
<= pg
&& pg
<= g
+d
&&
30 b
-d
<= pb
&& pb
<= b
+d
&&
31 a
-d
<= pa
&& pa
<= a
+d
,
32 "pixel "+pos
+" is "+pr
+","+pg
+","+pb
+","+pa
+"; expected "+colour
+" +/- "+d
);
35 SimpleTest
.waitForExplicitFinish();
36 MochiKit
.DOM
.addLoadEvent(function () {
38 var canvas
= document
.getElementById('c');
39 var ctx
= canvas
.getContext('2d');
41 var tol
= 1.5; // tolerance to avoid antialiasing artifacts
43 ctx
.fillStyle
= '#0f0';
44 ctx
.fillRect(0, 0, 100, 50);
46 ctx
.strokeStyle
= '#f00';
50 ctx
.arcTo(75, 25, 75, 60, 20);
53 ctx
.fillStyle
= '#0f0';
55 ctx
.rect(10, 20, 45, 10);
57 ctx
.arc(55, 45, 25+tol
, 0, -Math
.PI
/2, true);
58 ctx
.arc(55, 45, 15-tol
, -Math
.PI
/2, 0, false);
61 isPixel(ctx
, 50,25, 0,255,0,255, "50,25", "0,255,0,255", 0);
62 isPixel(ctx
, 55,19, 0,255,0,255, "55,19", "0,255,0,255", 0);
63 isPixel(ctx
, 55,20, 0,255,0,255, "55,20", "0,255,0,255", 0);
64 isPixel(ctx
, 55,21, 0,255,0,255, "55,21", "0,255,0,255", 0);
65 isPixel(ctx
, 64,22, 0,255,0,255, "64,22", "0,255,0,255", 0);
66 isPixel(ctx
, 65,21, 0,255,0,255, "65,21", "0,255,0,255", 0);
67 isPixel(ctx
, 72,28, 0,255,0,255, "72,28", "0,255,0,255", 0);
68 isPixel(ctx
, 73,27, 0,255,0,255, "73,27", "0,255,0,255", 0);
69 isPixel(ctx
, 78,36, 0,255,0,255, "78,36", "0,255,0,255", 0);
70 isPixel(ctx
, 79,35, 0,255,0,255, "79,35", "0,255,0,255", 0);
71 isPixel(ctx
, 80,44, 0,255,0,255, "80,44", "0,255,0,255", 0);
72 todo_isPixel(ctx
, 80,45, 0,255,0,255, "80,45", "0,255,0,255", 0);
73 todo_isPixel(ctx
, 80,46, 0,255,0,255, "80,46", "0,255,0,255", 0);