Ejemplo n.º 1
0
class TestMerge():

    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)
        assert (C == self.A)

    def testFullOutside(self):
        C = self.B.copy()
        C.Merge(self.A)
        assert (C == self.A)

    def testUpRight(self):
        A = self.A.copy()
        A.Merge(self.C)
        assert (A[0] == self.A[0] and A[1] == self.C[1])

    def testDownLeft(self):
        A = self.A.copy()
        A.Merge(self.D)
        assert (A[0] == self.D[0] and A[1] == self.A[1])
Ejemplo n.º 2
0
class TestNullBBox():

    B1 = NullBBox()
    B2 = NullBBox()
    B3 = BBox(((1.0, 2.0), (5., 10.)))

    def testValues(self):
        assert (np.alltrue(np.isnan(self.B1)))

    def testIsNull(self):
        assert (self.B1.IsNull)

    def testEquals(self):
        assert ((self.B1 == self.B2) is True)

    def testNotEquals(self):
        assert not self.B1 == self.B3

    def testNotEquals2(self):
        assert not self.B3 == self.B1

    def testMerge(self):
        C = self.B1.copy()
        C.Merge(self.B3)
        assert C == self.B3, 'merge failed, got: %s' % C

    def testOverlaps(self):
        assert self.B1.Overlaps(self.B3) is False

    def testOverlaps2(self):
        assert self.B3.Overlaps(self.B1) is False
Ejemplo n.º 3
0
class TestAsPoly():

    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())
        assert np.array_equal(self.B.AsPoly(), self.corners)
Ejemplo n.º 4
0
class TestCenter():

    B = BBox(((1.0, 2.0), (5., 10.)))

    def testCenter(self):
        assert ((self.B.Center == (3.0, 6.0)).all())

    def testSetCenter(self):
        with pytest.raises(AttributeError):
            self.B.Center = (6, 5)
Ejemplo n.º 5
0
class TestInfBBox():

    B1 = InfBBox()
    B2 = InfBBox()
    B3 = BBox(((1.0, 2.0), (5., 10.)))
    NB = NullBBox()

    def testValues(self):
        assert (np.alltrue(np.isinf(self.B1)))


#    def testIsNull(self):
#        assert ( self.B1.IsNull )

    def testEquals(self):
        assert self.B1 == self.B2

    def testNotEquals(self):
        assert not self.B1 == self.B3

    def testNotEquals2(self):
        assert self.B1 != self.B3

    def testNotEquals3(self):
        assert not self.B3 == self.B1

    def testMerge(self):
        C = self.B1.copy()
        C.Merge(self.B3)
        assert C == self.B2, 'merge failed, got: %s' % C

    def testMerge2(self):
        C = self.B3.copy()
        C.Merge(self.B1)
        assert C == self.B1, 'merge failed, got: %s' % C

    def testOverlaps(self):
        assert (self.B1.Overlaps(self.B2) is True)

    def testOverlaps2(self):
        assert (self.B3.Overlaps(self.B1) is True)

    def testOverlaps3(self):
        assert (self.B1.Overlaps(self.B3) is True)

    def testOverlaps4(self):
        assert (self.B1.Overlaps(self.NB) is True)

    def testOverlaps5(self):
        assert (self.NB.Overlaps(self.B1) is True)
Ejemplo n.º 6
0
class TestSides():

    B = BBox(((1.0, 2.0), (5., 10.)))

    def testLeft(self):
        assert self.B.Left == 1.0

    def testRight(self):
        assert self.B.Right == 5.0

    def testBottom(self):
        assert self.B.Bottom == 2.0

    def testTop(self):
        assert self.B.Top == 10.0
Ejemplo n.º 7
0
class TestWidthHeight():

    B = BBox(((1.0, 2.0), (5., 10.)))

    def testWidth(self):
        assert (self.B.Width == 4.0)

    def testWidth2(self):
        assert (self.B.Height == 8.0)

    def testSetW(self):
        with pytest.raises(AttributeError):
            self.B.Height = 6

    def testSetH(self):
        with pytest.raises(AttributeError):
            self.B.Width = 6
