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

cleanCoords() omits valid coords. #1255

Closed
erikh2000 opened this issue Feb 8, 2018 · 2 comments
Closed

cleanCoords() omits valid coords. #1255

erikh2000 opened this issue Feb 8, 2018 · 2 comments
Assignees
Labels

Comments

@erikh2000
Copy link

erikh2000 commented Feb 8, 2018

If you agree with me this is a bug, I can add a PR for a test case and maybe a fix.

const coords = {type:'Polygon', coordinates:[[[0,0],[2,2],[3,30],[3,30],[3,30],[4,4],[0,0]]]};
const expected = {type:'Polygon', [[[0,0],[2,2],[3,30],[4,4],[0,0]]]};
expect(cleanCoords(coords)).toEqual(expected); // Fails

The actual returned value is: {type:'Polygon', [[[0,0],[1,10],[2,2],[4,4],[0,0]]]}

In other words, it omits the [3,30] point. The reason it does this is that there is a duplicate coordinate of 3,30. When isPointOnLineSegment() evaluates either of the two cases of 3,30, it correctly returns true. But if I understand the contract of cleanCoords(), it should preserve one of the 3,30 coords.

And I think that would be a useful and expected contract to keep. Because then you can do things like @DenisCarriere 's earlier fix for intersect() which truncated the coord precision and then ran cleanCoords() to yank redundant points.

@rowanwins
Copy link
Member

Indeed looks like a bug @erikh2000 - thanks for reporting

@rowanwins rowanwins added the bug label Feb 8, 2018
@rowanwins rowanwins self-assigned this Feb 14, 2018
DenisCarriere added a commit that referenced this issue Feb 14, 2018
Fix for triplicate coords. resolves #1255
@SimonsUnikaNamn
Copy link

I am still getting this error, https://jsfiddle.net/eag6dvzk/1/

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

3 participants