Skip to content

Commit

Permalink
More documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatoom committed Apr 7, 2021
1 parent 2a08cbf commit beac19c
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 24 deletions.
6 changes: 6 additions & 0 deletions docs/private/breakpoint.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _breakpoint:

Breakpoint
==========
.. autoclass:: foronoi.nodes.Breakpoint
:members:
6 changes: 6 additions & 0 deletions docs/private/circle_event.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _circleevent:

CircleEvent
===========
.. autoclass:: foronoi.events.circle_event.CircleEvent
:members:
6 changes: 6 additions & 0 deletions docs/private/site_event.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. siteevent:
SiteEvent
===========
.. autoclass:: foronoi.events.site_event.SiteEvent
:members:
7 changes: 7 additions & 0 deletions docs/public/boundingbox.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _boundingbox:

BoundingBox
===========
.. autoclass:: foronoi.graph.bounding_box.BoundingBox
:members:

80 changes: 70 additions & 10 deletions foronoi/events/circle_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ class CircleEvent(Event):

def __init__(self, center: Coordinate, radius: Decimal, arc_node: LeafNode, point_triple=None, arc_triple=None):
"""
Circle event.
:param arc_node: Pointer to the node in the beach line tree that holds the arc that will disappear
:param point_triple: The tuple of points that caused the event
A circle event.
Parameters
----------
center: Coordinate
The center coordinate of the circle (where the new vertex will appear)
radius: Decimal
The radius of the circle
arc_node: LeafNode
Pointer to the node in the beach line tree that holds the arc that will disappear
point_triple: (Point, Point, Point)
The triple of points that caused the event
arc_triple: (Arc, Arc, Arc)
The triple of arcs related to the points
"""
self.center = center
self.radius = radius
Expand All @@ -29,32 +39,64 @@ def __repr__(self):

@property
def xd(self):
"""
The x-coordinate (in Decimal format) of the center of the circle, which functions as the secondary priority of this event.
Returns
-------
x: Decimal
"""
return self.center.xd

@property
def yd(self):
"""
The y-coordinate (in Decimal format) of the bottom of the circle, which functions as the primary priority of this event.
Returns
-------
y: Decimal
"""
return self.center.yd - self.radius

def get_triangle(self):
def _get_triangle(self):
return (
(self.point_triple[0].xd, self.point_triple[0].yd),
(self.point_triple[1].xd, self.point_triple[1].yd),
(self.point_triple[2].xd, self.point_triple[2].yd),
)

def remove(self):
"""
Mark this circle event as a false alarm.
Returns
-------
self: CircleEvent
"""
self.is_valid = False
return self

@staticmethod
def create_circle_event(left_node: LeafNode, middle_node: LeafNode, right_node: LeafNode, sweep_line) -> "CircleEvent":
"""
Checks if the breakpoints converge, and inserts circle event if required.
:param sweep_line: Y-coordinate of the sweep line
:param left_node: The node that represents the arc on the left
:param middle_node: The node that represents the arc on the middle
:param right_node: The node that represents the arc on the right
:return: The circle event or None if no circle event needs to be inserted
Parameters
----------
left_node: LeafNode
The node that represents the arc on the left
middle_node: LeafNode
The node that represents the arc in the middle
right_node: LeafNode
The node that represents the arc on the right
sweep_line: Decimal
The y-coordinate of the sweep line
Returns
-------
circleEvent: CircleEvent or None
The circle event or None if no circle event needs to be inserted
"""

