/// <summary> /// Constructs the geometric difference between this Polygon and the supplied Polygons. /// </summary> /// <param name="difPolys">The list of intersecting Polygons.</param> /// <returns> /// Returns a list of Polygons representing the subtraction of the supplied Polygons from this Polygon. /// Returns null if the area of this Polygon is entirely subtracted. /// Returns a list containing a representation of the perimeter of this Polygon if the two Polygons do not intersect. /// </returns> public IList <Polygon> Difference(IList <Polygon> difPolys) { var thisPath = this.ToClipperPath(); var polyPaths = new List <List <IntPoint> >(); foreach (Polygon polygon in difPolys) { polyPaths.Add(polygon.ToClipperPath()); } Clipper clipper = new Clipper(); clipper.AddPath(thisPath, PolyType.ptSubject, true); clipper.AddPaths(polyPaths, PolyType.ptClip, true); var solution = new List <List <IntPoint> >(); clipper.Execute(ClipType.ctDifference, solution); if (solution.Count == 0) { return(null); } var polygons = new List <Polygon>(); foreach (List <IntPoint> path in solution) { polygons.Add(PolygonExtensions.ToPolygon(path.Distinct().ToList())); } return(polygons); }
/// <summary> /// Returns Polygons representing the symmetric difference between this Polygon and the supplied Polygon. /// </summary> /// <param name="polygon">The intersecting polygon.</param> /// <returns> /// Returns a list of Polygons representing the symmetric difference of this Polygon and the supplied Polygon. /// Returns a representation of this Polygon and the supplied Polygon if the Polygons do not intersect. /// </returns> public IList <Polygon> XOR(Polygon polygon) { var thisPath = this.ToClipperPath(); var polyPath = polygon.ToClipperPath(); Clipper clipper = new Clipper(); clipper.AddPath(thisPath, PolyType.ptSubject, true); clipper.AddPath(polyPath, PolyType.ptClip, true); var solution = new List <List <IntPoint> >(); clipper.Execute(ClipType.ctUnion, solution); var polygons = new List <Polygon>(); foreach (List <IntPoint> path in solution) { polygons.Add(PolygonExtensions.ToPolygon(path)); } return(polygons); }