Beispiel #1
0
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])
Beispiel #2
0
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)
Beispiel #3
0
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))
Beispiel #4
0
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)
Beispiel #5
0
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.)
Beispiel #6
0
def plot_LEs(positions, filename='le_plot.png'):
    """
    plot the LEs and save as an image
    """
    # compute the bounding box:
    bb = BBox.fromPoints(positions)
    # bb.scale(1.1)

    canvas = map_canvas.MapCanvas(
        (500, 500),
        viewport=bb,
        preset_colors='web',
        background_color='white',
    )

    canvas.draw_points(positions,
                       diameter=1,
                       color='black',
                       shape="round",
                       background=False)
    canvas.save("test.png")
Beispiel #7
0
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)
Beispiel #8
0
def plot_LEs(positions, filename='le_plot.png'):
    """
    plot the LEs and save as an image
    """
    # compute the bounding box:
    bb = BBox.fromPoints(positions)
    # bb.scale(1.1)

    canvas = map_canvas.MapCanvas((500, 500),
                                  viewport=bb,
                                  preset_colors='web',
                                  background_color='white',
                                  )


    canvas.draw_points(positions,
                       diameter=1,
                       color='black',
                       shape="round",
                       background=False
                       )
    canvas.save("test.png")
Beispiel #9
0
 def testLeft(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((4, 8), (4.95, 32)))
     self.failIf(B.Inside(C))
Beispiel #10
0
 def testArrayConstruction(self):
     A = np.array(((4, 5), (10, 12)), np.float_)
     B = BBox(A)
     self.failUnless(isinstance(B, BBox))
Beispiel #11
0
 def testPointOnBottomRight(self):
     B = BBox(((-10., -10.), (-1.0, -1.0)))
     P = (-1, -10.)
     self.failUnless(B.PointInside(P))
Beispiel #12
0
 def testPointIn(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (3.0, 4.0)
     self.failUnless(B.PointInside(P))
Beispiel #13
0
 def testShape(self):
     B = BBox((0, 0, 5, 5))
     self.failUnless(B.shape == (2, 2))
Beispiel #14
0
 def testBelow(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((-10, 5), (8.5, 9.2)))
     self.failIf(B.Inside(C))
Beispiel #15
0
    def testMinMax5(self):

        # OK to have a tiny BB

        B = BBox(((0, 0), (1e-20, 5)))
        self.failUnless(isinstance(B, BBox))
Beispiel #16
0
 def testLeft(self):
     B = BBox(((5, 10), (15, 25)))
     P = (4, 12)
     self.failIf(B.PointInside(P))
Beispiel #17
0
 def testAbove(self):
     B = BBox(((5, 10), (15, 25)))
     P = (10, 25.001)
     self.failIf(B.PointInside(P))
Beispiel #18
0
 def testBelow(self):
     B = BBox(((5, 10), (15, 25)))
     P = (10, 5)
     self.failIf(B.PointInside(P))
Beispiel #19
0
 def testLowerLeft(self):
     B = BBox(((5, 10), (15, 25)))
     P = (-10, 5)
     self.failIf(B.PointInside(P))
Beispiel #20
0
 def testLowerRight(self):
     B = BBox(((5, 10), (15, 25)))
     P = (16, 4)
     self.failIf(B.PointInside(P))
Beispiel #21
0
 def testAbove(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((-10, 25.001), (8.5, 32)))
     self.failIf(B.Inside(C))
Beispiel #22
0
    def testMinMax3(self):

        # OK to have a zero-sized BB

        B = BBox(((0, 0), (0, 5)))
        self.failUnless(isinstance(B, BBox))
Beispiel #23
0
 def testLowerLeft(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((-10, 5), (8.5, 15)))
     self.failIf(B.Inside(C))
Beispiel #24
0
    def testMinMax4(self):

        # OK to have a zero-sized BB

        B = BBox(((10., -34), (10., -34.0)))
        self.failUnless(isinstance(B, BBox))
Beispiel #25
0
 def testPointOnLeft(self):
     B = BBox(((-10., -10.), (-1.0, -1.0)))
     P = (-10, -5.)
     self.failUnless(B.PointInside(P))
Beispiel #26
0
 def testRight(self):
     B = BBox(((5, 10), (15, 25)))
     P = (17.1, 12.3)
     self.failIf(B.PointInside(P))
Beispiel #27
0
 def testRight(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((17.1, 8), (17.95, 32)))
     self.failIf(B.Inside(C))
Beispiel #28
0
 def testPassThrough(self):
     B = BBox(((0, 0), (5, 5)))
     C = asBBox(B)
     self.failUnless(B is C)
Beispiel #29
0
 def testPointLeftTopLine(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (-3.0, 10.)
     self.failIf(B.PointInside(P))
Beispiel #30
0
 def testPointOnBottomLine(self):
     B = BBox(((1.0, 2.0), (5., 10.)))
     P = (3.0, 5.)
     self.failUnless(B.PointInside(P))
Beispiel #31
0
 def testLowerRight(self):
     B = BBox(((5, 10), (15, 25)))
     C = BBox(((12, 5), (25, 15)))
     self.failIf(B.Inside(C))