Skip to content

Commit

Permalink
Should fix #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatoom committed Mar 4, 2021
1 parent ce9eef5 commit 8b70125
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion voronoi/events/circle_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ def create_circle_event(left_node: LeafNode, middle_node: LeafNode, right_node:
@staticmethod
def create_circle(a, b, c):

a, b, c = sorted((a, b, c), key=lambda item: item.x)
# Due to small rounding errors, two circles that should have the same coordinates (e.g. in case of a 2x2 grid),
# can get slightly different coordinates from each other. This line will make sure this problem is avoided,
# by sorting the points, such that the calculations will be executed in the same order, and thus the rounding
# errors will be the same for both circles. This in turn, ensures that the priority of the two circle events
# is the same, so that first inserted circle event will be handled first.
a, b, c = sorted((a, b, c), key=lambda item: (item.y, item.x))

# Algorithm from O'Rourke 2ed p. 189
A = Decimal(b.x - a.x)
Expand Down
13 changes: 13 additions & 0 deletions voronoi/tests/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,16 @@ def test_alexdiab():
])
sizes = [14.04, 5.63, 6.11, 16.66, 11.57]
_execute(polygon, points, sizes)

# Test case added thanks to mars0001 (https://github.com/Yatoom/voronoi/issues/5)
def test_mars0001():
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)

0 comments on commit 8b70125

Please sign in to comment.