Ejemplo n.º 8
0
 def testLowerRight(self):
     B = BBox(((5, 10), (15, 25)))
     P = (16, 4)
     assert not (B.PointInside(P))
Ejemplo n.º 9
0
 def testMinMax(self):
     with pytest.raises(ValueError):
         BBox((0, 0, -1, 6))
Ejemplo n.º 10
0
 def testLowerLeft(self):
     B = BBox(((5, 10), (15, 25)))
     P = (-10, 5)
     assert not (B.PointInside(P))
Ejemplo n.º 11
0
 def testArrayConstruction(self):
     A = np.array(((4, 5), (10, 12)), np.float_)
     B = BBox(A)
     assert isinstance(B, BBox)
Ejemplo n.º 12
0
 def testBelow(self):
     B = BBox(((5, 10), (15, 25)))
     P = (10, 5)
     assert not (B.PointInside(P))
Ejemplo n.º 13
0
 def testLeft(self):
     B = BBox(((5, 10), (15, 25)))
     P = (4, 12)
     assert not (B.PointInside(P))
Ejemplo n.º 14
0
 def testMinMax4(self):
     # OK to have a zero-sized BB
     B = BBox(((10., -34), (10., -34.0)))
     assert isinstance(B, BBox)
Ejemplo n.º 15
0
 def testMinMax6(self):
     # Should catch tiny difference
     with pytest.raises(ValueError):
         BBox(((0, 0), (-1e-20, 5)))
Ejemplo n.º 16
0
 def testPointOnLeft(self):
     B = BBox(((-10., -10.), (-1.0, -1.0)))
     P = (-10, -5.)
     assert (B.PointInside(P))
Ejemplo n.º 17
0
 def testAbove(self):
     B = BBox(((5, 10), (15, 25)))
     P = (10, 25.001)
     assert not (B.PointInside(P))
Ejemplo n.º 18
0
 def testPointOnBottomLine(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (3.0, 5.)
     assert (B.PointInside(P))
Ejemplo n.º 19
0
 def testPointLeftTopLine(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (-3.0, 10.)
     assert not (B.PointInside(P))
Ejemplo n.º 20
0
 def testRight(self):
     B = BBox(((5, 10), (15, 25)))
     P = (17.1, 12.3)
     assert not (B.PointInside(P))
Ejemplo n.º 21
0
 def testMinMax2(self):
     with pytest.raises(ValueError):
         BBox((0, 0, 1, -6))
Ejemplo n.º 22
0
 def testPointIn(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (3.0, 4.0)
     assert (B.PointInside(P))
Ejemplo n.º 23
0
 def testPointOnBottomRight(self):
     B = BBox(((-10., -10.), (-1.0, -1.0)))
     P = (-1, -10.)
     assert (B.PointInside(P))
Ejemplo n.º 24
0
 def testShape(self):
     B = BBox((0, 0, 5, 5))
     assert B.shape == (2, 2)
Ejemplo n.º 25
0
    def testMinMax3(self):
        # OK to have a zero-sized BB

        B = BBox(((0, 0), (0, 5)))
        assert isinstance(B, BBox)
Ejemplo n.º 26
0
 def testShape2(self):
     with pytest.raises(ValueError):
         BBox((0, 0, 5))
Ejemplo n.º 27
0
 def testMinMax5(self):
     # OK to have a tiny BB
     B = BBox(((0, 0), (1e-20, 5)))
     assert isinstance(B, BBox)
Ejemplo n.º 28
0
 def testShape3(self):
     with pytest.raises(ValueError):
         BBox((0, 0, 5, 6, 7))
Ejemplo n.º 29
0
 def testPassThrough(self):
     B = BBox(((0, 0), (5, 5)))
     C = asBBox(B)
     assert B is C
Ejemplo n.º 30
0
 def testRight(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((17.1, 8), (17.95, 32)))
     assert not (B.Inside(C))