d3 / d3-geo-polygon

Clipping and geometric operations for spherical polygons.
https://d3.observablehq.cloud/d3-geo-polygon/
Other
113 stars 23 forks source link

epsilon3 and intersect(a, b) #3

Closed Fil closed 6 years ago

Fil commented 6 years ago

From Jason Davies's code (ported in https://github.com/d3/d3-geo-polygon/commit/82d94812e6c6387a43731f5d7ca8c8d87a12f8c9#diff-1955ba130f17ffd3f1a5db97ee798e02R13 ), there was an epsilon2 test in this function.

Somehow it allowed lines to escape the clipping on some occasions, so I lowered it to epsilon3 in https://github.com/d3/d3-geo-polygon/commit/202e60412effda1aef0b6be995f5b517849b3c50 and got much less errors.

But it still happens, and the fix is to get rid of any epsilon and compare the values with 0.

capture d ecran 2018-02-22 a 12 10 13 capture d ecran 2018-02-22 a 12 10 07

I wonder what I'm missing (in which cases this value should be st. positive), but testing in all my examples seems to be OK with 0 instead of epsilon3.

Fil commented 6 years ago

Now this creates a random error in the d3-geo-projection tests: sometimes they give the exact image, and sometimes not (in different runs).

The difference between those images and the reference is so tiny only the test sees them. (Red dots on the top-left edge). polyhedralcollignon-difference polyhedralbutterfly-difference

Fil commented 6 years ago

A way to get reproducible results and avoid the tests wobbling is to get rid of Math.random() and replace it with a deterministic function like Math.sin( 10000 * xxx). Fix coming soon