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
Configuration settings
One of CLIP_TYPES
Object passed to the clippingObject methods toPolygon and pointsBetween
Static
CLIP_The supported clip types. Values are equivalent to those in ClipperLib.ClipType.
Static
INTERSECTION_The supported intersection types.
Private
#combineClip 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
Private
#processGiven 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
Private
#buildPrivate
#buildConstruct 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
Static
unionUnion a polygon and clipObject using the Weiler Atherton algorithm.
Polygon to clip
Object to clip against the polygon
Options passed to the clipping object methods toPolygon and pointsBetween
Static
intersectIntersect a polygon and clipObject using the Weiler Atherton algorithm.
Polygon to clip
Object to clip against the polygon
Options passed to the clipping object methods toPolygon and pointsBetween
Static
combineClip 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
Optional
options: { Options which configure how the union or intersection is computed
One of CLIP_TYPES
If the WeilerAtherton constructor could mutate or not the subject polygon points
Options passed to the WeilerAthertonClipper constructor
Array of polygons and clipObjects
Static
testTest 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.
Static
Private
#consolidateGiven 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/