Skip to content

Commit

Permalink
Fixed bounding circle debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatoom committed Mar 20, 2021
1 parent d3c9ed8 commit 2428d0d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
37 changes: 21 additions & 16 deletions voronoi/graph/bounding_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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("""
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions voronoi/graph/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2428d0d

Please sign in to comment.