]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatcanvas/Utilities/BBoxTest.py
3 Test code for the BBox Object
11 class testCreator(unittest
.TestCase
):
12 def testCreates(self
):
13 B
= BBox(((0,0),(5,5)))
14 self
.failUnless(isinstance(B
, BBox
))
17 B
= N
.array(((0,0),(5,5)))
18 self
.failIf(isinstance(B
, BBox
))
20 def testDataType(self
):
21 B
= BBox(((0,0),(5,5)))
22 self
.failUnless(B
.dtype
== N
.float)
26 self
.failUnless(B
.shape
== (2,2))
29 self
.failUnlessRaises(ValueError, BBox
, (0,0,5) )
32 self
.failUnlessRaises(ValueError, BBox
, (0,0,5,6,7) )
34 def testArrayConstruction(self
):
35 A
= N
.array(((4,5),(10,12)), N
.float_
)
37 self
.failUnless(isinstance(B
, BBox
))
40 self
.failUnlessRaises(ValueError, BBox
, (0,0,-1,6) )
42 def testMinMax2(self
):
43 self
.failUnlessRaises(ValueError, BBox
, (0,0,1,-6) )
46 # OK to have a zero-sized BB
47 B
= BBox(((0,0),(0,5)))
48 self
.failUnless(isinstance(B
, BBox
))
50 def testMinMax2(self
):
51 # OK to have a zero-sized BB
52 B
= BBox(((10.0,-34),(10.0,-34.0)))
53 self
.failUnless(isinstance(B
, BBox
))
55 def testMinMax3(self
):
56 # OK to have a tiny BB
57 B
= BBox(((0,0),(1e-20,5)))
58 self
.failUnless(isinstance(B
, BBox
))
60 def testMinMax4(self
):
61 # Should catch tiny difference
62 self
.failUnlessRaises(ValueError, BBox
, ((0,0), (-1e-20,5)) )
64 class testAsBBox(unittest
.TestCase
):
66 def testPassThrough(self
):
67 B
= BBox(((0,0),(5,5)))
69 self
.failUnless(B
is C
)
71 def testPassThrough2(self
):
76 def testPassArray(self
):
78 A
= N
.array( (((0,0),(5,5))) )
82 def testPassArray2(self
):
83 # same data type -- should be a view
84 A
= N
.array( (((0,0),(5,5))), N
.float_
)
87 self
.failUnless(C
[0,0] == A
[0,0])
89 class testIntersect(unittest
.TestCase
):
92 B
= BBox(((-23.5, 456),(56, 532.0)))
93 C
= BBox(((-23.5, 456),(56, 532.0)))
94 self
.failUnless(B
.Overlaps(C
) )
96 def testUpperLeft(self
):
97 B
= BBox( ( (5, 10),(15, 25) ) )
98 C
= BBox( ( (0, 12),(10, 32.0) ) )
99 self
.failUnless(B
.Overlaps(C
) )
101 def testUpperRight(self
):
102 B
= BBox( ( (5, 10),(15, 25) ) )
103 C
= BBox( ( (12, 12),(25, 32.0) ) )
104 self
.failUnless(B
.Overlaps(C
) )
106 def testLowerRight(self
):
107 B
= BBox( ( (5, 10),(15, 25) ) )
108 C
= BBox( ( (12, 5),(25, 15) ) )
109 self
.failUnless(B
.Overlaps(C
) )
111 def testLowerLeft(self
):
112 B
= BBox( ( (5, 10),(15, 25) ) )
113 C
= BBox( ( (-10, 5),(8.5, 15) ) )
114 self
.failUnless(B
.Overlaps(C
) )
117 B
= BBox( ( (5, 10),(15, 25) ) )
118 C
= BBox( ( (-10, 5),(8.5, 9.2) ) )
119 self
.failIf(B
.Overlaps(C
) )
122 B
= BBox( ( (5, 10),(15, 25) ) )
123 C
= BBox( ( (-10, 25.001),(8.5, 32) ) )
124 self
.failIf(B
.Overlaps(C
) )
127 B
= BBox( ( (5, 10),(15, 25) ) )
128 C
= BBox( ( (4, 8),(4.95, 32) ) )
129 self
.failIf(B
.Overlaps(C
) )
132 B
= BBox( ( (5, 10),(15, 25) ) )
133 C
= BBox( ( (17.1, 8),(17.95, 32) ) )
134 self
.failIf(B
.Overlaps(C
) )
136 def testInside(self
):
137 B
= BBox( ( (-15, -25),(-5, -10) ) )
138 C
= BBox( ( (-12, -22), (-6, -8) ) )
139 self
.failUnless(B
.Overlaps(C
) )
141 def testOutside(self
):
142 B
= BBox( ( (-15, -25),(-5, -10) ) )
143 C
= BBox( ( (-17, -26), (3, 0) ) )
144 self
.failUnless(B
.Overlaps(C
) )
147 B
= BBox( ( (5, 10),(15, 25) ) )
148 C
= BBox( ( (15, 8),(17.95, 32) ) )
149 self
.failUnless(B
.Overlaps(C
) )
151 def testCorner(self
):
152 B
= BBox( ( (5, 10),(15, 25) ) )
153 C
= BBox( ( (15, 25),(17.95, 32) ) )
154 self
.failUnless(B
.Overlaps(C
) )
156 def testZeroSize(self
):
157 B
= BBox( ( (5, 10),(15, 25) ) )
158 C
= BBox( ( (15, 25),(15, 25) ) )
159 self
.failUnless(B
.Overlaps(C
) )
161 def testZeroSize2(self
):
162 B
= BBox( ( (5, 10),(5, 10) ) )
163 C
= BBox( ( (15, 25),(15, 25) ) )
164 self
.failIf(B
.Overlaps(C
) )
166 def testZeroSize3(self
):
167 B
= BBox( ( (5, 10),(5, 10) ) )
168 C
= BBox( ( (0, 8),(10, 12) ) )
169 self
.failUnless(B
.Overlaps(C
) )
171 def testZeroSize4(self
):
172 B
= BBox( ( (5, 1),(10, 25) ) )
173 C
= BBox( ( (8, 8),(8, 8) ) )
174 self
.failUnless(B
.Overlaps(C
) )
178 class testEquality(unittest
.TestCase
):
180 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
181 C
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
182 self
.failUnless(B
== C
)
184 def testIdentical(self
):
185 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
186 self
.failUnless(B
== B
)
188 def testNotSame(self
):
189 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
190 C
= BBox( ( (1.0, 2.0), (5.0, 10.1) ) )
193 def testWithArray(self
):
194 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
195 C
= N
.array( ( (1.0, 2.0), (5.0, 10.0) ) )
196 self
.failUnless(B
== C
)
198 def testWithArray2(self
):
199 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
200 C
= N
.array( ( (1.0, 2.0), (5.0, 10.0) ) )
201 self
.failUnless(C
== B
)
203 def testWithArray2(self
):
204 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
205 C
= N
.array( ( (1.01, 2.0), (5.0, 10.0) ) )
208 class testInside(unittest
.TestCase
):
210 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
211 C
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
212 self
.failUnless(B
.Inside(C
))
215 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
216 C
= BBox( ( (3.0, 4.0), (3.0, 4.0) ) )
217 self
.failUnless(B
.Inside(C
))
219 def testPointOutside(self
):
220 B
= BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
221 C
= BBox( ( (-3.0, 4.0), (0.10, 4.0) ) )
222 self
.failIf(B
.Inside(C
))
224 def testUpperLeft(self
):
225 B
= BBox( ( (5, 10),(15, 25) ) )
226 C
= BBox( ( (0, 12),(10, 32.0) ) )
227 self
.failIf(B
.Inside(C
) )
229 def testUpperRight(self
):
230 B
= BBox( ( (5, 10),(15, 25) ) )
231 C
= BBox( ( (12, 12),(25, 32.0) ) )
232 self
.failIf(B
.Inside(C
) )
234 def testLowerRight(self
):
235 B
= BBox( ( (5, 10),(15, 25) ) )
236 C
= BBox( ( (12, 5),(25, 15) ) )
237 self
.failIf(B
.Inside(C
) )
239 def testLowerLeft(self
):
240 B
= BBox( ( (5, 10),(15, 25) ) )
241 C
= BBox( ( (-10, 5),(8.5, 15) ) )
242 self
.failIf(B
.Inside(C
) )
245 B
= BBox( ( (5, 10),(15, 25) ) )
246 C
= BBox( ( (-10, 5),(8.5, 9.2) ) )
247 self
.failIf(B
.Inside(C
) )
250 B
= BBox( ( (5, 10),(15, 25) ) )
251 C
= BBox( ( (-10, 25.001),(8.5, 32) ) )
252 self
.failIf(B
.Inside(C
) )
255 B
= BBox( ( (5, 10),(15, 25) ) )
256 C
= BBox( ( (4, 8),(4.95, 32) ) )
257 self
.failIf(B
.Inside(C
) )
260 B
= BBox( ( (5, 10),(15, 25) ) )
261 C
= BBox( ( (17.1, 8),(17.95, 32) ) )
262 self
.failIf(B
.Inside(C
) )
264 class testFromPoints(unittest
.TestCase
):
266 def testCreate(self
):
267 Pts
= N
.array( ((5,2),
272 #B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) )
273 self
.failUnless(B
[0,0] == 1.0 and
278 def testCreateInts(self
):
279 Pts
= N
.array( ((5,2),
284 self
.failUnless(B
[0,0] == 1.0 and
290 def testSinglePoint(self
):
291 Pts
= N
.array( (5,2), N
.float_
)
293 self
.failUnless(B
[0,0] == 5.0 and
299 def testListTuples(self
):
307 self
.failUnless(B
[0,0] == -4.32 and
312 class testMerge(unittest
.TestCase
):
313 A
= BBox( ((-23.5, 456), (56, 532.0)) )
314 B
= BBox( ((-20.3, 460), (54, 465 )) )# B should be completely inside A
315 C
= BBox( ((-23.5, 456), (58, 540.0)) )# up and to the right or A
316 D
= BBox( ((-26.5, 12), (56, 532.0)) )
318 def testInside(self
):
321 self
.failUnless(C
== self
.A
)
323 def testFullOutside(self
):
326 self
.failUnless(C
== self
.A
)
328 def testUpRight(self
):
331 self
.failUnless(A
[0] == self
.A
[0] and A
[1] == self
.C
[1])
333 def testDownLeft(self
):
336 self
.failUnless(A
[0] == self
.D
[0] and A
[1] == self
.A
[1])
338 class testBBarray(unittest
.TestCase
):
339 BBarray
= N
.array( ( ((-23.5, 456), (56, 532.0)),
340 ((-20.3, 460), (54, 465 )),
341 ((-23.5, 456), (58, 540.0)),
342 ((-26.5, 12), (56, 532.0)),
346 BB
= asBBox( ((-26.5, 12.), ( 58. , 540.)) )
349 BB
= fromBBArray(self
.BBarray
)
350 self
.failUnless(BB
== self
.BB
, "Wrong BB was created. It was:\n%s \nit should have been:\n%s"%(BB
, self
.BB
))
353 if __name__
== "__main__":