velipso / polybooljs

Boolean operations on polygons (union, intersection, difference, xor)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Union completely ignoring some polygons

ahsan-sabir opened this issue · comments

I have about a dozen of polygons that I am taking union of (tried both union method and the core api), but the two of them are completely ignored.

I have been stuck on this whole for a whole day, and spent another hour in compiling this example with reproducible error for easy debugging

https://codesandbox.io/s/polybooljs-forked-6vto7

In this example poly1 and poly2 (green and magenta) are not present in the union

commented

In poly1, you have the point:

[5530.606601717798, 4154.393398282202],

In poly2, you have the point:

[5530.606601717799, 4154.393398282202],

When results are wrong, it's likely because of an issue with the epsilon. Notice that the X coordinate differs by a very very very small amount. This causes issues with trying to detect if points are on top of each other.

Check out issue #3 for a discussion behind this, and some ideas to fix it.

Shouldn't polybooljs treat these two points the same, since the difference is under the default epsilon value (0.0000000001)?

Math.abs(5530.606601717799 - 5530.606601717798) < 0.0000000001 // true

Decreasing the epsilon precision by one decimal place does fix the issue between.

commented

Shouldn't polybooljs treat these two points the same, since the difference is under the default epsilon value (0.0000000001)?

That makes sense, but it's more complicated than that. Check out the calculations in lib/epsilon.js to see exactly what polybooljs does. If you can come up with better replacements, let me know. The PR #8 also includes a new implementation of epsilon.js that you can try if you want.