1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
""" Needed Tests
Joins
DONE 1. Each version same for all paths through aliased code.
DONE 2. Each version same for all paths through antialiased code.
Dashed Lines
*. Should be tested for all versions of aliasing and all versions
of join, cap.
Clipping
<Perhaps in different file>
1. Test that clip_to_rect is inclusive on lower end and exclusive
on upper end.
2. Test that clip_to_rect behaves intelligently under ctm transforms.
Note: There are numerous comments in code that refer to implementation
details (outline, outline_aa, scanline_aa, etc.) from the C++
code. These are largely to help keep track of what paths have
been tested.
"""
import unittest
from numpy import array, alltrue, ravel
from kiva.agg import GraphicsContextArray
import kiva
from test_utils import Utils
class JoinStrokePathTestCase(unittest.TestCase, Utils):
def helper(self, antialias, width, line_cap, line_join,
size=(10,10)):
gc = GraphicsContextArray(size, pix_format="rgb24")
# clear background to white values (255, 255, 255)
gc.clear((1.0, 1.0, 1.0))
# single horizontal line across bottom of buffer
gc.move_to(1, 3)
gc.line_to(7, 3)
gc.line_to(7, 9)
# Settings allow the faster outline path through C++ code
gc. set_stroke_color((0.0, 0.0, 0.0)) # black
gc.set_antialias(antialias)
gc.set_line_width(width)
gc.set_line_cap(line_cap)
gc.set_line_join(line_join)
gc.stroke_path()
return gc
def _test_alias_miter(self):
""" fix me: This is producing aliased output.
I am not sure what this array should look like
exactly, so we just force it to fail right now
and print out the results.
"""
antialias = False
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_MITER
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
assert 0, "join=miter, width=3, antialias=False\n%s" % actual
#assert_arrays_equal(actual, desired)
def _test_alias_bevel(self):
""" fix me: This is producing a line width of 4 instead of 3.
I am not sure what this array should look like
exactly, so we just force it to fail right now
and print out the results.
"""
antialias = False
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_BEVEL
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
assert 0, "join=bevel, width=3, antialias=False\n%s" % actual
#assert_arrays_equal(actual, desired)
def _test_alias_round(self):
""" fix me: This is producing a line width of 4 instead of 3.
Also, the corner doesn't look so round. I have
checked that the scanline_aa renderer is setting
the stroked_path.line_join() value to agg::round_join.
I am not sure what this array should look like
exactly, so we just force it to fail right now
and print out the results.
"""
antialias = False
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_ROUND
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
assert 0, "join=round, width=3, antialias=False\n%s" % actual
#assert_arrays_equal(actual, desired)
def test_antialias_miter(self):
""" fix me: How to make this pass on OS X and agg...
"""
antialias = True
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_MITER
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
desired = array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 127, 127, 127, 127, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 127, 255],
[255, 127, 127, 127, 127, 127, 127, 127, 191, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255]])
self.assertRavelEqual(actual, desired)
def test_antialias_bevel(self):
antialias = True
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_BEVEL
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
desired = array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 127, 127, 127, 127, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 31, 223, 255],
[255, 127, 127, 127, 127, 127, 127, 223, 255, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255]])
self.assertRavelEqual(actual, desired)
def test_antialias_round(self):
""" fix me: How to make this test work for multiple renderers?
"""
antialias = True
width = 3
line_cap = kiva.CAP_BUTT
line_join = kiva.JOIN_ROUND
gc = self.helper(antialias, width, line_cap, line_join)
actual = gc.bmp_array[:,:,0]
desired = array([[255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 255, 255, 255, 255, 127, 0, 0, 127, 255],
[255, 127, 127, 127, 127, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 127, 255],
[255, 0, 0, 0, 0, 0, 0, 0, 180, 255],
[255, 127, 127, 127, 127, 127, 127, 179, 253, 255],
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255]])
self.assertRavelEqual(actual, desired)
if __name__ == "__main__":
unittest.main()
|