PeachDrawing.Core

PeachDrawing.Core.Geometry.PolygonClipper

PolygonClipper.ClipToRect(IReadOnlyList<PaintPoint>, Rect) Method

Clips a closed polygon to an axis-aligned rectangle, one edge of the rectangle at a time. The polygon may be convex, concave or self-intersecting: what makes each edge’s pass exact is that the <em>window</em> is convex, because clipping against a convex window can only shorten an original edge or add a piece of the window’s own boundary. So each contour of a multi-contour outline can be clipped on its own and the results filled together under the same fill rule, without a general polygon-against-polygon boolean.

public static System.Collections.Generic.List<PeachDrawing.Core.PaintPoint> ClipToRect(System.Collections.Generic.IReadOnlyList<PeachDrawing.Core.PaintPoint> polygon, PeachDrawing.Core.Rect rect);

Parameters

polygon System.Collections.Generic.IReadOnlyList<PaintPoint>

the polygon’s vertices in order; the last vertex is joined back to the first

rect Rect

the window to clip to

Returns

System.Collections.Generic.List<PaintPoint>
the clipped polygon’s vertices. Fewer than three vertices means nothing with area is left inside the window (the polygon lies outside it, or was degenerate to begin with); a result of three or more vertices can still enclose no area when they are all collinear, as when an edge runs exactly along the window’s boundary.

Exceptions

System.ArgumentNullException
polygon is null