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

How to convert between different formats? #46

Open
Pflyg opened this issue May 27, 2020 · 0 comments
Open

How to convert between different formats? #46

Pflyg opened this issue May 27, 2020 · 0 comments

Comments

@Pflyg
Copy link

Pflyg commented May 27, 2020

I wanted to use FlattenJS for just it's polygon boolean operations (since I already have implemented other functionality otherwise) and for that want to convert my polygon format into FlattenJS format.
For that I use the following function: return Flatten.polygon(this.points.map(p => Flatten.point(p.x, p.y)));
this.points is an array of points Point: {x, y}. For a hexagon I would have 6 points at the corners for example.This actually works fine.

But when I want to convert the result of a boolean intersection back the polygon seems to be intersecting itself (even though .isValid returns true). This is the function I use to convert them back:
var points = intersection.vertices.map(p => new Point(p.x, p.y))
new Point is the same type I used above.
It seems like the vertices of flattenJs seem to be a bit more complicated. How would I go about converting them to just an array of points, each point being connected to the next one?

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

1 participant