Skip to main content

Clipper64

Clipper64 class

Official Documentation

note

The Clipper class performs boolean 'clipping' using coordinates of type Int64.

tip

Subject and Clip paths are passed to a Clipper object via AddSubject, AddOpenSubject and AddClip methods. Clipping operations are then initiated by calling Execute. And Execute can be called multiple times (ie with different ClipTypes & FillRules) without having to reload these paths.

caution

All coordinates are represented internally using integers as this is the only way to ensure numerical robustness. While the library also accepts floating point coordinates (see PointD), these will be converted into integers internally (using user specified scaling).

Properties

PreserveCollinear: boolean

Whenever adjacent edges are collinear in closed path solutions, the common vertex can be removed from the path without altering its shape. However, because some users prefer to retain these vertices, this feature is optional. Nevertheless, when adjacent edges in solutions are 180 degree collinear (creating overlapping edge 'spikes'), these vertices will be removed irrespective of the PreserveCollinear setting.
This property is enabled by default.

ReverseSolution: boolean

Reverses the solution's orientation. Normally, closed paths will have Positive orientation.

Functions

new

Clipper64.new() void

Clipper64 constructor.


Clear

Clipper64:Clear() void

The Clear method removes any existing subject and clip polygons allowing the Clipper object to be reused for clipping operations on different polygon sets.
Official Documentation


AddSubject

Clipper64:AddSubject(
path: Path64
) void

ArgumentTypeDescription
pathPath64

Adds one or more closed subject paths (polygons) to the Clipper64 object.
Official Documentation


AddSubject

Clipper64:AddSubject(
paths: Paths64
) void

ArgumentTypeDescription
pathsPaths64

Adds one or more closed subject paths (polygons) to the Clipper64 object.
Official Documentation


AddOpenSubject

Clipper64:AddOpenSubject(
path: Path64
) void

ArgumentTypeDescription
pathPath64

Adds one or more open subject paths (polylines) to the Clipper64 object.
Official Documentation


AddOpenSubject

Clipper64:AddOpenSubject(
paths: Paths64
) void

ArgumentTypeDescription
pathsPaths64

Adds one or more open subject paths (polylines) to the Clipper64 object.
Official Documentation


AddClip

Clipper64:AddClip(
path: Path64
) void

ArgumentTypeDescription
pathPath64

Adds one or more clip polygons to the Clipper64 object.
Official Documentation


AddClip

Clipper64:AddClip(
paths: Paths64
) void

ArgumentTypeDescription
pathsPaths64

Adds one or more clip polygons to the Clipper64 object.
Official Documentation


Execute

Clipper64:Execute(
clipType: ClipType,
fillRule: FillRule,
closedPaths: Paths64
) boolean

ArgumentTypeDescription
clipTypeClipType
fillRuleFillRule
closedPathsPaths64Output for closed paths.

Executes clipping operation from given settings and pre-assigned subject and clip paths.
Official Documentation

Example: Full example of Union operation using Clipper64 object.
local Clipper64 = Clipper.Clipper64.new();

Callback.Bind(CallbackType.OnDraw, function()
Clipper64:Clear()

local pos = Game.localPlayer.position2D

local path1 = Clipper.CreatePath64FromVectors({
Math.Vector2(pos.x - 300, pos.y - 300),
Math.Vector2(pos.x + 300, pos.y - 300),
Math.Vector2(pos.x + 300, pos.y + 300),
Math.Vector2(pos.x - 300, pos.y + 300),
})

local path2 = Clipper.CreatePath64FromVectors({
Math.Vector2(pos.x - 200 + 300, pos.y - 200),
Math.Vector2(pos.x + 200 + 300, pos.y - 200),
Math.Vector2(pos.x + 200 + 300, pos.y + 200),
Math.Vector2(pos.x - 200 + 300, pos.y + 200),
})

Clipper64:AddSubject(path1)
Clipper64:AddSubject(path2)

local paths = Clipper.CreatePaths64({}) -- Output
Clipper64:Execute(Clipper.ClipType.Union, Clipper.FillRule.NonZero, paths)

-- Determine color based on whether our cursor is inside this polygon or not:
local color = Clipper.PointInPolygons(Game.GetCursorWorldPosition(), union) and 0xFF00FF00 or 0xFFFF0000

-- Draw:
Renderer.DrawPaths(union, 1, color)
end)

Execute

Clipper64:Execute(
clipType: ClipType,
fillRule: FillRule,
closedPaths: Paths64,
openPaths: Paths64
) boolean

ArgumentTypeDescription
clipTypeClipType
fillRuleFillRule
closedPathsPaths64Output for closed paths.
openPathsPaths64Output for open paths.

Executes clipping operation from given settings and pre-assigned subject and clip paths.
Official Documentation