Clipper

clipper.Clipper (Class)

High-level static API for common polygon clipping and offsetting operations. This module provides simple functions that cover most polygon boolean and offsetting needs while avoiding the inherent complexities of other modules.

Static Members

intersect(subject: Paths64, clip: Paths64, fillRule: FillRule): Paths64

Computes the intersection of subject and clip paths.

Name Type
subject Paths64
clip Paths64
fillRule FillRule
Returns
Paths64

intersectD(subject: PathsD, clip: PathsD, fillRule: FillRule, ?precision: Int = 2): PathsD

Computes the intersection of subject and clip paths (floating-point).

Name Type Default
subject PathsD
clip PathsD
fillRule FillRule
precision Int 2
Returns
PathsD

union(subject: Paths64, fillRule: FillRule): Paths64

Computes the union of subject paths.

Name Type
subject Paths64
fillRule FillRule
Returns
Paths64

unionWithClip(subject: Paths64, clip: Paths64, fillRule: FillRule): Paths64

Computes the union of subject and clip paths.

Name Type
subject Paths64
clip Paths64
fillRule FillRule
Returns
Paths64

unionD(subject: PathsD, fillRule: FillRule): PathsD

Computes the union of subject paths (floating-point).

Name Type
subject PathsD
fillRule FillRule
Returns
PathsD

unionWithClipD(subject: PathsD, clip: PathsD, fillRule: FillRule, ?precision: Int = 2): PathsD

Computes the union of subject and clip paths (floating-point).

Name Type Default
subject PathsD
clip PathsD
fillRule FillRule
precision Int 2
Returns
PathsD

difference(subject: Paths64, clip: Paths64, fillRule: FillRule): Paths64

Computes the difference of subject and clip paths (subject - clip).

Name Type
subject Paths64
clip Paths64
fillRule FillRule
Returns
Paths64

differenceD(subject: PathsD, clip: PathsD, fillRule: FillRule, ?precision: Int = 2): PathsD

Computes the difference of subject and clip paths (floating-point).

Name Type Default
subject PathsD
clip PathsD
fillRule FillRule
precision Int 2
Returns
PathsD

xor(subject: Paths64, clip: Paths64, fillRule: FillRule): Paths64

Computes the XOR (symmetric difference) of subject and clip paths.

Name Type
subject Paths64
clip Paths64
fillRule FillRule
Returns
Paths64

xorD(subject: PathsD, clip: PathsD, fillRule: FillRule, ?precision: Int = 2): PathsD

Computes the XOR of subject and clip paths (floating-point).

Name Type Default
subject PathsD
clip PathsD
fillRule FillRule
precision Int 2
Returns
PathsD

booleanOp(clipType: ClipType, subject: Null<Paths64>, clip: Null<Paths64>, fillRule: FillRule): Paths64

Performs a boolean operation on subject and clip paths.

Name Type
clipType ClipType
subject Null<Paths64>
clip Null<Paths64>
fillRule FillRule
Returns
Paths64

booleanOpD(clipType: ClipType, subject: PathsD, clip: Null<PathsD>, fillRule: FillRule, ?precision: Int = 2): PathsD

Performs a boolean operation on subject and clip paths (floating-point).

Name Type Default
clipType ClipType
subject PathsD
clip Null<PathsD>
fillRule FillRule
precision Int 2
Returns
PathsD

inflatePaths(paths: Paths64, delta: Float, joinType: JoinType, endType: EndType, ?miterLimit: Float = 2.0, ?arcTolerance: Float = 0.0): Paths64

Inflates or deflates paths by the given delta.

Name Type Default
paths Paths64
delta Float
joinType JoinType
endType EndType
miterLimit Float 2.0
arcTolerance Float 0.0
Returns
Paths64

inflatePathsD(paths: PathsD, delta: Float, joinType: JoinType, endType: EndType, ?miterLimit: Float = 2.0, ?precision: Int = 2, ?arcTolerance: Float = 0.0): PathsD

Inflates or deflates paths by the given delta (floating-point).

Name Type Default
paths PathsD
delta Float
joinType JoinType
endType EndType
miterLimit Float 2.0
precision Int 2
arcTolerance Float 0.0
Returns
PathsD

rectClip(rect: Rect64, paths: Paths64): Paths64

Clips paths to the given rectangle.

Name Type
rect Rect64
paths Paths64
Returns
Paths64

rectClipPath(rect: Rect64, path: Path64): Paths64

Clips a single path to the given rectangle.

Name Type
rect Rect64
path Path64
Returns
Paths64

rectClipD(rect: RectD, paths: PathsD, ?precision: Int = 2): PathsD

Clips paths to the given rectangle (floating-point).

