def test_polygon_centroid_1(): assert polygon_centroid(polygon1) == Point( 2.5, 2.5), f"Centroid function calculates the centroid not correctly."
from exercises.Ex_3 import * from exercises.helper_classes import Point p1 = Point(0, 0) p2 = Point(6, 0) p3 = Point(3, 5) p4 = Point(3, 1) p5 = Point(4, 2.5) p6 = Point(2, 2.5) arrayOfPoints = [p4, p5, p6] bbTriangle = Polygon(arrayOfPoints=[p1, p2, p3, p1]) # test delaunay triangulation def test_delaunay_triangulation_1(): assert delaunay_triangulation(arrayOfPoints, bbTriangle) == { Polygon(arrayOfPoints=[p1, p6, p3, p1]), Polygon(arrayOfPoints=[p6, p5, p3, p6]), Polygon(arrayOfPoints=[p5, p2, p3, p5]), Polygon(arrayOfPoints=[p4, p2, p5, p4]), Polygon(arrayOfPoints=[p1, p2, p4, p1]), Polygon(arrayOfPoints=[p1, p4, p6, p1]), Polygon(arrayOfPoints=[p6, p4, p5, p6]) }, f"DT was calculated wrongly"
from exercises.Ex_2 import * from exercises.helper_classes import Point, Polygon p1 = Point(0, 0) p2 = Point(5, 0) p3 = Point(5, 5) p4 = Point(0, 5) polygon1 = Polygon(arrayOfPoints=[p1, p2, p3, p4, p1]) # Centroid Test. def test_polygon_centroid_1(): assert polygon_centroid(polygon1) == Point( 2.5, 2.5), f"Centroid function calculates the centroid not correctly."
from exercises.Sheet_1 import * from exercises.helper_classes import Point, Polygon p1 = Point(0, 0) p2 = Point(5, 0) p3 = Point(5, 5) p4 = Point(0, 5) polygon1 = Polygon(arrayOfPoints=[p1, p2, p3, p4, p1]) p5 = Point(1, 1) p6 = Point(4, 1) p7 = Point(4, 4) p8 = Point(1, 4) polygon2 = Polygon(arrayOfPoints=[p5, p6, p7, p8, p5]) print(non_overlapping_area(polygon1, polygon2)) h1 = Point(2, 2) h2 = Point(3, 2) h3 = Point(3, 3) h4 = Point(2, 3) hole_p1 = Hole([h1, h2, h3, h4, h1]) polygon1.holes.append(hole_p1) polygonh2 = Polygon([h1, h2, h3, h4, h1]) p9 = Point(10, 10) p10 = Point(10, 15) p11 = Point(15, 15) p12 = Point(15, 10) polygon3 = Polygon([p9, p10, p11, p12, p9])
from exercises.Sheet_1 import * from exercises.helper_classes import Point, Polygon p1 = Point(0, 0) p2 = Point(5, 0) p3 = Point(5, 5) p4 = Point(0, 5) polygon1 = Polygon(arrayOfPoints=[p1, p2, p3, p4, p1]) p5 = Point(4.5, 4.5) p6 = Point(5.5, 4.5) p7 = Point(5.5, 5.5) p8 = Point(4.5, 5.5) polygon2 = Polygon(arrayOfPoints=[p5, p6, p7, p8, p5]) p9 = Point(-1, 0) p10 = Point(0.5, 2.6) p11 = Point(-1, 5.2) p12 = Point(-4, 5.2) p13 = Point(-5.5, 2.6) p14 = Point(-4, 0) polygon3 = Polygon([p9, p10, p11, p12, p13, p14, p9]) p15 = Point(0, 0) p16 = Point(-4, 2) p17 = Point(-7.73, -0.46) p18 = Point(-7.46, -4.93) p19 = Point(-3.46, -6.93) p20 = Point(0.27, -4.46) polygon4 = Polygon([p15, p16, p17, p18, p19, p20, p15])
from exercises.Ex_2 import * from exercises.helper_classes import Point, Polygon p1 = Point(0, 0) p2 = Point(1.05, 0.5) p3 = Point(1, 1) p4 = Point(2, 0) arrayOfPoints = [p1, p2, p3, p4] # MergeHull test def test_jarvis_march_1(): assert jarvis_march(arrayOfPoints) == [ p1, p4, p3 ], f"Convex Hull was calculated wrongly" if __name__ == "__main__": test_jarvis_march_1()
from exercises.Ex_2 import * from exercises.helper_classes import Point, Polygon p1 = Point(4, 5) p2 = Point(7, 3) p3 = Point(1, 2) p4 = Point(3, 3) p5 = Point(5, 0) p6 = Point(4, 2) p7 = Point(5, 3) arrayOfPoints = [p1, p2, p3, p4, p5, p6, p7] # Spiral polyline computation with Graham’s scan def test_spiral_1(): result = spiral(arrayOfPoints) assert result == [p3, p5, p2, p1, p4, p6, p7], f"Spiral polyline was calculated wrongly"
def test_point_intersection_plane_sweep_1(): intersections_detected = point_intersection_plane_sweep(list_of_lines) intersections_detected == [Point(3.00, 2.00)] assert is_polygon_convex( polygon1), f"Line intersections were detected wrongly."
from exercises.Ex_3 import * from exercises.helper_classes import Point, Line l1 = Line(Point(2, 0), Point(4, 4)) l2 = Line(Point(0, 4), Point(6, 0)) l3 = Line(Point(7, 0), Point(7, 5)) list_of_lines = [l1, l2, l3] # Test if plane sweep finds all intersections def test_point_intersection_plane_sweep_1(): intersections_detected = point_intersection_plane_sweep(list_of_lines) intersections_detected == [Point(3.00, 2.00)] assert is_polygon_convex( polygon1), f"Line intersections were detected wrongly."
from exercises.Sheet_1 import * from exercises.helper_classes import Point, Polygon, Line, Polyline p1 = Point(1, 3) p2 = Point(5, 3) p3 = Point(5, 6) p4 = Point(1, 6) polygon1 = Polygon(arrayOfPoints=[p1, p2, p3, p4, p1]) p5 = Point(3, 2) p6 = Point(7, 2) p7 = Point(7, 4) p8 = Point(3, 4) polygon2 = Polygon(arrayOfPoints=[p5, p6, p7, p8, p5]) l1 = Line(Point(4, 5), Point(6, 5)) l2 = Line(Point(6, 5), Point(9, 5)) polyline1 = Polyline([l1, l2]) l3 = Line(Point(3.5, 5), Point(3.5, 3)) l4 = Line(Point(3.5, 3), Point(3.5, 0)) polyline2 = Polyline([l3, l4]) # polyline lies completely inside the polygon def test_percentage_polylines_in_polygons_50(): result = percentage_polylines_in_polygons([polyline1, polyline2], [polygon1, polygon2]) assert result == [ polyline2 ], f"Polyline(s) with less than 50% of their length are selected as to be inside."
def test_bisector_1(): bis_calculated = bisector(p1, p2) assert bis_calculated == Line(Point(-0.5, 0.5), Point( 0.5, 0.5)), f"Bisector was calculated wrongly."
from exercises.Ex_3 import * from exercises.helper_classes import Point, Line p1 = Point(0, 0) p2 = Point(0, 1) # Test if bisector was calculated correctly def test_bisector_1(): bis_calculated = bisector(p1, p2) assert bis_calculated == Line(Point(-0.5, 0.5), Point( 0.5, 0.5)), f"Bisector was calculated wrongly."