JCash / voronoi

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

An infinite loop in the function `jcv_boxshape_fillgaps`(line 1236 in jc_voronoi.h) #83

Open YoungCapta1n opened 1 year ago

YoungCapta1n commented 1 year ago

Love your library and it is very efficient. I run the jcv_diagram_generate using Double floating point precision from the following points (On ubuntu 22.04, Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz with 16Gb of RAM) 13.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 0.00000000000000022204460492503130808472633361816406 13.5000000000000000000000000000000000000000, 3.50000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 0.50000000000000022204460492503130808472633361816406 13.5000000000000000000000000000000000000000, 3.00000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 1.00000000000000000000000000000000000000000000000000 13.5000000000000000000000000000000000000000, 2.50000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 1.50000000000000022204460492503130808472633361816406 13.5000000000000000000000000000000000000000, 1.99999999999999977795539507496869191527366638183594 8.5000000000000000000000000000000000000000, 2.00000000000000000000000000000000000000000000000000 13.5000000000000000000000000000000000000000, 1.50000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 2.50000000000000000000000000000000000000000000000000 13.5000000000000000000000000000000000000000, 0.99999999999999977795539507496869191527366638183594 8.5000000000000000000000000000000000000000, 3.00000000000000000000000000000000000000000000000000 13.5000000000000000000000000000000000000000, 0.49999999999999977795539507496869191527366638183594 8.5000000000000000000000000000000000000000, 3.50000000000000000000000000000000000000000000000000 13.5000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 8.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 13.0000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 9.0000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 12.5000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 9.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 12.0000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 10.0000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 11.5000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 10.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 11.0000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 11.0000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 10.5000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 11.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 10.0000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 12.0000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 9.5000000000000000000000000000000000000000, 0.00000000000000000000000000000000000000000000000000 12.5000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 9.0000000000000000000000000000000000000000, 0.00000000000000022204460492503130808472633361816406 13.0000000000000000000000000000000000000000, 4.00000000000000000000000000000000000000000000000000 However, An infinite loop occurs in the function jcv_boxshape_fillgaps(line 1236 in jc_voronoi.h), resulting in an error in 2d voronoi generation. Thanks!

Wambomango commented 1 year ago

I have also stumbled upon this issue with the following points: 1.5484909, -0.21024238 1.5413352, -0.21024236 1.5378445, -0.21024236 1.5343539, -0.21024235 1.5308806, -0.19333011 and a rectangular clip from (-4,-4) to (4,4) Upping the precision from float to double does not resolve the problem.

Initial investigation leads me to believe there is something wrong in the generation of the breachline in this case.

14RS commented 1 year ago

First of all, I wanted to thank you for this great initiative and excellent work.

I have a similar (if not the same) issue, where the program infinitely loops within jcv_fillgaps(). Subsequently, more and more memory is allocated within each loop iteration, ultimately killing the program or freezing the OS.

I've attached a .csv file with points (x,y) and I used {{0,0},{7339,4984}} as a rectangular bounding box (x,y). I used the default settings (i.e. float).

points(16521).csv

14RS commented 1 year ago

I also want to add that this issue does not occur for me in version 0.7, but is present now in jc_voronoi.h version 0.9.

JCash commented 1 year ago

Thanks for the info!

Yes, I seem to have broken something in 0.9 (I need better tests apparently). Hopefully, I can schedule some time this weekend to fix it.

14RS commented 1 year ago

I was wondering if there is any further development on the look-out. If so, I'd be more than willing to help out and do some testing.

finnwrt commented 1 year ago

If I can do anything to help too I will. In my program I generate the diagram from a set of random points and this issue seems to appear about 5-10% of time

ericheee111 commented 3 months ago

I got the same issue, anyone knows how to fix it? Thanks!