def test_intersect_polygon_segments_zero_tolerance(): """Tests that the default tolerance of 0 does not update nearby polygons.""" pts0 = (Point2D(1, 0), Point2D(4, 0), Point2D(4, 1.99), Point2D(1, 1.99)) polygon0 = Polygon2D(pts0) pts1 = (Point2D(0, 2), Point2D(3, 2), Point2D(3, 4), Point2D(0, 4)) polygon1 = Polygon2D(pts1) polygon2, polygon3 = Polygon2D._intersect_polygon_segments( polygon0, polygon1) assert len(polygon2.segments) == 4 # No new points assert all([ polygon0.vertices[i] == polygon2.vertices[i] for i in range(len(polygon0.vertices)) ]) assert len(polygon3.segments) == 4 # No new points assert all([ polygon1.vertices[i] == polygon3.vertices[i] for i in range(len(polygon1.vertices)) ])
def test_intersect_polygon_segments_with_colinear_edges(): """Tests that the default tolerance of 0 updates polygons which share part of an edge segment.""" pts0 = (Point2D(1, 0), Point2D(4, 0), Point2D(4, 2), Point2D(1, 2)) polygon0 = Polygon2D(pts0) pts1 = (Point2D(0, 2), Point2D(3, 2), Point2D(3, 4), Point2D(0, 4)) polygon1 = Polygon2D(pts1) polygon0, polygon1 = Polygon2D._intersect_polygon_segments( polygon0, polygon1) # Extra vertex added to polygon0, as expected assert len(polygon0.segments) == 5 assert polygon0.vertices[3] == Point2D(3, 2) assert polygon0.segments[2].p2 == Point2D(3, 2) assert polygon0.segments[3].p1 == Point2D(3, 2) # Extra vertex added to polygon1, as expected assert len(polygon1.segments) == 5 assert polygon1.vertices[1] == Point2D(1, 2) assert polygon1.segments[0].p2 == Point2D(1, 2) assert polygon1.segments[1].p1 == Point2D(1, 2)
def test_intersect_polygon_segments(): """Tests that polygons within tolerance distance have vertices updated.""" tolerance = 0.01 pts0 = (Point2D(1, 0), Point2D(4, 0), Point2D(4, 1.99), Point2D(1, 1.99)) polygon0 = Polygon2D(pts0) pts1 = (Point2D(0, 2), Point2D(3, 2), Point2D(3, 4), Point2D(0, 4)) polygon1 = Polygon2D(pts1) polygon0, polygon1 = Polygon2D._intersect_polygon_segments( polygon0, polygon1, tolerance) # Extra vertex added to polygon0, as expected assert len(polygon0.segments) == 5 assert polygon0.vertices[3] == Point2D(3, 1.99) assert polygon0.segments[2].p2 == Point2D(3, 1.99) assert polygon0.segments[3].p1 == Point2D(3, 1.99) # Extra vertex added to polygon1, as expected assert len(polygon1.segments) == 5 assert polygon1.vertices[1] == Point2D(1, 2) assert polygon1.segments[0].p2 == Point2D(1, 2) assert polygon1.segments[1].p1 == Point2D(1, 2)