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

Suspicious handling of a number (result of area) as a boolean #141

Open
OndrejSpanel opened this issue Aug 27, 2020 · 0 comments
Open

Suspicious handling of a number (result of area) as a boolean #141

OndrejSpanel opened this issue Aug 27, 2020 · 0 comments
Labels

Comments

@OndrejSpanel
Copy link

Is handling the number result of the area call as a boolean value intended in the snippet below?

earcut/src/earcut.js

Lines 476 to 481 in 36742a5

function isValidDiagonal(a, b) {
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges
(locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible
(area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors
equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case
}

As I understand the code now, it checks that at least one of the triangles a.prev, a, b.prev and a, b.prev, b has non zero area. I do not understand the intent well enough, the comment says "does not create opposite-facing sectors".

If the code is correct, perhaps an explicit comparion using !== 0 would make the intent clearer?

(Originally reported as mrdoob/three.js#20200)

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

No branches or pull requests

2 participants