Name Type Default
rect RectD
paths PathsD
precision Int 2
Returns
PathsD

rectClipLines(rect: Rect64, paths: Paths64): Paths64

Clips lines (open paths) to the given rectangle.

Name Type
rect Rect64
paths Paths64
Returns
Paths64

rectClipLinesD(rect: RectD, paths: PathsD, ?precision: Int = 2): PathsD

Clips lines to the given rectangle (floating-point).

Name Type Default
rect RectD
paths PathsD
precision Int 2
Returns
PathsD

minkowskiSum(pattern: Path64, path: Path64, isClosed: Bool): Paths64

Computes the Minkowski sum of pattern and path.

Name Type
pattern Path64
path Path64
isClosed Bool
Returns
Paths64

minkowskiSumD(pattern: PathD, path: PathD, isClosed: Bool, ?decimalPlaces: Int = 2): PathsD

Computes the Minkowski sum (floating-point).

Name Type Default
pattern PathD
path PathD
isClosed Bool
decimalPlaces Int 2
Returns
PathsD

minkowskiDiff(pattern: Path64, path: Path64, isClosed: Bool): Paths64

Computes the Minkowski difference of pattern and path.

Name Type
pattern Path64
path Path64
isClosed Bool
Returns
Paths64

minkowskiDiffD(pattern: PathD, path: PathD, isClosed: Bool, ?decimalPlaces: Int = 2): PathsD

Computes the Minkowski difference (floating-point).

Name Type Default
pattern PathD
path PathD
isClosed Bool
decimalPlaces Int 2
Returns
PathsD

areaPath64(path: Path64): Float

Calculates the signed area of a path using the Shoelace formula.

Name Type
path Path64
Returns
Float

areaPaths64(paths: Paths64): Float

Calculates the signed area of multiple paths.

Name Type
paths Paths64
Returns
Float

areaPathD(path: PathD): Float

Calculates the signed area of a path (floating-point).

Name Type
path PathD
Returns
Float

areaPathsD(paths: PathsD): Float

Calculates the signed area of multiple paths (floating-point).

Name Type
paths PathsD
Returns
Float

isPositive(poly: Path64): Bool

Returns true if the path has positive (counter-clockwise) area.

Name Type
poly Path64
Returns
Bool

isPositiveD(poly: PathD): Bool

Returns true if the path has positive (counter-clockwise) area (floating-point).

Name Type
poly PathD
Returns
Bool

translatePath(path: Path64, dx: ClipperInt64, dy: ClipperInt64): Path64

Translates a path by dx, dy.

Name Type
path Path64
dx ClipperInt64
dy ClipperInt64
Returns
Path64

translatePaths(paths: Paths64, dx: ClipperInt64, dy: ClipperInt64): Paths64

Translates multiple paths by dx, dy.

Name Type
paths Paths64
dx ClipperInt64
dy ClipperInt64
Returns
Paths64

translatePathD(path: PathD, dx: Float, dy: Float): PathD

Translates a path by dx, dy (floating-point).

Name Type
path PathD
dx Float
dy Float
Returns
PathD

translatePathsD(paths: PathsD, dx: Float, dy: Float): PathsD

Translates multiple paths by dx, dy (floating-point).

Name Type
paths PathsD
dx Float
dy Float
Returns
PathsD

reversePath(path: Path64): Path64

Returns a reversed copy of the path.

Name Type
path Path64
Returns
Path64

reversePathD(path: PathD): PathD

Returns a reversed copy of the path (floating-point).

Name Type
path PathD
Returns
PathD

reversePaths(paths: Paths64): Paths64

Returns reversed copies of all paths.

Name Type
paths Paths64
Returns
Paths64

reversePathsD(paths: PathsD): PathsD

Returns reversed copies of all paths (floating-point).

Name Type
paths PathsD
Returns
PathsD

scalePath(path: Path64, scale: Float): Path64

Scales a path by the given factor.

Name Type
path Path64
scale Float
Returns
Path64

scalePaths(paths: Paths64, scale: Float): Paths64

Scales multiple paths by the given factor.

Name Type
paths Paths64
scale Float
Returns
Paths64

scalePath64(path: PathD, scale: Float): Path64

Scales a PathD to Path64 with the given scale.

Name Type
path PathD
scale Float
Returns
Path64

scalePaths64(paths: PathsD, scale: Float): Paths64

Scales PathsD to Paths64 with the given scale.

Name Type
paths PathsD
scale Float
Returns
Paths64

scalePathD(path: Path64, scale: Float): PathD

Scales a Path64 to PathD with the given scale.

Name Type
path Path64
scale Float
Returns
PathD

scalePathsD(paths: Paths64, scale: Float): PathsD

Scales Paths64 to PathsD with the given scale.

