Skip to main content

Module clipping

Module clipping 

Source
Expand description

Weiler-Atherton polygon clipping engine

Production-grade polygon clipping supporting Intersection, Union, Difference, and Symmetric Difference (XOR) operations. Handles holes, degeneracies, self-intersecting polygons, and floating-point edge cases.

§Algorithm

The Weiler-Atherton algorithm proceeds in five phases:

  1. Intersection detection – segment-segment tests between polygon boundaries
  2. Entry/exit labeling – cross-product orientation classifies each intersection as entering or exiting the other polygon
  3. Polygon tracing – walk along subject/clip polygons, switching at intersections to build result rings
  4. Hole handling – process holes independently, classify output rings as exterior/interior by winding, assign holes via point-in-polygon
  5. Degeneracy handling – epsilon snap, zero-length edge removal

§Operations

Enums§

ClipOperation
Polygon clipping operation kind.

Functions§

clip_multi
Clip subject against a set of clip polygons in sequence.
clip_polygons
Clip two polygons with the given boolean operation.