/// <summary> /// Clips one Polygon with an other. Returns a Polygon-Set representing the Intersections of the two. /// Works only with all (convex/concave) Polygons /// !!!! UNTESTED !!!! /// </summary> public static IEnumerable <Polygon2d> ClippedBy(this Polygon2d p0, Polygon2d p1, double relativeEpsilon) { List <int[]> i0 = SubPrimitives.ComputeNonConcaveSubPolygons(p0, relativeEpsilon); List <int[]> i1 = SubPrimitives.ComputeNonConcaveSubPolygons(p1, relativeEpsilon); List <Polygon2d> polys = new List <Polygon2d>(); for (int i = 0; i < i0.Count; i++) { for (int u = 0; u < i1.Count; u++) { Polygon2d q0 = new Polygon2d(from o in i0[i] select p0[o]); Polygon2d q1 = new Polygon2d(from o in i1[u] select p1[o]); Polygon2d r = q0.ClippedByConvex(q1); if (r.PointCount > 0) { polys.Add(r); } } } return(Union(polys)); }