polygon-clipping icon indicating copy to clipboard operation
polygon-clipping copied to clipboard

Another union ring problem :) - Unable to complete output ring starting at ....

Open pentacular opened this issue 6 years ago • 4 comments

union(...[[[[-13.659807482533342,15.000000000000004],[-4.619397662556434,-1.9134171618254447],[-9.750026667063697,15.000000000000004],[-13.659807482533342,15.000000000000004]]],[[[-9.750026667063697,15.000000000000004],[-4.903926402016152,-0.9754516100806383],[-6.477371050357451,15.000000000000004],[-9.750026667063697,15.000000000000004]]]]);

Unable to complete output ring starting at [-13.659807482533342, 15.000000000000004]. Last matching segment found ends at [-9.750026667063697, 15.000000000000004].

pentacular avatar Aug 07 '19 11:08 pentacular

Seems to also occur in current master.

pentacular avatar Aug 07 '19 11:08 pentacular

Thanks for the failing coordinates @pentacular, I've reproduced the failure on my side

mfogel avatar Aug 07 '19 22:08 mfogel

Ok, I think that I understand the problem a little better now.

If we reduce the mantissa of the floats involved, by trimming the number of significant digits, the problem disappears.

e.g.

polygonClipping.union(...[[[[-13.65980,15.00000],[-4.61939,-1.91341],[-9.75002,15.00000],[-13.65980,15.00000]]],[[[-9.75002,15.00000],[-4.90392,-0.97545],[-6.47737,15.00000],[-9.75002,15.00000]]]]);

works fine.

Which leads me to think that this is due to numeric instability.

pentacular avatar Aug 14 '19 09:08 pentacular

Re: numeric instability - most of the bugs in this repo turn out to be related somehow to the joys of floating point math.

I've verified this bug is still happening with the latest on master.

mfogel avatar Aug 15 '19 23:08 mfogel