def test_mars0001_1(): points = [(20.1273, 18.7303), (26.5107, 18.7303), (20.1273, 23.8437), (26.5107, 23.8437)] polygon = Polygon([ (15., 15.), (15., 30.), (30., 30.), (30., 15.), ]) sizes = [52.3, 42.0, 72.48, 58.21] _execute(polygon, points, sizes)
def test_vertices_correct(): points = [(2.5, 2.5), (4, 7.5), (7.5, 2.5), (6, 7.5), (4, 4), (3, 3), (6, 3)] polygon = Polygon([(2.5, 10), (5, 10), (10, 5), (10, 2.5), (5, 0), (2.5, 0), (0, 2.5), (0, 5)]) expected = [[[(2.5, 0.0), (4.642857142857143, 0.0)], [(2.5, 0.0), (0.0, 2.5)]], [[(4.642857142857143, 0.0), (4.5, 1.0)], [(4.642857142857143, 0.0), (5.0, 0.0)], [(4.642857142857143, 0.0), (2.5, 0.0)]], [[(5.0, 0.0), (6.0, 0.5)], [(5.0, 0.0), (4.642857142857143, 0.0)]], [[(6.0, 0.5), (7.583333333333333, 5.25)], [(6.0, 0.5), (10.0, 2.5)], [(6.0, 0.5), (5.0, 0.0)]], [[(4.5, 1.0), (4.5, 2.5)], [(4.5, 1.0), (0.16666666666666607, 5.333333333333334)], [(4.5, 1.0), (4.642857142857143, 0.0)]], [[(0.0, 2.5), (2.5, 0.0)], [(0.0, 2.5), (0.0, 5.0)]], [[(4.5, 2.5), (5.875, 5.25)], [(4.5, 2.5), (1.25, 5.75)], [(4.5, 2.5), (4.5, 1.0)]], [[(10.0, 2.5), (10.0, 5.0)], [(10.0, 2.5), (6.0, 0.5)]], [[(0.0, 5.0), (0.16666666666666607, 5.333333333333334)], [(0.0, 5.0), (0.0, 2.5)]], [[(10.0, 5.0), (9.25, 5.75)], [(10.0, 5.0), (10.0, 2.5)]], [[(5.875, 5.25), (5.0, 5.75)], [(5.875, 5.25), (7.583333333333333, 5.25)], [(5.875, 5.25), (4.5, 2.5)]], [[(7.583333333333333, 5.25), (6.0, 0.5)], [(7.583333333333333, 5.25), (5.875, 5.25)], [(7.583333333333333, 5.25), (9.25, 5.75)]], [[(0.16666666666666607, 5.333333333333334), (4.5, 1.0)], [(0.16666666666666607, 5.333333333333334), (0.0, 5.0)], [(0.16666666666666607, 5.333333333333334), (0.4624999999999999, 5.925)]], [[(1.25, 5.75), (4.5, 2.5)], [(1.25, 5.75), (5.0, 5.75)], [(1.25, 5.75), (0.4624999999999999, 5.925)]], [[(5.0, 5.75), (1.25, 5.75)], [(5.0, 5.75), (5.0, 10.0)], [(5.0, 5.75), (5.875, 5.25)]], [[(9.25, 5.75), (7.583333333333333, 5.25)], [(9.25, 5.75), (5.0, 10.0)], [(9.25, 5.75), (10.0, 5.0)]], [[(0.4624999999999999, 5.925), (1.25, 5.75)], [(0.4624999999999999, 5.925), (0.16666666666666607, 5.333333333333334)], [(0.4624999999999999, 5.925), (2.5, 10.0)]], [[(2.5, 10.0), (0.4624999999999999, 5.925)], [(2.5, 10.0), (5.0, 10.0)]], [[(5.0, 10.0), (2.5, 10.0)], [(5.0, 10.0), (5.0, 10.0)]], [[(5.0, 10.0), (5.0, 5.75)], [(5.0, 10.0), (5.0, 10.0)], [(5.0, 10.0), (9.25, 5.75)]]] _test_vertices_correct(polygon, points, expected, False)
def test_mars0001_2(): points = [(0.3308, 0.204), (10.1432, 0.204), (19.9556, 0.204), (29.768, 0.204), (0.3308, 7.942), (10.1432, 7.942), (19.9556, 7.942), (29.768, 7.942), (0.3308, 15.6801), (10.1432, 15.6801), (19.9556, 15.6801), (29.768, 15.6801), (0.3308, 23.4181), (10.1432, 23.4181), (19.9556, 23.4181), (29.768, 23.4181)] polygon = Polygon([ (0, -10), (0., 35.), (35., 35.), (35., -10.), ]) sizes = [ 73.7, 138.09, 138.09, 142.67, 40.52, 75.93, 75.93, 78.45, 40.52, 75.93, 75.93, 78.45, 80.92, 151.61, 151.61, 156.64 ] _execute(polygon, points, sizes)
def test_large_grid(): points = [[0.3308, 0.204], [4.5361, 0.204], [8.7414, 0.204], [12.9467, 0.204], [17.1521, 0.204], [21.3574, 0.204], [25.5627, 0.204], [29.768, 0.204], [0.3308, 3.5203], [4.5361, 3.5203], [8.7414, 3.5203], [12.9467, 3.5203], [17.1521, 3.5203], [21.3574, 3.5203], [25.5627, 3.5203], [29.768, 3.5203], [0.3308, 6.8366], [4.5361, 6.8366], [8.7414, 6.8366], [12.9467, 6.8366], [17.1521, 6.8366], [21.3574, 6.8366], [25.5627, 6.8366], [29.768, 6.8366], [0.3308, 10.1529], [4.5361, 10.1529], [8.7414, 10.1529], [12.9467, 10.1529], [17.1521, 10.1529], [21.3574, 10.1529], [25.5627, 10.1529], [29.768, 10.1529], [0.3308, 13.4692], [4.5361, 13.4692], [8.7414, 13.4692], [12.9467, 13.4692], [17.1521, 13.4692], [21.3574, 13.4692], [25.5627, 13.4692], [29.768, 13.4692], [0.3308, 16.7855], [4.5361, 16.7855], [8.7414, 16.7855], [12.9467, 16.7855], [17.1521, 16.7855], [21.3574, 16.7855], [25.5627, 16.7855], [29.768, 16.7855], [0.3308, 20.1018], [4.5361, 20.1018], [8.7414, 20.1018], [12.9467, 20.1018], [17.1521, 20.1018], [21.3574, 20.1018], [25.5627, 20.1018], [29.768, 20.1018], [0.3308, 23.4181], [4.5361, 23.4181], [8.7414, 23.4181], [12.9467, 23.4181], [17.1521, 23.4181], [21.3574, 23.4181], [25.5627, 23.4181], [29.768, 23.4181]] polygon = Polygon([ (0, -10), (0., 35.), (35., 35.), (35., -10.), ]) sizes = [ 28.87, 49.88, 49.88, 49.88, 49.88, 49.88, 49.88, 87.0, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 8.07, 13.95, 13.95, 13.95, 13.95, 13.95, 13.95, 24.32, 32.22, 55.68, 55.68, 55.68, 55.68, 55.68, 55.68, 97.11 ] _execute(polygon, points, sizes)
def _triangle(x, y): return Polygon([(0, y), (x, y), (x / 2, 0)])
def test_alexdiab(): points = [(3.45, 3.66), (6.0, 4.54), (7.82, 5.35), (5.65, 3.09), (1.99, 4.66)] polygon = Polygon([(0, 0), (0, 6), (9, 0), (9, 6)]) sizes = [14.04, 5.63, 6.11, 16.66, 11.57] _execute(polygon, points, sizes)
import random from voronoi.algorithm import Algorithm from voronoi.graph import Polygon, Point x = 100 y = 100 n = 10 print_input = True polygon_points = [(0, y), (x, y), (x / 2, 0)] polygon = Polygon(polygon_points) points = [] while len(points) < n: p = Point(random.randint(0, x), random.randint(0, y)) if polygon.inside(p): points.append(p) if print_input: print("points = [") for point in points: print(f" Point({point.x}, {point.y}),") print("]") v = Algorithm(polygon) v.create_diagram(points=points, vis_steps=True, vis_result=True, verbose=False,