-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'NoneType' object has no attribute 'edge' #5
Comments
Hi, With that package, using a list of points like this: So I searched for an alternative and found this package Yatoom/voronoi, with which I tried the same series of points. Only that in this case I only had to make a couple of changes to make it work. BTW, I've tried with 64 points in a grid and it worked after making the simple changes I've mentioned. I think that this is an ugly hack but it may point the developer in the right direction. The changes I made were: Update breakpoints
If the method reach it's end I return True. and in voronoi.algorithm.handle_circle_event() method: if res is None: PS: Sorry for the formatting, I'm not used to ... Best regards, LE: Well, while the Matplotlib plot that the create_diagram() method display looks correct for 64 points, in reality with the modification above, after plotting the actual resulting Voronoi polygons in another plot, some of the polygons are fused together. |
Thanks @mars0001, there seems to be an issue with this case indeed. I will investigate this further. I'm putting this here so that we have a reproducible script.
|
This issue was caused by rounding errors, which in turn caused the circle events to be executed in the wrong order. Thanks for your help. If you find anything else that doesn't work, please let me know! 😄 |
Hi Jeroen, ( @Yatoom ) Thank you for your effort! Best regards, |
Thanks Marius/@mars0001! In that case let me reopen this issue. Those grids are indeed a bit tricky as they require special/careful handling when multiple events happen on the same line (see #2 (comment) for more information on this) Using your points, I'll try to solve this one next. |
Hi @mars0001, it turned out to be rounding errors again. I think it should be fixed now 👍 |
Hi Jeroen, ( @Yatoom ), Now it works for a 4 by 4 grid but not for a higher order grid (5x4, 5x5 and higher). Points list for which it does not work: 5x4: 5x5: 6x6: 6x7: 7x7: 8x8: And so on... I hope those can help in pinpointing the bugs. Thanks, |
Hi @mars0001, thanks for these grids! Those really help. There was another place where rounding errors where causing trouble. This time it was when querying the binary tree to find the breakpoints that needed to be updated. I used a workaround for this: instead of returning Let me know if it works for you 😄 |
Hi Jeroen (@Yatoom ), It seems that the latest fix solved the issue with point on grid. Here is a picture with 20x20 points (400 points in a gid). But I did found that by adding manual points (is done by clicking with the mouse) and perhaps adding overlapped points (points with same or very close coordinates) I get this result. The black points are actually the clicked points that are used in the algorithm. Each seed point should have its own polygon but that is not the case ... I get the Shapely polygons using something like this: def generate_voronoi_geometry(self, pts):
env = self.solid_geo.envelope # an outline of a complex geometry
fact = 1 if self.units == 'MM' else 0.039
env = env.buffer(fact) # create a polygon from the outline
# voronoi_poly is the Polygon from Voronoi package so it does not get confused with the Shapely Polygon
env_poly = voronoi_poly(list(env.exterior.coords)
new_pts = [[pt.x, pt.y] for pt in pts]
# Initialize the algorithm
v = Voronoi(env_poly)
# calculate the Voronoi diagram
try:
v.create_diagram(new_pts)
except Exception as e:
print("CNCJobObject.generate_voronoi_geometry_2() --> %s" % str(e))
# try again with slightly changed coordinates (random) perhaps will make it work
new_pts_2 = []
for pt_index in range(len(new_pts)):
new_pts_2.append([
new_pts[pt_index][0] + random.random() * 1e-06,
new_pts[pt_index][1] + random.random() * 1e-06
])
try:
v.create_diagram(new_pts_2)
except Exception:
print("Didn't work.")
return
new_voronoi = []
for p in v.points:
p_coords = [(coord.x, coord.y) for coord in p.get_coordinates()]
new_pol = Polygon(p_coords)
new_voronoi.append(new_pol)
new_voronoi = MultiPolygon(new_voronoi)
return new_voronoi Should I open a new issue for this? LE: in my case I can get away with storing manual points in a set (therefore eliminating duplicates) or test if it is already added, but maybe fixing it may make your package more foolproof. |
Hi @mars0001, could you confirm whether this issue only pops up if there are duplicates? |
Hi Jeroen @Yatoom , I did made sure that the duplicated points are not added at all and that fixed the issue. Best regards, |
When point number is too large (around 30) Algorithm stops workin, and i can see this error
After limiting the number of points graph is computed properly
The text was updated successfully, but these errors were encountered: