class testMerge(wtc.WidgetTestCase): 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.0))) # 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.assertTrue(C == self.A) def testFullOutside(self): C = self.B.copy() C.Merge(self.A) self.assertTrue(C == self.A) def testUpRight(self): A = self.A.copy() A.Merge(self.C) self.assertTrue(A[0] == self.A[0] and A[1] == self.C[1]) def testDownLeft(self): A = self.A.copy() A.Merge(self.D) self.assertTrue(A[0] == self.D[0] and A[1] == self.A[1])
def CalcBoundingBox(self): if self.Scaled: self.BoundingBox = BBox.asBBox( ((self.XY-self.Diameter),(self.XY+self.Diameter)) ) else: self.BoundingBox = BBox.asBBox((self.XY, self.XY)) if self._Canvas: self._Canvas.BoundingBoxDirty = True
def ZoomToFit(self): # Calculate bounding box by hand, FC doesn't work right. points = list(itertools.chain(x.points for x in self.IterXforms())) self.ZoomToBB(NewBB=BBox.fromPoints(points), DrawFlag=False) # Factor of .8 is to leave some breathing room self.AdjustZoom(.8)
class testNullBBox(wtc.WidgetTestCase): B1 = NullBBox() B2 = NullBBox() B3 = BBox( ( (1.0, 2.0), (5.0, 10.0) ) ) def testValues(self): self.failUnless( N.alltrue(N.isnan(self.B1)) ) def testIsNull(self): self.failUnless( self.B1.IsNull ) def testEquals(self): self.failUnless( (self.B1 == self.B2) == True ) def testNotEquals(self): self.failUnless ( (self.B1 == self.B3) == False, "NotEquals failed for\n%s,\n %s:%s"%(self.B1, self.B3, (self.B1 == self.B3)) ) def testNotEquals2(self): self.failUnless ( (self.B3 == self.B1) == False, "NotEquals failed for\n%s,\n %s:%s"%(self.B3, self.B1, (self.B3 == self.B1)) ) def testMerge(self): C = self.B1.copy() C.Merge(self.B3) self.failUnless( C == self.B3, "merge failed, got: %s"%C ) def testOverlaps(self): self.failUnless( self.B1.Overlaps(self.B3) == False) def testOverlaps2(self): self.failUnless( self.B3.Overlaps(self.B1) == False)
class testCenter(wtc.WidgetTestCase): B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) ) 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(wtc.WidgetTestCase): B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) ) def testLeft(self): self.failUnless( self.B.Left == 1.0 ) def testRight(self): self.failUnless( self.B.Right == 5.0 ) def testBottom(self): self.failUnless( self.B.Bottom == 2.0 ) def testTop(self): self.failUnless( self.B.Top == 10.0 )
class testInfBBox(wtc.WidgetTestCase): B1 = InfBBox() B2 = InfBBox() B3 = BBox(((1.0, 2.0), (5.0, 10.0))) NB = NullBBox() def testValues(self): self.assertTrue(N.alltrue(N.isinf(self.B1))) # def testIsNull(self): # self.assertTrue( self.B1.IsNull ) def testEquals(self): self.assertTrue((self.B1 == self.B2) == True) def testNotEquals(self): self.assertTrue( (self.B1 == self.B3) == False, "NotEquals failed for\n%s,\n %s:%s" % (self.B1, self.B3, (self.B1 == self.B3))) def testNotEquals2(self): self.assertTrue( (self.B3 == self.B1) == False, "NotEquals failed for\n%s,\n %s:%s" % (self.B3, self.B1, (self.B3 == self.B1))) def testMerge(self): C = self.B1.copy() C.Merge(self.B3) self.assertTrue(C == self.B2, "merge failed, got: %s" % C) def testMerge2(self): C = self.B3.copy() C.Merge(self.B1) self.assertTrue(C == self.B1, "merge failed, got: %s" % C) def testOverlaps(self): self.assertTrue(self.B1.Overlaps(self.B2) == True) def testOverlaps2(self): self.assertTrue(self.B3.Overlaps(self.B1) == True) def testOverlaps3(self): self.assertTrue(self.B1.Overlaps(self.B3) == True) def testOverlaps4(self): self.assertTrue(self.B1.Overlaps(self.NB) == True) def testOverlaps5(self): self.assertTrue(self.NB.Overlaps(self.B1) == True)
def OnLeftUp(self, event): if event.LeftUp() and not self.StartRBBox is None: self.PrevRBBox = None EndRBBox = event.GetPosition() StartRBBox = self.StartRBBox # if mouse has moved less that ten pixels, don't use the box. if ( abs(StartRBBox[0] - EndRBBox[0]) > 10 and abs(StartRBBox[1] - EndRBBox[1]) > 10 ): EndRBBox = self.Canvas.PixelToWorld(EndRBBox) StartRBBox = self.Canvas.PixelToWorld(StartRBBox) self.Canvas.ZoomToBB( BBox.fromPoints(N.r_[EndRBBox,StartRBBox]) ) else: Center = self.Canvas.PixelToWorld(StartRBBox) self.Canvas.Zoom(1.5,Center) self.StartRBBox = None
class testWidthHeight(wtc.WidgetTestCase): B = BBox( ( (1.0, 2.0), (5.0, 10.0) ) ) def testWidth(self): self.failUnless(self.B.Width == 4.0) def testWidth(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 testAbove(self): B = BBox(((5, 10), (15, 25))) P = (10, 25.001) self.assertFalse(B.PointInside(P))
def testPointOnLeft(self): B = BBox(((-10.0, -10.0), (-1.0, -1.0))) P = (-10, -5.0) self.assertTrue(B.PointInside(P))
def testPointOnBottomRight(self): B = BBox(((-10.0, -10.0), (-1.0, -1.0))) P = (-1, -10.0) self.assertTrue(B.PointInside(P))
def testLowerRight(self): B = BBox(((5, 10), (15, 25))) P = (16, 4) self.assertFalse(B.PointInside(P))
def testPointIn(self): B = BBox(((1.0, 2.0), (5.0, 10.0))) P = (3.0, 4.0) self.assertTrue(B.PointInside(P))
def testUpperLeft(self): B = BBox(((5, 10), (15, 25))) C = BBox(((0, 12), (10, 32.0))) self.assertTrue(B.Overlaps(C))
def testPassThrough(self): B = BBox(((0, 0), (5, 5))) C = asBBox(B) self.assertTrue(B is C)
def testLowerLeft(self): B = BBox(((5, 10), (15, 25))) P = (-10, 5) self.assertFalse(B.PointInside(P))
def testMinMax(self): # OK to have a zero-sized BB B = BBox(((0, 0), (0, 5))) self.assertTrue(isinstance(B, BBox))
def testBelow(self): B = BBox(((5, 10), (15, 25))) P = (10, 5) self.assertFalse(B.PointInside(P))
def testMinMax2(self): # OK to have a zero-sized BB B = BBox(((10.0, -34), (10.0, -34.0))) self.assertTrue(isinstance(B, BBox))
def testLeft(self): B = BBox(((5, 10), (15, 25))) P = (4, 12) self.assertFalse(B.PointInside(P))
def testMinMax3(self): # OK to have a tiny BB B = BBox(((0, 0), (1e-20, 5))) self.assertTrue(isinstance(B, BBox))
def testRight(self): B = BBox(((5, 10), (15, 25))) P = (17.1, 12.3) self.assertFalse(B.PointInside(P))
def testSame(self): B = BBox(((-23.5, 456), (56, 532.0))) C = BBox(((-23.5, 456), (56, 532.0))) self.assertTrue(B.Overlaps(C))
def testPointLeftTopLine(self): B = BBox(((1.0, 2.0), (5.0, 10.0))) P = (-3.0, 10.0) self.assertFalse(B.PointInside(P))
def testUpperRight(self): B = BBox(((5, 10), (15, 25))) C = BBox(((12, 12), (25, 32.0))) self.assertTrue(B.Overlaps(C))
def CalcBoundingBox(self): self.BoundingBox = BBox.fromPoints(self.getEndPoints()) if self._Canvas: self._Canvas.BoundingBoxDirty = True
def testPointOnBottomLine(self): B = BBox(((1.0, 2.0), (5.0, 10.0))) P = (3.0, 5.0) self.assertTrue(B.PointInside(P))
def CalcBoundingBox(self): self.BoundingBox = BBox.fromPoints((self.Object1.GetConnectPoint(), self.Object2.GetConnectPoint()) ) if self._Canvas: self._Canvas.BoundingBoxDirty = True
def testArrayConstruction(self): A = N.array(((4, 5), (10, 12)), N.float_) B = BBox(A) self.assertTrue(isinstance(B, BBox))