OLD | NEW |
| (Empty) |
1 description("Series of tests to ensure correct results of the winding rule."); | |
2 | |
3 | |
4 var tmpimg = document.createElement('canvas'); | |
5 tmpimg.width = 200; | |
6 tmpimg.height = 200; | |
7 ctx = tmpimg.getContext('2d'); | |
8 | |
9 // Create the image for blending test with images. | |
10 var img = document.createElement('canvas'); | |
11 img.width = 100; | |
12 img.height = 100; | |
13 var imgCtx = img.getContext('2d'); | |
14 | |
15 function pixelDataAtPoint() | |
16 { | |
17 return ctx.getImageData(50, 50, 1, 1).data; | |
18 } | |
19 | |
20 function checkResult(expectedColors, sigma) { | |
21 for (var i = 0; i < 4; i++) | |
22 shouldBeCloseTo("pixelDataAtPoint()[" + i + "]", expectedColors[i],
sigma); | |
23 } | |
24 | |
25 // Execute test. | |
26 function prepareTestScenario() { | |
27 debug('Testing default clip'); | |
28 ctx.fillStyle = 'rgb(255,0,0)'; | |
29 ctx.fillRect(0, 0, 100, 100); | |
30 ctx.fillStyle = 'rgb(0,255,0)'; | |
31 ctx.beginPath(); | |
32 ctx.rect(0, 0, 100, 100); | |
33 ctx.rect(25, 25, 50, 50); | |
34 ctx.clip(); | |
35 ctx.beginPath(); | |
36 ctx.fillRect(0, 0, 100, 100); | |
37 checkResult([0, 255, 0, 255], 5); | |
38 debug(''); | |
39 | |
40 debug('Testing nonzero clip'); | |
41 ctx.fillStyle = 'rgb(255,0,0)'; | |
42 ctx.fillRect(0, 0, 100, 100); | |
43 ctx.fillStyle = 'rgb(0,255,0)'; | |
44 ctx.beginPath(); | |
45 ctx.rect(0, 0, 100, 100); | |
46 ctx.rect(25, 25, 50, 50); | |
47 ctx.clip('nonzero'); | |
48 ctx.beginPath(); | |
49 ctx.fillRect(0, 0, 100, 100); | |
50 checkResult([0, 255, 0, 255], 5); | |
51 debug(''); | |
52 | |
53 debug('Testing evenodd clip'); | |
54 ctx.fillStyle = 'rgb(255,0,0)'; | |
55 ctx.fillRect(0, 0, 100, 100); | |
56 ctx.fillStyle = 'rgb(0,255,0)'; | |
57 ctx.beginPath(); | |
58 ctx.rect(0, 0, 100, 100); | |
59 ctx.rect(25, 25, 50, 50); | |
60 ctx.clip('evenodd'); | |
61 ctx.beginPath(); | |
62 ctx.fillRect(0, 0, 100, 100); | |
63 checkResult([255, 0, 0, 255], 5); | |
64 debug(''); | |
65 | |
66 } | |
67 | |
68 // Run test and allow variation of results. | |
69 prepareTestScenario(); | |
OLD | NEW |