def test_overlaps_other_20x8(self): """ With dims and positions used in L{Test_PositionEvaluator.test_with_others}:: 5 4 3 2 (267,261) +-------------------+ | 0 | | 9 | | 8 | | 7 (257,257) | | 6 | | 5 | (275,254) | 4 +-----------|-------+ (247,253) +-------------------+ | 2 | | 1 | | 9876543210987654321012345678901234|6789012345678901234|678 9 | (265,0) | 8 | | 7 | | 6 +-------------------+ 5 (255,246) 4 """ rr1 = a.RectangleRegion(MockAnnotation(), 15, 0, 20, 8) rr2 = a.RectangleRegion(MockAnnotation(), 7, 7, 20, 8) self.assertTrue(rr1.overlaps_other(rr2)) self.assertTrue(rr2.overlaps_other(rr1))
def test_arrow_line(self): rr = a.RectangleRegion(MockAnnotation(), 0, 0, 10, 10) Axy, Cxy = rr.arrow_line self.assertEqual(Axy, (250, 250)) self.assertEqual(Cxy, (250, 250)) rr = a.RectangleRegion(MockAnnotation(0.1, 0.1), 15, 10, 10, 10) Axy, Cxy = rr.arrow_line self.assertEqual(Axy, (275, 275)) self.assertEqual(Cxy, (290, 285))
def test_overlaps_arrow(self): # "Midway, lower", overlaps the other one's line dx1, dy1 = 30, -30 w1, h1 = 89.41, 18.785 ann1 = MockAnnotation(0.01, -0.0899, dx1, dy1, w1, h1) rr1 = a.RectangleRegion(ann1, dx1, dy1, w1, h1) # "Near Midway, lower", vertical line overlaps the other # annotation dx2, dy2 = 0, -71 w2, h2 = 120.785, 18.785 ann2 = MockAnnotation(0.01, -0.0899, dx2, dy2, w2, h2) rr2 = a.RectangleRegion(ann2, dx2, dy2, w2, h2) self.assertTrue(rr1.overlaps_line(*rr2.arrow_line))
def test_overlaps_line(self): def xyp(x, y): return [250 + z for z in (x, y)] def yes(xa, ya, xb, yb): self.assertTrue(rr.overlaps_line(xyp(xa, ya), xyp(xb, yb))) def no(xa, ya, xb, yb): self.assertFalse(rr.overlaps_line(xyp(xa, ya), xyp(xb, yb))) # Rectangular region with lower left at (-10,-5) and upper # right at (+10,+5). rr = a.RectangleRegion(MockAnnotation(), 0, 0, 20, 10) # Vertical lines no(-15, -15, -15, +15) # To the left no(+15, -15, +15, +15) # To the right yes(+5, -15, +5, +15) # Slightly off center # Horizontal lines no(-40, 0, -30, 0) # To the left no(+30, 0, +40, 0) # To the right yes(-30, +3, -5, +3) # Extending in from the left yes(+5, -3, +25, -3) # Extending in from the right no(-40, +8, +40, +8) # Above no(-40, -8, +40, -8) # Below # Ascending lines no(0, +8, +15, +16) # Entirely above no(-20, 0, +0, +18) # Above and to the left yes(-20, 0, +0, +9) # Not enough above and to the left yes(-100, -100, +100, +100) # Straight thru middle yes(0, -10, +20, +0) # Not enough above and to the left no(0, -18, +20, +0) # Below and to the right no(-15, -16, 0, -8) # Entirely below
def test_overlaps_point(self): rr = a.RectangleRegion(MockAnnotation(), 4, 4, 10, 10) self.assertTrue(rr.overlaps_point(250, 250)) self.assertTrue(rr.overlaps_point(255, 255)) self.assertFalse(rr.overlaps_point(280, 250)) # Right self.assertFalse(rr.overlaps_point(250, 280)) # Above self.assertFalse(rr.overlaps_point(230, 250)) # Left self.assertFalse(rr.overlaps_point(250, 230)) # Below
def test_with_boundary(self): ann = MockAnnotation() pos = a.PositionEvaluator(self.ax, self.pairs, [ann]) #--- Right in middle --------------------------------------------- rr = a.RectangleRegion(ann, 0, 0, 20, 8) self.assertEqual(pos.with_boundary(rr), 0) #--- To the right ------------------------------------------------ # Near but not touching right boundary rr = a.RectangleRegion(ann, 238, 0, 20, 8) self.assertEqual(pos.with_boundary(rr), 0) # Overlaps right subplot boundary but not figure boundary rr = a.RectangleRegion(ann, 245, 0, 20, 8) self.assertEqual(pos.with_boundary(rr), 3) # Overlaps right subplot boundary and figure boundary rr = a.RectangleRegion(ann, 255, 0, 20, 8) self.assertEqual(pos.with_boundary(rr), 9) #--- Below ------------------------------------------------------- # Near but not touching bottom boundary rr = a.RectangleRegion(ann, 100, -230, 20, 8) self.assertEqual(pos.with_boundary(rr), 0) # Overlaps bottom subplot boundary but not figure boundary rr = a.RectangleRegion(ann, 100, -248, 20, 8) self.assertEqual(pos.with_boundary(rr), 3) # Overlaps bottom subplot boundary and figure boundary rr = a.RectangleRegion(ann, 100, -257, 20, 8) self.assertEqual(pos.with_boundary(rr), 9)
def test_overlaps_other(self): def yes(rr1, rr2): self.assertTrue(rr1.overlaps_other(rr2)) self.assertTrue(rr2.overlaps_other(rr1)) def no(rr1, rr2): self.assertFalse(rr1.overlaps_other(rr2)) self.assertFalse(rr2.overlaps_other(rr1)) rr1 = a.RectangleRegion(MockAnnotation(), 0, 0, 20, 10) rr2 = a.RectangleRegion(MockAnnotation(), 18, 0, 20, 10) # Right 18 yes(rr1, rr2) rr3 = a.RectangleRegion(MockAnnotation(), 25, 0, 20, 10) # Right 25 no(rr1, rr3) yes(rr2, rr3) rr4 = a.RectangleRegion(MockAnnotation(), 0, 8, 20, 10) # Up 8 yes(rr1, rr4) no(rr3, rr4) rr4 = a.RectangleRegion(MockAnnotation(), 0, 20, 20, 10) # Up 20 for rr in rr1, rr2, rr3: no(rr4, rr)
def rr(dx, dy): return a.RectangleRegion(ann, dx, dy, 20, 8)