public static InterceptedShape FindShapeIntersection(InterceptedShape lower, Shape upper) { List <VisibleSdlPoint> interPoints = new List <VisibleSdlPoint>(); for (int i = 0; i < lower.Points.Length; i++) { bool r = !IsPointInPolygon(upper.Points, lower.Points[i].Point); if (upper.Layer < 0) { r = !r; } interPoints.Add(new VisibleSdlPoint() { Point = lower.Points[i].Point, IsVisible = lower.Points[i].IsVisible && r }); for (int j = 0; j < upper.Points.Length; j++) { var interPoint = FindLinesIntersectionPoint(lower.Points[i].Point, lower.Points[(i + 1) % lower.Points.Length].Point, upper.Points[j], upper.Points[(j + 1) % upper.Points.Length]); if (interPoint.HasValue) { interPoints.Add(new VisibleSdlPoint() { Point = interPoint.Value, IsVisible = false }); } } } return(new InterceptedShape(interPoints.ToArray())); }
public static InterceptedShape FindIntersectionedShape(Shape shape, IEnumerable <Shape> shapes) { var interShape = new InterceptedShape( shape.Points.Select(e => new VisibleSdlPoint() { Point = e, IsVisible = true }).ToArray()); foreach (var temp in shapes.Where(e => Math.Abs(e.Layer) > Math.Abs(shape.Layer))) { interShape = FindShapeIntersection(interShape, temp); } return(interShape); }
private static void DrawShape(IntPtr renderer, InterceptedShape shape) { for (int i = 0; i < shape.Points.Length; i++) { if (!shape.Points[i].IsVisible && !shape.Points[(i + 1) % shape.Points.Length].IsVisible) { if (!(shape.Points.Length > 50 && i % 2 == 0)) { DrawDashLine(renderer, shape.Points[i].Point, shape.Points[(i + 1) % shape.Points.Length].Point); } } else { DrawLine(renderer, shape.Points[i].Point, shape.Points[(i + 1) % shape.Points.Length].Point); } } }