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.

Unify fails when polygons are wound in opposite directions

See original GitHub issue

If two polygons are constructed, the first in a CCW direction and the second in a CW direction, the resulting union is not correct:

const polygon1 = new Polygon();
polygon1.addFace([point(0, 0), point(10, 0), point(10, 10), point(0, 10)]);

const polygon2 = new Polygon();
polygon2.addFace([point(8, 2), point(8, 8), point(20, 8), point(20, 2)]);

const result = unify(polygon1, polygon2);
// result is not the expected shape

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexbol99commented, May 18, 2021

Hi, David, Flatten-js support multi-polygons, comprised from a number of faces, some of them may be external, some internal. Internal faces represent holes - cut-off areas inside a polygon, and their orientation should be opposite to the outer polygon they belong. unify (and other boolean operations) assume that both polygons have same meaning of orientation, for example, in both polygons outer faces oriented counterclockwise, and inner faces oriented clockwise. Best regards, Alex

0reactions
alexbol99commented, May 20, 2021

I have a method polygon.splitToIslands() which returns an array of polygons, where each polygon is ordered by inclusion of faces: the first face is an outer (we call it “island”) and the others are internal (we call them "holes). You can use it before and after unify , because unify indeed does not keep an order of faces. I can also add a method that rearrange faces in polygon in the way that island always precede holes, if it may help Best, Alex

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extend 2d polygon by vector - Stack Overflow
It is part of my Polygon class, which has a std::vector of counterclockwise-wound vertices. units::Coordinate are floats, ...
Read more >
Chapter 11 - OpenGL Programming Guide
This chapter has the following major sections. "Polygon Tessellation" explains how to tessellate convex polygons into easier-to-render convex polygons. " ...
Read more >
Boston Scientific Corp. v. Cook Inc., 187 F. Supp. 3d 249 (2016 ...
“wound helically,” “wound in opposite directions,” and “a strand wound helically in a direction [different from the first direction]” ...292.
Read more >
Why should polygons in 3D models have no more than 4 sides?
Nothing is done to the intersections to blend the shapes and merge the vertices. The image on the right shows that the branch...
Read more >
Fill paths for one slice of the part shown in Fig. 1(a); | Download ...
Internal contours are buffered in the opposite direction to the commanded buffering direction. ... This reduces the number of polygons to merge by...
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