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

Strange behavior when polygon is closed #8

Open
AlgoTrader opened this issue Jan 19, 2017 · 5 comments
Open

Strange behavior when polygon is closed #8

AlgoTrader opened this issue Jan 19, 2017 · 5 comments

Comments

@AlgoTrader
Copy link

When polygon is not closed, everything is OK
When polygon is closed (firstPoint==lastPoint), the intersection is weird. Weird means

image

@AlgoTrader
Copy link
Author

When remove (just drop) the last closing point, the result is:

image

@NTag
Copy link

NTag commented Mar 16, 2017

I exactly face the same issue. The following code (should) computes the intersection between two basic squares.

console.log(greinerHormann.intersection(
  [
    [0, 0], [0, 1], [1, 1], [1, 0], [0, 0]
  ],
  [
    [0.5, 0.5], [0.5, 2], [2, 2], [2, 0.5], [0.5, 0.5]
  ]
));

And instead of returning [[0.5, 0.5], [0.5, 1], [1, 1], [1, 0.5], [0.5, 0.5]] it returns

[ [ [ 1, 0.5 ],
    [ 1, 0 ],
    [ 0, 0 ],
    [ 0, 0 ],
    [ 0, 1 ],
    [ 1, 1 ],
    [ 1, 0.5 ] ] ]

which corresponds to the first square...

@srt19170
Copy link

Ditto, I've run into this as well.

@hefler
Copy link

hefler commented Mar 5, 2019

I think what you guys are facing is a Leaflet issue.
In Leaflet polygons should not have the same first and last coords.

From the docs (https://leafletjs.com/reference-1.4.0.html#polygon)

A class for drawing polygon overlays on a map. Extends Polyline. Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.

@Xrayez
Copy link

Xrayez commented Aug 11, 2021

In Leaflet polygons should not have the same first and last coords.

I'd go as far as to say that this is how other polygon clipping algorithms work to be honest. For example, in Clipper you can add both polygons (closed) and polylines (open), and this is explicitly distinguished via closed = true parameter when adding paths.

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

5 participants