/// <summary> /// Removes the specified contour. /// </summary> /// <param name="contour">The contour.</param> public void Remove(PolygonContour contour) { foreach (var item in Shapes) { switch (item) { case Group g: g.Remove(contour); break; case Polygon p: p.Remove(contour); break; case PolygonContour c: if (c == contour) { Shapes.Remove(c); return; } break; } } }
/// <summary> /// Translates the specified path. /// </summary> /// <param name="path">The path.</param> /// <param name="delta">The delta.</param> /// <returns></returns> public static PolygonContour Translate(PolygonContour path, Vector2 delta) { var contour = new List <PointF>(path.Points.Count); for (var i = 0; i < path.Points.Count; i++) { contour.Add(new PointF(path[i].X + delta.X, path[i].Y + delta.Y)); } return(new PolygonContour(contour)); }
public static Inclusions PolygonContourContainsPoint(PolygonContour points, PointF point, double epsilon = double.Epsilon) { // Default value is no inclusion. var result = Inclusions.Outside; if (points is null) { return(result); } // Special cases for points and line segments. if (points?.Count < 3) { if (points.Count == 1) { // If the polygon has 1 point, it is a point and has no interior, but a point can intersect a point. return((point.X == points[0].X && point.Y == points[0].Y) ? Inclusions.Boundary : Inclusions.Outside); } else if (points.Count == 2) { // If the polygon has 2 points, it is a line and has no interior, but a point can intersect a line. return(((point.X == points[0].X) && (point.Y == points[0].Y)) || ((point.X == points[1].X) && (point.Y == points[1].Y)) || (((point.X > points[0].X) == (point.X < points[1].X)) && ((point.Y > points[0].Y) == (point.Y < points[1].Y)) && ((point.X - points[0].X) * (points[1].Y - points[0].Y) == (point.Y - points[0].Y) * (points[1].X - points[0].X))) ? Inclusions.Boundary : Inclusions.Outside); } else { // Empty geometry. return(Inclusions.Outside); } } // Loop through each line segment. var curPoint = points ![0];
/// <summary> /// Inserts the specified contour. /// </summary> /// <param name="index">The index.</param> /// <param name="contour">The contour.</param> public void Insert(int index, PolygonContour contour) => Shapes.Insert(index, contour);
/// <summary> /// Adds the specified contour. /// </summary> /// <param name="contour">The contour.</param> public void Add(PolygonContour contour) { Shapes.Add(contour); }
/// <summary> /// Initializes a new instance of the <see cref="PolygonContour" /> class. /// </summary> /// <param name="polygon">The <paramref name="polygon" />.</param> public PolygonContour(PolygonContour polygon) : this(polygon.Points) { }