# Check if any of the nodes is None
Expand Down Expand Up @@ -82,6 +124,24 @@ def create_circle_event(left_node: LeafNode, middle_node: LeafNode, right_node:

@staticmethod
def create_circle(a, b, c):
"""
Create a circle from three coordinates.
Parameters
----------
a: Coordinate
b: Coordinate
c: Coordinate
Returns
-------
x: Decimal
The x-coordinate of the center of the circle
y: Decimal
The y-coordinate of the center of the circle
radius: Decimal
The radius of the circle
"""

# Algorithm from O'Rourke 2ed p. 189
A = b.xd - a.xd
Expand Down
22 changes: 20 additions & 2 deletions foronoi/events/site_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@ class SiteEvent(Event, Subject):

def __init__(self, point: Point):
"""
Site event
:param point:
A site event.
Parameters
----------
point: Point
The point that causes the site event.
"""
super().__init__()
self.point = point

@property
def xd(self):
"""
The x-coordinate (in Decimal format) of the point, which functions as the secondary priority of this event.
Returns
-------
x: Decimal
"""
return self.point.xd

@property
def yd(self):
"""
The y-coordinate (in Decimal format) of the point, which functions as the primary priority of this event.
Returns
-------
y: Decimal
"""
return self.point.yd

def __repr__(self):
Expand Down
14 changes: 14 additions & 0 deletions foronoi/graph/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
class BoundingBox(Polygon):

def __init__(self, left_x, right_x, bottom_y, top_y):
"""
Convenience method to create a bounding box. Extends :class:`foronoi.graph.Polygon`.
Parameters
----------
left_x: float
The x-coordinate of the left border
right_x: float
The x-coordinate of the right border
bottom_y: float
The y-coordinate of the bottom border
top_y: float
The y-coordinate of the top border
"""
points = [
(left_x, top_y),
(right_x, top_y),
Expand Down
43 changes: 32 additions & 11 deletions foronoi/nodes/breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ class Breakpoint:

def __init__(self, breakpoint: tuple, edge=None):
"""
The breakpoint is stored by an ordered tuple of sites (p_i, p_j) where p_i defines the parabola left of the
breakpoint and p_j defines the parabola to the right. Furthermore, the internal node v has a pointer to the half
edge in the doubly connected edge list of the Voronoi diagram. More precisely, v has a pointer to one of the
half-edges of the edge being traced out by the breakpoint represented by v.
:param breakpoint: A tuple of two points that caused two arcs to intersect
The breakpoint is stored by an ordered tuple of sites (:obj:`p_i`, :obj:`p_j`) where :obj:`p_i` defines the
parabola left of the breakpoint and :obj:`p_j` defines the parabola to the right. Furthermore, the internal node
:obj:`v` has a pointer to the half edge in the doubly connected edge list of the Voronoi diagram. More
precisely, :obj:`v` has a pointer to one of the half-edges of the edge being traced out by the breakpoint
represented by :obj:`v`.
Parameters
----------
breakpoint: (Point, Point)
A point where two arcs intersect, represented as a tuple of the two site points that the arcs refer to
"""

# The tuple of the points whose arcs intersect
Expand All @@ -28,10 +33,18 @@ def __init__(self, breakpoint: tuple, edge=None):
def __repr__(self):
return f"Breakpoint({self.breakpoint[0].name}, {self.breakpoint[1].name})"

def tuple_name(self):
return self.breakpoint[0].name + self.breakpoint[1].name

def does_intersect(self):
"""
A guard that handles the edge-case where two arcs were initialized at the same time due to their sites
having the same :obj:`y`-coordinate. This guard makes sure that the left arc intersects once with the right arc
and not the other way around.
Returns
-------
intersects: bool
Returns false when :obj:`p_i` and :obj:`p_j` have the same y-coordinate and :obj:`p_j` is
situated left of `p_i`.
"""
i, j = self.breakpoint
return not (i.yd == j.yd and j.xd < i.xd)

Expand All @@ -40,9 +53,17 @@ def get_intersection(self, l, max_y=None):
Calculate the coordinates of the intersection
Modified from https://www.cs.hmc.edu/~mbrubeck/voronoi.html
:param max_y: Bounding box top for clipping infinite breakpoints
:param l: (float) The position (y-coordinate) of the sweep line
:return: (float) The coordinates of the breakpoint
Parameters
----------
l: float
The y-coordinate of the sweep line
max_y: float
The top of the bounding box/polygon for clipping infinite breakpoints
Returns
--------
coordinate: Coordinate
The current coordinates of the breakpoint
"""

# Get the points
Expand Down
2 changes: 1 addition & 1 deletion foronoi/visualization/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def _plot_circle(self, evt, show_triangle=False):
self.canvas.add_artist(circle)

if show_triangle:
triangle = plt.Polygon(evt.get_triangle(), fill=False, color=Colors.TRIANGLE, linewidth=1)
triangle = plt.Polygon(evt._get_triangle(), fill=False, color=Colors.TRIANGLE, linewidth=1)
self.canvas.add_artist(triangle)

points = evt.point_triple
Expand Down

0 comments on commit beac19c

Please sign in to comment.