private static int PerformPartition(PARTITION_METHOD method) { int numPolygons = 0; switch (method) { case PARTITION_METHOD.APPROX: numPolygons = CGAL_ApproxConvexPartition(); break; case PARTITION_METHOD.GREENE: numPolygons = CGAL_GreeneApproxConvexPartition(); break; case PARTITION_METHOD.YMONOTONE: numPolygons = CGAL_YMonotonePartition(); break; case PARTITION_METHOD.OPTIMAL: numPolygons = CGAL_OptimalConvexPartition(); break; } return(numPolygons); }
public static List <Polygon2f> Partition(Polygon2f polygon, PARTITION_METHOD method = PARTITION_METHOD.APPROX) { if (!polygon.IsSimple) { throw new ArgumentException("Polygon must be simple."); } if (!polygon.IsCCW) { throw new ArgumentException("Polygon must have counter clock wise orientation. Reverse polygon."); } if (polygon.HasHoles) { throw new NotImplementedException("Polygon with holes not implemented."); } CGAL_LoadPoints(polygon.Positions, polygon.Positions.Length); int numPolygons = PerformPartition(method); List <Polygon2f> partition = new List <Polygon2f>(numPolygons); for (int i = 0; i < numPolygons; i++) { int numPoints = CGAL_GetPolygonSize(i); Polygon2f poly = new Polygon2f(numPoints); for (int j = 0; j < numPoints; j++) { poly.Positions[j] = CGAL_GetPolygonVector2f(i, j); } poly.CalculatePolygon(); partition.Add(poly); } CGAL_Clear(); return(partition); }