def test_segments_in_rec(self): r = Rectangle((0,0), (19,16)) s = LineSegment(np.array([4,4]), np.array([11,9])) self.assertTrue(r.overlaps(s)) self.assertTrue(s.overlaps(r)) s2 = LineSegment(np.array([-2,6]), np.array([11,9])) self.assertTrue(r.overlaps(s2)) self.assertTrue(s2.overlaps(r))
def test_recs(self): r1 = Rectangle( (-1,-1), (8,7) ) r2 = Rectangle((8.79, 2.144), (17.79, 11.144)).rotate(-10, around_origin=False) self.assertFalse(r1.overlaps(r2)) self.assertFalse(r2.overlaps(r1)) r2 = Rectangle((8.5, 2.144), (17.5, 11.144)).rotate(-10, around_origin=False) # edges=list(r2.edges()) # self.assertEqual(len(edges), 4) # for e in edges: # print e.p1, e.p2 self.assertTrue(r1.overlaps(r2)) self.assertTrue(r2.overlaps(r1)) r = Rectangle((0.498, -12.082), (13.29, -0.124)) npt.assert_allclose(r.center(), np.array([ 6.894, -6.103])) r1 = r.rotate(10, False) npt.assert_allclose(r1.center(), np.array([ 6.894, -6.103])) rcopy = r1.copy() npt.assert_allclose(rcopy.center(), np.array([ 6.894, -6.103])) rcopy = rcopy.rotate(-10, False) npt.assert_allclose(rcopy.center(), np.array([ 6.894, -6.103])) npt.assert_allclose(r1.center(), np.array([ 6.894, -6.103])) r2 = Rectangle((0,-12), (13,0)).rotate(20, False) self.assertTrue(r1.overlaps(r2)) npt.assert_allclose(r1.center(), np.array([ 6.894, -6.103])) r2 = Rectangle((3,-9), (9,-5)).rotate(169, False) self.assertTrue(r1.overlaps(r2)) r2 = Rectangle((13,-5), (19,-1)).rotate(169, False) self.assertTrue(r1.overlaps(r2)) r2.move(np.array([1,0])) self.assertFalse(r1.overlaps(r2)) r1 = Rectangle((3,-8), (18,-2)).rotate(0) r2 = r1.copy().rotate(90, around_origin=False) self.assertTrue(r1.overlaps(r2)) r2.move(np.array([11,0])) self.assertFalse(r1.overlaps(r2)) r1 = Rectangle((3,-8), (18,-2)).rotate(10,False) r2 = Rectangle((-5,-8), (10,-2)).rotate(280,False) self.assertTrue(r1.overlaps(r2)) self.assertTrue(r2.overlaps(r1)) r2.move(np.array([-3,0])) self.assertFalse(r1.overlaps(r2)) self.assertFalse(r2.overlaps(r1))