MCPcopy Create free account
hub / github.com/Rhoban/placo / test_intersection

Method test_intersection

python/tests/segment_test.py:51–77  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

49 self.assertFalse(placo.Segment(p0, p1).is_point_in_segment(p4, 1e-5))
50
51 def test_intersection(self):
52 p0 = np.array([0, 0])
53 p1 = np.array([1, 1])
54 p2 = np.array([1, 0])
55 p3 = np.array([0, 1])
56 p4 = np.array([0.5, 0.5])
57 p5 = np.array([2, 2])
58 p6 = np.array([3, 3])
59 p7 = np.array([-1, 2])
60 # Intersect
61 self.assertTrue(placo.Segment(p0, p1).intersects(placo.Segment(p2, p3)))
62 self.assertFalse(placo.Segment(p5, p6).intersects(placo.Segment(p2, p3)))
63 # Lines intersection
64 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p2, p3))[0], p4[0])
65 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p2, p3))[1], p4[1])
66 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p3, p2))[0], p4[0])
67 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p3, p2))[1], p4[1])
68 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p2, p3))[0], placo.Segment(p2, p3).lines_intersection(placo.Segment(p0, p1))[0])
69 self.assertEqual(placo.Segment(p0, p1).lines_intersection(placo.Segment(p2, p3))[1], placo.Segment(p2, p3).lines_intersection(placo.Segment(p0, p1))[1])
70 # Line pass through
71 self.assertTrue(placo.Segment(p2, p3).line_pass_through(placo.Segment(p0, p1)))
72 self.assertTrue(placo.Segment(p2, p3).line_pass_through(placo.Segment(p5, p6)))
73 self.assertFalse(placo.Segment(p5, p6).line_pass_through(placo.Segment(p2, p3)))
74 # Half-line pass through
75 self.assertTrue(placo.Segment(p0, p1).half_line_pass_through(placo.Segment(p7, p3)))
76 self.assertFalse(placo.Segment(p0, p1).half_line_pass_through(placo.Segment(p3, p7)))
77 self.assertFalse(placo.Segment(p1, p5).half_line_pass_through(placo.Segment(p7, p3)))
78
79if __name__ == "__main__":
80 unittest.main()

Callers

nothing calls this directly

Calls 5

intersectsMethod · 0.80
SegmentMethod · 0.80
lines_intersectionMethod · 0.80
line_pass_throughMethod · 0.80

Tested by

no test coverage detected