question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong result for two simple polygons

See original GitHub issue

These are my two simple polygons:

Two simple polygons

with coordinates:

[[115,96], [140,206], [120,210], [125,250], [80,300]]
[[111,228], [129,192], [309,282]]

And this is the resulting union:

Wrong resulting union

There are no vertical edges, in fact, no two points share the same x-coordinate. I believe the issue here is with the otherInOut property not being correctly computed as these are the sweep events with otherInOut set to true after the subdivision step:

Sweep events with otherInOut set to true

I also tried with the C++ code available online from the original paper, and the resulting union is the same.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
w8rcommented, Jan 7, 2020

I would love to get some help here, I didn’t have time to look at it recently

1reaction
abelramoscommented, Jan 6, 2020

@abelramos Until this gets fixed, I have found that adding very small (like 0.0005), pseudorandom values to the coordinates will prevent this. The problem occurs when a point falls exactly on another line. Our app has grid snapping, I can confirm that this happens all the time.

Exactly. I can also confirm it is not related to floating-point arithmetic and/or epsilon values, I tested the implementation with a type for rational numbers, and the issue remains.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging touching polygons giving wrong result - Stack Overflow
Now this is obviously wrong as these two polygons do not touch each other. The same result occurs with both methods. The result...
Read more >
Intersection gives wrong result · Issue #1216 · shapely/shapely
I ran into a case where an intersection between two (valid) (multi)polygons results in a wrong result. One example results in an "invalid" ......
Read more >
Detecting two kinds of almost-simple polygons
We can determine whether a given polygon is simple in O(n2) time by checking every pair of edges for intersection, or in O(nlogn)...
Read more >
Triangulations and arrangements - ICS, UCI
The resulting polytope, with eight triangular faces, cannot be triangulated. ... THE TWO-EARS THEOREM (Meister, 1975): Every simple polygon with at least ...
Read more >
Detecting Weakly Simple Polygons∗ - Hsien-Chih Chang
Top row: Two weakly simple polygons from Meis- ... is incorrect for polygons with spurs; many of these definitions are incorrect even for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found