Name Type
paths Paths64
scale Float
Returns
PathsD

scaleRect(rect: RectD, scale: Float): Rect64

Scales a RectD to Rect64.

Name Type
rect RectD
scale Float
Returns
Rect64

pathDToPath64(path: PathD): Path64

Converts PathD to Path64 without scaling.

Name Type
path PathD
Returns
Path64

pathsDToPaths64(paths: PathsD): Paths64

Converts PathsD to Paths64 without scaling.

Name Type
paths PathsD
Returns
Paths64

path64ToPathD(path: Path64): PathD

Converts Path64 to PathD without scaling.

Name Type
path Path64
Returns
PathD

paths64ToPathsD(paths: Paths64): PathsD

Converts Paths64 to PathsD without scaling.

Name Type
paths Paths64
Returns
PathsD

getBoundsPath64(path: Path64): Rect64

Gets the bounding rectangle of a path.

Name Type
path Path64
Returns
Rect64

getBoundsPaths64(paths: Paths64): Rect64

Gets the bounding rectangle of multiple paths.

Name Type
paths Paths64
Returns
Rect64

getBoundsPathD(path: PathD): RectD

Gets the bounding rectangle of a path (floating-point).

Name Type
path PathD
Returns
RectD

getBoundsPathsD(paths: PathsD): RectD

Gets the bounding rectangle of multiple paths (floating-point).

Name Type
paths PathsD
Returns
RectD

makePathInt(arr: Array<Int>): Path64

Creates a path from an array of integers [x1, y1, x2, y2, ...].

Name Type
arr Array<Int>
Returns
Path64

makePathFloat(arr: Array<Float>): PathD

Creates a path from an array of floats [x1, y1, x2, y2, ...].

Name Type
arr Array<Float>
Returns
PathD

sqr(val: Float): Float

Calculates the squared distance between two points.

Name Type
val Float
Returns
Float

distanceSqr(pt1: Point64, pt2: Point64): Float

Calculates the squared distance between two Point64 values.

Name Type
pt1 Point64
pt2 Point64
Returns
Float

midPoint(pt1: Point64, pt2: Point64): Point64

Calculates the midpoint between two Point64 values.

Name Type
pt1 Point64
pt2 Point64
Returns
Point64

midPointD(pt1: PointD, pt2: PointD): PointD

Calculates the midpoint between two PointD values.

Name Type
pt1 PointD
pt2 PointD
Returns
PointD

pointsNearEqual(pt1: PointD, pt2: PointD, distanceSqrd: Float): Bool

Tests if a point is near equal to another point within a squared distance tolerance.

Name Type
pt1 PointD
pt2 PointD
distanceSqrd Float
Returns
Bool

stripNearDuplicates(path: PathD, minEdgeLenSqrd: Float, isClosedPath: Bool): PathD

Strips near-duplicate points from a path.

Name Type
path PathD
minEdgeLenSqrd Float
isClosedPath Bool
Returns
PathD

stripDuplicates(path: Path64, isClosedPath: Bool): Path64

Strips duplicate points from a path.

Name Type
path Path64
isClosedPath Bool
Returns
Path64

perpendicDistFromLineSqrd(pt: Point64, line1: Point64, line2: Point64): Float

Returns perpendicular distance squared from a point to a line.

Name Type
pt Point64
line1 Point64
line2 Point64
Returns
Float

perpendicDistFromLineSqrdD(pt: PointD, line1: PointD, line2: PointD): Float

Returns perpendicular distance squared from a point to a line (floating-point).

Name Type
pt PointD
line1 PointD
line2 PointD
Returns
Float

pointInPolygon(pt: Point64, polygon: Path64): PointInPolygonResult

Tests if a point is inside a polygon.

Name Type
pt Point64
polygon Path64
Returns
PointInPolygonResult

ellipse(center: Point64, radiusX: Float, ?radiusY: Float = 0, ?steps: Int = 0): Path64

Generates an ellipse path.

Name Type Default
center Point64
radiusX Float
radiusY Float 0
steps Int 0
Returns
Path64

ellipseD(center: PointD, radiusX: Float, ?radiusY: Float = 0, ?steps: Int = 0): PathD

Generates an ellipse path (floating-point).

Name Type Default
center PointD
radiusX Float
radiusY Float 0
steps Int 0
Returns
PathD

trimCollinear(path: Path64, ?isOpen: Bool = false): Path64

Trims collinear points from a path.

Name Type Default
path Path64
isOpen Bool false
Returns
Path64

triangulate(paths: Paths64, ?useDelaunay: Bool = true): AnonStruct

Triangulates paths using Constrained Delaunay Triangulation.

Name Type Default
paths Paths64
useDelaunay Bool true
Returns
AnonStruct