/// <summary> /// Returns the list of polygons that result from the subshapes common to both A and B. By providing the intersections /// between the two polygons, the operation will be performed with less time and memory. /// </summary> /// <param name="polygonA">The polygon a.</param> /// <param name="polygonB">The polygon b.</param> /// <param name="interaction">The interaction.</param> /// <param name="outputAsCollectionType">Type of the output as collection.</param> /// <param name="tolerance">The minimum allowable area.</param> /// <returns>System.Collections.Generic.List<TVGL.TwoDimensional.Polygon>.</returns> public static List <Polygon> Intersect(this Polygon polygonA, Polygon polygonB, PolygonInteractionRecord interaction, PolygonCollection outputAsCollectionType = PolygonCollection.PolygonWithHoles, double tolerance = double.NaN) { if (interaction.IntersectionWillBeEmpty()) { if (polygonB.IsPositive) { return(new List <Polygon>()); } else { return new List <Polygon> { polygonA.Copy(true, false) } }; } else { polygonIntersection ??= new PolygonIntersection(); return(polygonIntersection.Run(polygonA, polygonB, interaction, outputAsCollectionType, tolerance)); } }
/// <summary> /// Returns the list of polygons that are the Exclusive-OR of the two input polygons. Exclusive-OR are the regions where one polgyon /// resides but not both. By providing the intersections between the two polygons, the operation will be performed with less time and memory. /// </summary> /// <param name="polygonA">The polygon a.</param> /// <param name="polygonB">The polygon b.</param> /// <param name="interactionRecord">The interaction record.</param> /// <param name="outputAsCollectionType">Type of the output as collection.</param> /// <param name="tolerance">The tolerance.</param> /// <returns>System.Collections.Generic.List<TVGL.TwoDimensional.Polygon>.</returns> public static List <Polygon> ExclusiveOr(this Polygon polygonA, Polygon polygonB, PolygonInteractionRecord interactionRecord, PolygonCollection outputAsCollectionType = PolygonCollection.PolygonWithHoles, double tolerance = double.NaN) { if (interactionRecord.IntersectionWillBeEmpty()) { return new List <Polygon> { polygonA.Copy(true, false), polygonB.Copy(true, false) } } ; else if (interactionRecord.Relationship == PolygonRelationship.BInsideA && !interactionRecord.CoincidentEdges && !interactionRecord.CoincidentVertices) { var polygonACopy1 = polygonA.Copy(true, false); polygonACopy1.AddInnerPolygon(polygonB.Copy(true, true)); return(new List <Polygon> { polygonACopy1 }); } else if (interactionRecord.Relationship == PolygonRelationship.AInsideB && !interactionRecord.CoincidentEdges && !interactionRecord.CoincidentVertices) { var polygonBCopy2 = polygonB.Copy(true, false); polygonBCopy2.AddInnerPolygon(polygonA.Copy(true, true)); return(new List <Polygon> { polygonBCopy2 }); } else { var result = polygonA.Subtract(polygonB, interactionRecord, outputAsCollectionType, tolerance); result.AddRange(polygonB.Subtract(polygonA, interactionRecord, outputAsCollectionType, tolerance)); return(result); } }