Open nedbat opened 7 years ago
I don't have time to investigate this just now, but quickly checked whats going on.
-281.28544884362674
and -281.2854488436267
(the second value has one less digit, it should work of course)EPS = 1e-13
(or smaller) in poly_point_isect.py
is a temporary workaround.In general I'd like to look in ways to get better precision from the sweep-line, however cases I ran into were corner cases and this looks to be trivial, so it should work without so much trouble.
Committed test fix in temp branch, EPS_SCALE
may need tweaking though. It passes all tests as well as a new test added from your data. 1a6254af8c31a6b3ebd0cd53f54bed09a93aac23 - otherwise this feels like a weak solution, hence committing to temp branch for further investigation.
As a workaround (if you just want to use the library as-is) it may be best to normalize coords to -1..1 range since this is well tested.
@ideasman42 again, thanks for the quick turnaround, and the fix/workaround. BTW, new in Python 3 is the math.isclose() function which deals with relative epsilon values. That might be helpful.
I hadn't noticed that the two points weren't identical. I can also fix that on my end (https://nedbatchelder.com/blog/201707/finding_fuzzy_floats.html).
On my current data, sometimes this fix works better, and sometimes master works better. ("better" meaning, doesn't fail an assertion.)
Have you considered Hypothesis as a tool for testing? I can take a stab at writing a test with it.
Regarding Hypothesis, I'd like to keep the version in master using vanilla Python (or other 3rd party Python modules optional at least). If theres some significant advantage maybe having tests using an extra module is ok - as long as the module its self remains standalone.
I totally agree about not introducing third-party modules that would be required to use the code. This would only be for testing the code. If I get a test written, I'll share it, and you can decide whether it is worth the dependency.
Note that I've committed support for swapping out different number implementations (decimal, numpy, gmpy) - may be useful when investigating precision issues. see: 0457b4fd6d327ea15f1d77eabd60b84e88f0bbdb
produces:
I'm not sure what is special about these four segments. They are the smallest set that produces the crash from a much larger set that I started with.