Class Clipper64
java.lang.Object
com.github.micycle1.clipper2.engine.Clipper64
The Clipper class performs boolean 'clipping'. This class is very similar to
ClipperD except that coordinates passed to Clipper64 objects are of type
long instead of type double.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds one or more clip polygons to the Clipper object.final voidAdds one or more clip polygons to the Clipper object.final voidaddOpenSubject(Path64 path) Adds one or more open subject paths (polylines) to the Clipper object.final voidaddOpenSubject(Paths64 paths) Adds one or more open subject paths (polylines) to the Clipper object.final voidAdds a path as either a subject or clip polygon.final voidAdds a path as either a closed polygon or an open path.final voidAdds multiple closed subject or clip polygons.final voidAdds multiple subject or clip paths.voidaddReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData) Loads preprocessed reusable path data into this clipper instance.final voidaddSubject(Path64 path) Adds a closed subject path.final voidaddSubject(Paths64 paths) Adds one or more closed subject paths (polygons) to the Clipper object.static booleanbuildPath(@Nullable com.github.micycle1.clipper2.engine.ClipperBase.OutPt op, boolean reverse, boolean isOpen, Path64 path) Converts a linkedClipperBase.OutPtsolution into aPath64.protected final booleanBuildPaths(Paths64 solutionClosed, Paths64 solutionOpen) Builds closed and open path solutions from the current clipping result.protected voidBuildTree(PolyPathBase polytree, Paths64 solutionOpen) Builds a polygon tree, preserving parent-child nesting information, and collects any open solution paths.final voidclear()Removes all loaded paths together with any current solution state.protected final voidClears the current solution state while leaving the loaded subject and clip paths unchanged.final booleanExecutes the requested clipping operation and returns only closed solution paths.final booleanOnce subject and clip paths have been assigned (viaaddSubject(),addOpenSubject()andaddClip()methods),execute()can then perform the specified clipping operation (intersection, union, difference or XOR).final booleanexecute(ClipType clipType, FillRule fillRule, PolyTree64 polytree) Executes the requested clipping operation and writes the nested closed-path result to aPolyTree64.final booleanexecute(ClipType clipType, FillRule fillRule, PolyTree64 polytree, Paths64 openPaths) Executes the requested clipping operation and writes the nested closed-path result to aPolyTree64.protected final voidExecuteInternal(ClipType ct, FillRule fillRule) Executes the core clipping algorithm for the currently loaded input paths.final Rect64Returns the bounding rectangle of all currently loaded input paths.final booleanReturns whether collinear vertices are preserved in closed-path solutions.final booleanReturns whether solution path orientation is reversed before being output.protected final voidReset()Prepares the loaded input paths so another clipping operation can be executed.final voidsetPreserveCollinear(boolean value) When adjacent edges are collinear in closed path solutions, the common vertex can safely be removed to simplify the solution without altering path shape.final voidsetReverseSolution(boolean value) Sets whether generated solution paths should use the reverse orientation.
-
Constructor Details
-
Clipper64
public Clipper64()
-
-
Method Details
-
execute
public final boolean execute(ClipType clipType, FillRule fillRule, Paths64 solutionClosed, Paths64 solutionOpen) Once subject and clip paths have been assigned (viaaddSubject(),addOpenSubject()andaddClip()methods),execute()can then perform the specified clipping operation (intersection, union, difference or XOR).The solution parameter can be either a Paths64 or a PolyTree64, though since the Paths64 structure is simpler and more easily populated (with clipping about 5% faster), it should generally be preferred.
While polygons in solutions should never intersect (either with other polygons or with themselves), they will frequently be nested such that outer polygons will contain inner 'hole' polygons with in turn may contain outer polygons (to any level of nesting). And given that PolyTree64 and PolyTreeD preserve these parent-child relationships, these two PolyTree classes will be very useful to some users.
- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingsolutionClosed- receives the closed solution pathssolutionOpen- receives any open solution paths- Returns:
truewhen clipping completed successfully
-
execute
Executes the requested clipping operation and returns only closed solution paths.- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingsolutionClosed- receives the closed solution paths- Returns:
truewhen clipping completed successfully
-
execute
public final boolean execute(ClipType clipType, FillRule fillRule, PolyTree64 polytree, Paths64 openPaths) Executes the requested clipping operation and writes the nested closed-path result to aPolyTree64.- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingpolytree- receives the closed solution hierarchyopenPaths- receives any open solution paths- Returns:
truewhen clipping completed successfully
-
execute
Executes the requested clipping operation and writes the nested closed-path result to aPolyTree64.- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingpolytree- receives the closed solution hierarchy- Returns:
truewhen clipping completed successfully
-
addReuseableData
public void addReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData) Loads preprocessed reusable path data into this clipper instance.- Parameters:
reuseableData- cached path data to load
-
getPreserveCollinear
public final boolean getPreserveCollinear()Returns whether collinear vertices are preserved in closed-path solutions.- Returns:
truewhen collinear vertices are preserved where possible
-
setPreserveCollinear
public final void setPreserveCollinear(boolean value) When adjacent edges are collinear in closed path solutions, the common vertex can safely be removed to simplify the solution without altering path shape. However, because some users prefer to retain these common vertices, this feature is optional. Nevertheless, when adjacent edges in solutions are collinear and also create a 'spike' by overlapping, the vertex creating the spike will be removed irrespective of the PreserveCollinear setting. This property is enabled by default. -
getReverseSolution
public final boolean getReverseSolution()Returns whether solution path orientation is reversed before being output.- Returns:
truewhen closed and open solution paths are returned in reverse order
-
setReverseSolution
public final void setReverseSolution(boolean value) Sets whether generated solution paths should use the reverse orientation.- Parameters:
value-trueto reverse the orientation of generated paths
-
ClearSolutionOnly
protected final void ClearSolutionOnly()Clears the current solution state while leaving the loaded subject and clip paths unchanged. -
clear
public final void clear()Removes all loaded paths together with any current solution state. -
Reset
protected final void Reset()Prepares the loaded input paths so another clipping operation can be executed. -
addSubject
Adds a closed subject path.- Parameters:
path- the path to add
-
addSubject
Adds one or more closed subject paths (polygons) to the Clipper object. -
addOpenSubject
Adds one or more open subject paths (polylines) to the Clipper object. -
addOpenSubject
Adds one or more open subject paths (polylines) to the Clipper object.- Parameters:
paths- the open subject paths to add
-
addClip
Adds one or more clip polygons to the Clipper object. -
addClip
Adds one or more clip polygons to the Clipper object.- Parameters:
paths- the clip polygons to add
-
addPath
Adds a path as either a subject or clip polygon.- Parameters:
path- the path to addpolytype- the role the path will play in the clipping operation
-
addPath
Adds a path as either a closed polygon or an open path.- Parameters:
path- the path to addpolytype- the role the path will play in the clipping operationisOpen-truewhen the path should be treated as open
-
addPaths
Adds multiple closed subject or clip polygons.- Parameters:
paths- the paths to addpolytype- the role the paths will play in the clipping operation
-
addPaths
Adds multiple subject or clip paths.- Parameters:
paths- the paths to addpolytype- the role the paths will play in the clipping operationisOpen-truewhen the paths should be treated as open
-
ExecuteInternal
Executes the core clipping algorithm for the currently loaded input paths. Subclasses call this before converting the generated solution into the desired output format.- Parameters:
ct- the clipping operation to performfillRule- the fill rule used during clipping
-
buildPath
public static boolean buildPath(@Nullable @Nullable com.github.micycle1.clipper2.engine.ClipperBase.OutPt op, boolean reverse, boolean isOpen, Path64 path) Converts a linkedClipperBase.OutPtsolution into aPath64.- Parameters:
op- the linked solution points to convertreverse- whether to traverse the points in reverse orderisOpen- whether the source path is openpath- receives the converted path- Returns:
truewhen a non-degenerate path was produced
-
BuildPaths
Builds closed and open path solutions from the current clipping result.- Parameters:
solutionClosed- receives closed solution pathssolutionOpen- receives open solution paths- Returns:
- always
true
-
BuildTree
Builds a polygon tree, preserving parent-child nesting information, and collects any open solution paths.- Parameters:
polytree- receives the closed solution hierarchysolutionOpen- receives open solution paths
-
getBounds
Returns the bounding rectangle of all currently loaded input paths.- Returns:
- the bounds of the loaded paths, or an empty rectangle when no paths have been added
-