class testMerge(unittest.TestCase): A = BBox(((-23.5, 456), (56, 532.0))) B = BBox(((-20.3, 460), (54, 465))) # B should be completely inside A C = BBox(((-23.5, 456), (58, 540.))) # up and to the right or A D = BBox(((-26.5, 12), (56, 532.0))) def testInside(self): C = self.A.copy() C.Merge(self.B) self.failUnless(C == self.A) def testFullOutside(self): C = self.B.copy() C.Merge(self.A) self.failUnless(C == self.A) def testUpRight(self): A = self.A.copy() A.Merge(self.C) self.failUnless(A[0] == self.A[0] and A[1] == self.C[1]) def testDownLeft(self): A = self.A.copy() A.Merge(self.D) self.failUnless(A[0] == self.D[0] and A[1] == self.A[1])
class testInfBBox(unittest.TestCase): B1 = InfBBox() B2 = InfBBox() B3 = BBox(((1.0, 2.0), (5., 10.))) NB = NullBBox() def testValues(self): self.failUnless(np.alltrue(np.isinf(self.B1))) # def testIsNull(self): # self.failUnless( self.B1.IsNull ) def testEquals(self): self.failUnless((self.B1 == self.B2) == True) def testNotEquals(self): print (self.B1 == self.B3) == False msg = '''NotEquals failed for {0}, {1}:{2}''' self.failUnless((self.B1 == self.B3) == False, msg.format(self.B1, self.B3, self.B1 == self.B3)) def testNotEquals2(self): msg = '''NotEquals failed for {0}, {1}:{2}''' self.failUnless((self.B3 == self.B1) == False, msg.format(self.B3, self.B1, self.B3 == self.B1)) def testMerge(self): C = self.B1.copy() C.Merge(self.B3) self.failUnless(C == self.B2, 'merge failed, got: %s' % C) def testMerge2(self): C = self.B3.copy() C.Merge(self.B1) self.failUnless(C == self.B1, 'merge failed, got: %s' % C) def testOverlaps(self): self.failUnless(self.B1.Overlaps(self.B2) == True) def testOverlaps2(self): self.failUnless(self.B3.Overlaps(self.B1) == True) def testOverlaps3(self): self.failUnless(self.B1.Overlaps(self.B3) == True) def testOverlaps4(self): self.failUnless(self.B1.Overlaps(self.NB) == True) def testOverlaps5(self): self.failUnless(self.NB.Overlaps(self.B1) == True)
class testAsPoly(unittest.TestCase): B = BBox(((5, 0), (10, 20))) corners = np.array([(5., 0.), (5., 20.), (10., 20.), (10., 0.)], dtype=np.float64) def testCorners(self): print self.B.AsPoly() self.failUnless(np.array_equal(self.B.AsPoly(), self.corners))
class testCenter(unittest.TestCase): B = BBox(((1.0, 2.0), (5., 10.))) def testCenter(self): self.failUnless((self.B.Center == (3.0, 6.0)).all()) def attemptSetCenter(self): self.B.Center = (6, 5) def testSetCenter(self): self.failUnlessRaises(AttributeError, self.attemptSetCenter)
class testSides(unittest.TestCase): B = BBox(((1.0, 2.0), (5., 10.))) def testLeft(self): self.failUnless(self.B.Left == 1.0) def testRight(self): self.failUnless(self.B.Right == 5.) def testBottom(self): self.failUnless(self.B.Bottom == 2.0) def testTop(self): self.failUnless(self.B.Top == 10.)
class testWidthHeight(unittest.TestCase): B = BBox(((1.0, 2.0), (5., 10.))) def testWidth(self): self.failUnless(self.B.Width == 4.0) def testWidth2(self): self.failUnless(self.B.Height == 8.0) def attemptSetWidth(self): self.B.Width = 6 def attemptSetHeight(self): self.B.Height = 6 def testSetW(self): self.failUnlessRaises(AttributeError, self.attemptSetWidth) def testSetH(self): self.failUnlessRaises(AttributeError, self.attemptSetHeight)
def testBelow(self): B = BBox(((5, 10), (15, 25))) P = (10, 5) self.failIf(B.PointInside(P))
def testArrayConstruction(self): A = np.array(((4, 5), (10, 12)), np.float_) B = BBox(A) self.failUnless(isinstance(B, BBox))
def testLowerLeft(self): B = BBox(((5, 10), (15, 25))) C = BBox(((-10, 5), (8.5, 15))) self.failIf(B.Inside(C))
def testPointOnLeft(self): B = BBox(((-10., -10.), (-1.0, -1.0))) P = (-10, -5.) self.failUnless(B.PointInside(P))
def testPointOnBottomRight(self): B = BBox(((-10., -10.), (-1.0, -1.0))) P = (-1, -10.) self.failUnless(B.PointInside(P))
def testLowerRight(self): B = BBox(((5, 10), (15, 25))) C = BBox(((12, 5), (25, 15))) self.failIf(B.Inside(C))
def testPointOnBottomLine(self): B = BBox(((1.0, 2.0), (5., 10.))) P = (3.0, 5.) self.failUnless(B.PointInside(P))
def testShape(self): B = BBox((0, 0, 5, 5)) self.failUnless(B.shape == (2, 2))
def testMinMax5(self): # OK to have a tiny BB B = BBox(((0, 0), (1e-20, 5))) self.failUnless(isinstance(B, BBox))
def testAbove(self): B = BBox(((5, 10), (15, 25))) C = BBox(((-10, 25.001), (8.5, 32))) self.failIf(B.Inside(C))
def testBelow(self): B = BBox(((5, 10), (15, 25))) C = BBox(((-10, 5), (8.5, 9.2))) self.failIf(B.Inside(C))
def testLowerLeft(self): B = BBox(((5, 10), (15, 25))) P = (-10, 5) self.failIf(B.PointInside(P))
def testLowerRight(self): B = BBox(((5, 10), (15, 25))) P = (16, 4) self.failIf(B.PointInside(P))
def testPointIn(self): B = BBox(((1.0, 2.0), (5., 10.))) P = (3.0, 4.0) self.failUnless(B.PointInside(P))
def testRight(self): B = BBox(((5, 10), (15, 25))) C = BBox(((17.1, 8), (17.95, 32))) self.failIf(B.Inside(C))
def testLeft(self): B = BBox(((5, 10), (15, 25))) C = BBox(((4, 8), (4.95, 32))) self.failIf(B.Inside(C))
def testMinMax3(self): # OK to have a zero-sized BB B = BBox(((0, 0), (0, 5))) self.failUnless(isinstance(B, BBox))
def testAbove(self): B = BBox(((5, 10), (15, 25))) P = (10, 25.001) self.failIf(B.PointInside(P))
def testMinMax4(self): # OK to have a zero-sized BB B = BBox(((10., -34), (10., -34.0))) self.failUnless(isinstance(B, BBox))
def testLeft(self): B = BBox(((5, 10), (15, 25))) P = (4, 12) self.failIf(B.PointInside(P))
def testRight(self): B = BBox(((5, 10), (15, 25))) P = (17.1, 12.3) self.failIf(B.PointInside(P))
def testPointLeftTopLine(self): B = BBox(((1.0, 2.0), (5., 10.))) P = (-3.0, 10.) self.failIf(B.PointInside(P))
def testPassThrough(self): B = BBox(((0, 0), (5, 5))) C = asBBox(B) self.failUnless(B is C)
def testUpperRight(self): B = BBox(((5, 10), (15, 25))) C = BBox(((12, 12), (25, 32.0))) self.failIf(B.Inside(C))