Class ClipperD
java.lang.Object
com.github.micycle1.clipper2.engine.ClipperD
The ClipperD class performs boolean 'clipping'. This class is very similar to
Clipper64 except that coordinates passed to ClipperD objects are of type
double instead of type long.-
Constructor Summary
ConstructorsConstructorDescriptionClipperD()Creates a clipper that rounds double coordinates to 2 decimal places during internal integer conversion.ClipperD(int roundingDecimalPrecision) Creates a clipper that rounds double coordinates to the requested number of decimal places during internal integer conversion. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAdds one or more clip polygons to the Clipper object.voidAdds a clip path.final voidAdds one or more clip polygons to the Clipper object.voidAdds multiple clip paths.final voidaddOpenSubject(Path64 path) Adds one or more open subject paths (polylines) to the Clipper object.voidaddOpenSubject(PathD path) Adds an open subject path.final voidaddOpenSubject(Paths64 paths) Adds one or more open subject paths (polylines) to the Clipper object.voidaddOpenSubjects(PathsD paths) Adds multiple open subject paths.final voidAdds a path as either a subject or clip polygon.final voidAdds a path as either a closed polygon or an open path.voidAdds a closed path as either subject or clip input.voidAdds a path as either subject or clip input.final voidAdds multiple closed subject or clip polygons.final voidAdds multiple subject or clip paths.voidAdds multiple closed paths as either subject or clip input.voidAdds multiple paths as either subject or clip input.protected voidaddReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData) Loads preprocessed path data created in aClipperBase.ReuseableDataContainer64.final voidaddSubject(Path64 path) Adds a closed subject path.voidaddSubject(PathD path) Adds a closed subject path.final voidaddSubject(Paths64 paths) Adds one or more closed subject paths (polygons) to the Clipper object.voidaddSubjects(PathsD paths) Adds multiple closed subject paths.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.booleanExecutes the requested clipping operation and returns only closed solution paths.booleanExecutes the requested clipping operation and returns closed and open results as scaledPathsDcollections.booleanExecutes the requested clipping operation and writes the nested closed-path result to aPolyTreeD.booleanExecutes the requested clipping operation and writes the nested closed-path result to aPolyTreeD.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
-
ClipperD
public ClipperD()Creates a clipper that rounds double coordinates to 2 decimal places during internal integer conversion. -
ClipperD
public ClipperD(int roundingDecimalPrecision) Creates a clipper that rounds double coordinates to the requested number of decimal places during internal integer conversion.- Parameters:
roundingDecimalPrecision- default = 2
-
-
Method Details
-
addPath
Adds a closed path as either subject or clip input.- Parameters:
path- the path to addpolytype- the role the path will play in the clipping operation
-
addPath
Adds a path as either subject or clip input.- 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 paths as either subject or clip input.- Parameters:
paths- the paths to addpolytype- the role the paths will play in the clipping operation
-
addPaths
Adds multiple paths as either subject or clip input.- Parameters:
paths- the paths to addpolytype- the role the paths will play in the clipping operationisOpen-truewhen the paths should be treated as open
-
addSubject
Adds a closed subject path.- Parameters:
path- the path to add
-
addOpenSubject
Adds an open subject path.- Parameters:
path- the path to add
-
addClip
Adds a clip path.- Parameters:
path- the path to add
-
addSubjects
Adds multiple closed subject paths.- Parameters:
paths- the paths to add
-
addOpenSubjects
Adds multiple open subject paths.- Parameters:
paths- the paths to add
-
addClips
Adds multiple clip paths.- Parameters:
paths- the paths to add
-
execute
public boolean execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed, PathsD solutionOpen) Executes the requested clipping operation and returns closed and open results as scaledPathsDcollections.- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingsolutionClosed- receives closed solution pathssolutionOpen- receives 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 closed solution paths- Returns:
truewhen clipping completed successfully
-
execute
Executes the requested clipping operation and writes the nested closed-path result to aPolyTreeD.- 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 aPolyTreeD.- Parameters:
clipType- the clipping operation to performfillRule- the fill rule used during clippingpolytree- receives the closed solution hierarchy- Returns:
truewhen clipping completed successfully
-
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
-
addReuseableData
protected void addReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData) Loads preprocessed path data created in aClipperBase.ReuseableDataContainer64. Reusing cached data avoids rebuilding the internal vertex structures when the same inputs are clipped repeatedly.- Parameters:
reuseableData- cached path data to load
-
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
-