ivanfratric / polypartition

Tiny Polygon Partitioning and Triangulation Library
MIT License
664 stars 118 forks source link

Calling RemoveHoles #41

Closed EDToaster closed 3 years ago

EDToaster commented 3 years ago

This is for people who are having a bit of confusion about how to use the different triangulation methods on geometry with holes. (Maybe this could be included into the README for future users?)

Suppose you have a list of contours, some CCW and others CW (indicating holes). With the exception of Triangulate_MONO, you need to explicitly set CW contours to "holes" in the polygon.

Here is a little snippet to demonstrate this.

// convert contours to polygons using polypartition
for (auto contour : contours) {
    TPPLPoly poly;
    // set polygon points from contour. 
    // CCW for geometry and CW for holes

    // Need to manually call SetHole
    if (poly.GetOrientation() == TPPL_CW) {
        poly.SetHole(true);
    }
    polyList.push_back(poly);
}

TPPLPolyList tmpPolys;
// remove the holes
partition.RemoveHoles(&polyList, &tmpPolys);
// call triangulate function of your choice.
partition.Triangulate_EC(&tmpPolys, &outTriangles);