Yatoom / foronoi

An implementation of Fortune's algorithm for Voronoi diagrams in Python.
MIT License
51 stars 11 forks source link

get_coordinates() returns None #4

Closed alexdiab closed 3 years ago

alexdiab commented 4 years ago

Hi, I have an issue when trying to use get_coordinate() as it returns None for some of the set of points that I use. To reproduce the problem, here is the code that I use

points = [(3.45, 3.66), (6.0, 4.54), (7.82, 5.35), (5.65, 3.09), (1.99, 4.66)]
The_grid = Polygon([
    (0, 0),
    (0, 6),
    (9, 0),
    (9, 6)
])
v = Voronoi(The_grid)
v.create_diagram(points=points, vis_steps=False, verbose=False, vis_result=True, vis_tree=True)
points = v.points
points[2].get_coordinates()

I don't understand why the first_edge attribute present a Nonetype object in next.

I am trying to get all the vertices for each polygon formed by the Voronoi tesselation Thank you for your help.

Yatoom commented 3 years ago

Thank you very much for reporting this @alexdiab! Using your case, I was able to determine the problem. I added your case as a unit test to prevent future mistakes.

What went wrong? During clipping, some of the edges fall outside of the bounding box. These need to be deleted, and the pointers need to be updated. It turns out that during this update process, some of the center points ended up pointing to the edges of other center points.