diff --git a/voronoi/graph/bounding_circle.py b/voronoi/graph/bounding_circle.py index 83cd756..f1f68d4 100644 --- a/voronoi/graph/bounding_circle.py +++ b/voronoi/graph/bounding_circle.py @@ -2,10 +2,13 @@ from decimal import Decimal from voronoi import Polygon +from voronoi.algorithm import Algorithm from voronoi.graph import Point, DecimalCoordinate, Vertex -from voronoi.visualization import Visualizer -DEBUG = False +DEBUG = True + +if DEBUG: + from voronoi.visualization import Visualizer class BoundingCircle(Polygon): @@ -20,6 +23,8 @@ def __init__(self, x, y, radius): self.min_x = self.x - 2 * self.radius self.max_y = self.y + 2 * self.radius self.min_y = self.y - 2 * self.radius + self.voronoi = Algorithm(self) # A dummy for visualization + self.voronoi.sweep_line = self.min_y - abs(self.max_y) # Important warning about visualization warnings.warn(""" @@ -42,12 +47,13 @@ def finish_edges(self, edges, vertices=None, points=None, event_queue=None): B = edge.twin.get_origin(y=-1000) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites(points) \ .plot_vertices(vertices + self.polygon_vertices) \ .plot_edges(edges) \ .plot_edges([edge], color="green") \ - .plot() + .plot_polygon()\ + .show() if A is None: if B is None: @@ -59,11 +65,12 @@ def finish_edges(self, edges, vertices=None, points=None, event_queue=None): resulting_edges.append(edge) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites(points) \ .plot_vertices(vertices + self.polygon_vertices) \ .plot_edges(edges) \ .plot_edges([edge], color="green") \ + .plot_polygon() \ .show() if B is None or not self.inside(B): @@ -72,21 +79,23 @@ def finish_edges(self, edges, vertices=None, points=None, event_queue=None): resulting_edges.append(edge.twin) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites(points) \ .plot_vertices(vertices + self.polygon_vertices) \ .plot_edges(edges) \ .plot_edges([edge], color="green") \ + .plot_polygon() \ .show() # Re-order polygon vertices self.polygon_vertices = self.get_ordered_vertices(self.polygon_vertices) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites(points) \ .plot_vertices(vertices + self.polygon_vertices) \ .plot_edges(edges) \ + .plot_polygon() \ .show() return resulting_edges, self.polygon_vertices @@ -133,8 +142,9 @@ def get_ray(self, edge): a, b, c = self.get_line(ray_start, center) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites([A, B, center, ray_start, a, b, c]) \ + .plot_polygon() \ .show() return ray_start, center, a, b, c @@ -159,8 +169,9 @@ def cut_line(self, edge): point1, point2 = self.cut_circle(a, b, c) if DEBUG: - Visualizer(None, 1) \ + Visualizer(self.voronoi, 1) \ .plot_sites([point1, point2]) \ + .plot_polygon() \ .show() if point1 is None: return None @@ -196,10 +207,4 @@ def cut_circle(self, a, b, c): y2 = self.y + (b * d + a * big_sqrt) / a_sq_b_sq point2 = Point(x=x2, y=y2) - return point1, point2 - - # def finish_shape(self, edges, vertices, points): - # return Shape.finish_shape( - # edges=edges, existing_vertices=vertices, points=points, - # polygon_vertices=self.polygon_vertices, center=self.center - # ) + return point1, point2 \ No newline at end of file diff --git a/voronoi/graph/polygon.py b/voronoi/graph/polygon.py index ab5fed5..2bea01a 100644 --- a/voronoi/graph/polygon.py +++ b/voronoi/graph/polygon.py @@ -109,12 +109,14 @@ def finish_edges(self, edges, **kwargs): return resulting_edges, self.polygon_vertices def finish_edge(self, edge): + # Sweep line position + sweep_line = self.min_y - abs(self.max_y) + # Start should be a breakpoint - start = edge.get_origin(y=2 * (self.min_y - self.max_y), max_y=self.max_y) - # TODO: check if this is correct + start = edge.get_origin(y=sweep_line, max_y=self.max_y) # End should be a vertex - end = edge.twin.get_origin(y=self.min_y - self.max_y, max_y=self.max_y) + end = edge.twin.get_origin(y=sweep_line, max_y=self.max_y) # Get point of intersection point = self.get_intersection_point(end, start)