JCash / voronoi

A C implementation for creating 2D voronoi diagrams
MIT License
632 stars 94 forks source link

Assertion on polygon bounds #54

Closed Balgy closed 3 years ago

Balgy commented 3 years ago

Hey, congrats on the great library.

I am trying to generate a voronoi diagram inside one of the cells of another voronoi diagram. I am converting the bounding polygon to a jcv_polygon and then making a clipper and setting it as a ctx.

The generation asserts at line 218 of jc_voronoi_clip.h at this assertion assert(min_edge >= 0);

Can you please help me understand what is happening? Thanks

JCash commented 3 years ago

HI @Balgy !

I'm not entirely sure, but apart from the obvious check to see that the polygon->num_points isn't 0, I'm thinking that my code here is a bit flawed.

Iirc, I want the code to find the closest polygon edge for that particular point.

However, it's entirely possible for a point from to be outside of all the edge segments of the clip region, which is an oversight on my part.

I might have some time this weekend to take a look at it, unless someone else wants to give it a go ;)

Balgy commented 3 years ago

Hey, thanks for the quick response. num_points is definitely not 0 however, your explanation seems to make a lot of sense so I will go on to try and fix this case. Will do a pull request if I succeed.

Balgy commented 3 years ago

Hey just a quick update, my crash was related to jcv_real min_dist = (jcv_real)1000000; not being enough for my coordinates square distance so I fixed that but I have another issue now. The clipper doesn't seem to include perimeter polygon points in cells whenever it should be doing that so I get results that look like this (white lines are the polygon voronoi, purple lines are the bounding polygon, blue dots are the voronoi centes, green lines are irrelevant): Capture

Could this bug be related to another case of the float type not being enough?