Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flattenedPointsAreClockwise - unexpected results for self-intersecting polygons #113

Open
luckyclan opened this issue Feb 28, 2024 · 2 comments

Comments

@luckyclan
Copy link

luckyclan commented Feb 28, 2024

I found that flattenedPointsAreClockwise may return wrong value for self-intersecting polygons.
For example it returns true for:
(0,0) (9,0) (0,10) (10,10)
But returns false for:
0,0) (11,0) (0,10) (10,10)

To be more specific - the returned values says whether the polygon is "mostly clockwise" or not. It is not information that all neighbouring edges are clockwise. And for self-intersecting points orientation is undefined.

Suggestion: add
assert(pointsAreSelfIntersecting(points) == false)

More informations:
https://en.wikipedia.org/wiki/Curve_orientation

@luckyclan luckyclan changed the title flattenedPointsAreClockwise - sometimes wrong result for rotated rectangle flattenedPointsAreClockwise - unexpected results for self-intersecting polygons Feb 28, 2024
@nicklockwood
Copy link
Owner

@luckyclan thanks for reporting this. I'm curious how you bumped into it though since the method is internal. Is there a way to reproduce this issue using public APIs?

@luckyclan
Copy link
Author

luckyclan commented Feb 29, 2024

I'm author of Artstudio Pro app I just use similar function in my own (closed source) graphic library in Swift, and i encounter the same issue. So i started checking how is it implemented in other libraries, and it turned out that nobody cares of this case.
"isClockwise" is very imporatant function for asserts, it helps to find a lot of bugs.

I think Euclid is great and i often use it to learn how this and that works, how to write good code etc. I just wanted to help to improve it a bit ;)

I can write that In my library i just added:
assert(isPolygonSelfIntersecting() == false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants