def test_line_line_segment(): l1 = Line(1, 1, 0) assert {P2(0, 0)} == intersect(l1, LineSegment(P2(-10, -10), P2(10, 10))) assert {P2(0, 0)} == intersect(LineSegment(P2(-10, -10), P2(10, 10)), l1) assert {P2(0, 0)} == intersect(l1, LineSegment(P2(10, 10), P2(-10, -10))) assert {P2(0, 0)} == intersect(LineSegment(P2(10, 10), P2(-10, -10)), l1) assert set() == intersect(l1, LineSegment(P2(1, 1), P2(10, 10)))
def test_line_segment_line_segment(): ls1 = LineSegment(P2(0, 0), P2(10, 10)) ls2 = LineSegment(P2(0, 10), P2(10, 0)) assert {P2(5, 5)} == intersect(ls1, ls2) assert {P2(5, 5)} == intersect(ls2, ls1) with pytest.raises(NotImplementedError): intersect(ls1, None) assert set() == intersect(ls1, LineSegment(P2(0, 5), P2(5, 10)))
def test_polygon_line_segment(): polygon = Polygon([P2(-1, -1), P2(1, -1), P2(1, 1), P2(-1, 1)]) ls = LineSegment(P2(0, 0), P2(10, 0)) assert {P2(1.0, 0.0)} == intersect(polygon, ls) assert {P2(1.0, 0.0)} == intersect(ls, polygon) ls = LineSegment(P2(-0.5, -0.5), P2(0.5, 0.5)) assert set() == intersect(polygon, ls) assert set() == intersect(ls, polygon) ls = LineSegment(P2(0, 0), P2(-10, -10)) assert {P2(-1.0, -1.0)} == intersect(polygon, ls) assert {P2(-1.0, -1.0)} == intersect(ls, polygon) ls = LineSegment(P2(0, -10), P2(0, 10)) assert {P2(0.0, -1.0), P2(0.0, 1.0)} == intersect(polygon, ls) assert {P2(0.0, -1.0), P2(0.0, 1.0)} == intersect(ls, polygon)