alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
535 stars 56 forks source link

Can I merge duplicated edges and merge faces in Polygon? #162

Closed mathedu4all closed 6 months ago

mathedu4all commented 6 months ago

Screenshot from 2024-01-23 15-45-07

For example, can i construct the cross shape as polygon with 5 faces. and use some algorithm to merge these 5 faces as one face.

This is not a bug, but to check if this feature can be accomplish theoretically?

alexbol99 commented 6 months ago

Hi, @mathedu4all, Not exactly what you describe, but you can create 5 polygons and then unify them. If you already have one polygon with 5 faces, you can do following:

import {Polygon, BooleanOperations} from "@flatten-js/core"

let parts = polygon.toArray();  // create array of 5 polygons
let polygon1 = new Polygon();
for (const part of parts) {
    polygon1 = BooleanOperations.unify(polygon1, part);
}

In the resulted polygon duplicated edges will be eliminated

mathedu4all commented 6 months ago

Forgive me ignoring the 'unify' method, thanks a lot for your great contribution.

alexbol99 commented 6 months ago

If it works for you, @mathedu4all , that is great! Thank you for collaboration