Construct a WeilerAthertonClipper instance used to perform the calculation.
Polygon to clip
Object used to clip the polygon
Type of clip to use
Object passed to the clippingObject methods toPolygon and pointsBetween
The supported clip types. Values are equivalent to those in ClipperLib.ClipType.
The supported intersection types.
Clip the polygon with the clipObject, assuming no holes will be created. For a union or intersect with no holes, a single pass through the intersections will build the resulting union shape.
Array of linked points and intersections
Given an intersection and the previous intersection, fill the points between the two intersections, in clockwise order.
Intersection to process
Previous intersection to process
Whether we were tracing the polygon (true) or the clipObject (false).
The new polygon that results from this clipping operation
Construct an array of intersections between the polygon and the clipping object. The intersections follow clockwise around the polygon. Round all intersections and polygon vertices to the nearest pixel (integer).
Construct an array that holds all the points of the polygon with all the intersections with the clipObject inserted, in correct position moving clockwise. If an intersection and endpoint are nearly the same, prefer the intersection. Intersections are labeled with isIntersection and type = out/in or in/out. Tangents are removed.
Labeled array of points
Clip a given clipObject using the Weiler-Atherton algorithm.
At the moment, this will return a single PIXI.Polygon in the array unless clipType is a union and the polygon and clipObject do not overlap, in which case the [polygon, clipObject.toPolygon()] array will be returned. If this algorithm is expanded in the future to handle holes, an array of polygons may be returned.
Polygon to clip
Object to clip against the polygon
Options which configure how the union or intersection is computed
Array of polygons and clipObjects
Test if one shape envelops the other. Assumes the shapes do not intersect.
Polygon to clip
Object to clip against the polygon
One of CLIP_TYPES
Clip options which are forwarded to toPolygon methods
Returns the polygon, the clipObject.toPolygon(), both, or neither.
Given an array of labeled points, consolidate into a tracking array of intersections, where each intersection contains its array of leadingPoints.
Array of points, from _buildLabeledIntersectionsArray
Array of intersections
An implementation of the Weiler Atherton algorithm for clipping polygons. This currently only handles combinations that will not result in any holes. Support may be added for holes in the future.
This algorithm is faster than the Clipper library for this task because it relies on the unique properties of the circle, ellipse, or convex simple clip object. It is also more precise in that it uses the actual intersection points between the circle/ellipse and polygon, instead of relying on the polygon approximation of the circle/ellipse to find the intersection points.
For more explanation of the underlying algorithm, see: https://en.wikipedia.org/wiki/Weiler%E2%80%93Atherton_clipping_algorithm https://www.geeksforgeeks.org/weiler-atherton-polygon-clipping-algorithm https://h-educate.in/weiler-atherton-polygon-clipping-algorithm/