public static Point[] GeometryPolygonIntersection(ShapeGeometry geometry, PolygonGeometry polygon) { if (geometry == null || polygon == null) { return(null); } if (!geometry.Bounds.IntersectsWith(polygon.Bounds)) { return(new Point[0]); } LineGeometry[] edges = polygon.Edges; Point[] intersections = null; foreach (LineGeometry edge in edges) { intersections = intersections == null ? geometry.Intersect(edge) : intersections.Union(geometry.Intersect(edge)).ToArray(); } return(intersections); }
public static Point[] PolygonPolygonIntersection(PolygonGeometry firstPolygon, PolygonGeometry secondPolygon) { if (firstPolygon == null || secondPolygon == null) { return(new Point[0]); } if (!firstPolygon.Bounds.IntersectsWith(secondPolygon.Bounds)) { return(new Point[0]); } LineGeometry[] edges = firstPolygon.Edges; Point[] intersections = null; foreach (LineGeometry aEdge in edges) { intersections = intersections == null ? GeometryPolygonIntersection(aEdge, secondPolygon) : intersections.Union(GeometryPolygonIntersection(aEdge, secondPolygon)).ToArray(); } return(intersections); }