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

Check for closed polygons is incorrect #3

Open
captbaritone opened this issue Oct 4, 2022 · 1 comment
Open

Check for closed polygons is incorrect #3

captbaritone opened this issue Oct 4, 2022 · 1 comment

Comments

@captbaritone
Copy link

https://github.com/math-utils/area-polygon/blob/master/index.js#L7

Here we try check to see if the polygon ends where it begins, but because JavaScript compares object/arrays by reference, this comparison will return false even if the points of the head and tail of the polygon do match.

This does not pose a correctness issue, because adding the additional end point redundantly does not change the area of the polygon, but it is a bit wasteful/confusing.

@MikkoSteerpath
Copy link

This actually masks another bug, where if this would not always be false, then the point would not get added, and l variable would not be 1 shorter than the actual length of the array, and the code would access an index outside the array.

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