Class ClipperD

java.lang.Object
com.github.micycle1.clipper2.engine.ClipperD

public class ClipperD extends Object
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

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    final void
    Adds one or more clip polygons to the Clipper object.
    void
    addClip(PathD path)
    Adds a clip path.
    final void
    Adds one or more clip polygons to the Clipper object.
    void
    Adds multiple clip paths.
    final void
    Adds one or more open subject paths (polylines) to the Clipper object.
    void
    Adds an open subject path.
    final void
    Adds one or more open subject paths (polylines) to the Clipper object.
    void
    Adds multiple open subject paths.
    final void
    addPath(Path64 path, PathType polytype)
    Adds a path as either a subject or clip polygon.
    final void
    addPath(Path64 path, PathType polytype, boolean isOpen)
    Adds a path as either a closed polygon or an open path.
    void
    addPath(PathD path, PathType polytype)
    Adds a closed path as either subject or clip input.
    void
    addPath(PathD path, PathType polytype, boolean isOpen)
    Adds a path as either subject or clip input.
    final void
    addPaths(Paths64 paths, PathType polytype)
    Adds multiple closed subject or clip polygons.
    final void
    addPaths(Paths64 paths, PathType polytype, boolean isOpen)
    Adds multiple subject or clip paths.
    void
    addPaths(PathsD paths, PathType polytype)
    Adds multiple closed paths as either subject or clip input.
    void
    addPaths(PathsD paths, PathType polytype, boolean isOpen)
    Adds multiple paths as either subject or clip input.
    protected void
    addReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData)
    Loads preprocessed path data created in a ClipperBase.ReuseableDataContainer64.
    final void
    Adds a closed subject path.
    void
    Adds a closed subject path.
    final void
    Adds one or more closed subject paths (polygons) to the Clipper object.
    void
    Adds multiple closed subject paths.
    static boolean
    buildPath(@Nullable com.github.micycle1.clipper2.engine.ClipperBase.OutPt op, boolean reverse, boolean isOpen, Path64 path)
    Converts a linked ClipperBase.OutPt solution into a Path64.
    protected final boolean
    BuildPaths(Paths64 solutionClosed, Paths64 solutionOpen)
    Builds closed and open path solutions from the current clipping result.
    protected void
    BuildTree(PolyPathBase polytree, Paths64 solutionOpen)
    Builds a polygon tree, preserving parent-child nesting information, and collects any open solution paths.
    final void
    Removes all loaded paths together with any current solution state.
    protected final void
    Clears the current solution state while leaving the loaded subject and clip paths unchanged.
    boolean
    execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed)
    Executes the requested clipping operation and returns only closed solution paths.
    boolean
    execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed, PathsD solutionOpen)
    Executes the requested clipping operation and returns closed and open results as scaled PathsD collections.
    boolean
    execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree)
    Executes the requested clipping operation and writes the nested closed-path result to a PolyTreeD.
    boolean
    execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree, PathsD openPaths)
    Executes the requested clipping operation and writes the nested closed-path result to a PolyTreeD.
    protected final void
    Executes the core clipping algorithm for the currently loaded input paths.
    final Rect64
    Returns the bounding rectangle of all currently loaded input paths.
    final boolean
    Returns whether collinear vertices are preserved in closed-path solutions.
    final boolean
    Returns whether solution path orientation is reversed before being output.
    protected final void
    Prepares the loaded input paths so another clipping operation can be executed.
    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.
    final void
    setReverseSolution(boolean value)
    Sets whether generated solution paths should use the reverse orientation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public void addPath(PathD path, PathType polytype)
      Adds a closed path as either subject or clip input.
      Parameters:
      path - the path to add
      polytype - the role the path will play in the clipping operation
    • addPath

      public void addPath(PathD path, PathType polytype, boolean isOpen)
      Adds a path as either subject or clip input.
      Parameters:
      path - the path to add
      polytype - the role the path will play in the clipping operation
      isOpen - true when the path should be treated as open
    • addPaths

      public void addPaths(PathsD paths, PathType polytype)
      Adds multiple closed paths as either subject or clip input.
      Parameters:
      paths - the paths to add
      polytype - the role the paths will play in the clipping operation
    • addPaths

      public void addPaths(PathsD paths, PathType polytype, boolean isOpen)
      Adds multiple paths as either subject or clip input.
      Parameters:
      paths - the paths to add
      polytype - the role the paths will play in the clipping operation
      isOpen - true when the paths should be treated as open
    • addSubject

      public void addSubject(PathD path)
      Adds a closed subject path.
      Parameters:
      path - the path to add
    • addOpenSubject

      public void addOpenSubject(PathD path)
      Adds an open subject path.
      Parameters:
      path - the path to add
    • addClip

      public void addClip(PathD path)
      Adds a clip path.
      Parameters:
      path - the path to add
    • addSubjects

      public void addSubjects(PathsD paths)
      Adds multiple closed subject paths.
      Parameters:
      paths - the paths to add
    • addOpenSubjects

      public void addOpenSubjects(PathsD paths)
      Adds multiple open subject paths.
      Parameters:
      paths - the paths to add
    • addClips

      public void addClips(PathsD paths)
      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 scaled PathsD collections.
      Parameters:
      clipType - the clipping operation to perform
      fillRule - the fill rule used during clipping
      solutionClosed - receives closed solution paths
      solutionOpen - receives open solution paths
      Returns:
      true when clipping completed successfully
    • execute

      public boolean execute(ClipType clipType, FillRule fillRule, PathsD solutionClosed)
      Executes the requested clipping operation and returns only closed solution paths.
      Parameters:
      clipType - the clipping operation to perform
      fillRule - the fill rule used during clipping
      solutionClosed - receives closed solution paths
      Returns:
      true when clipping completed successfully
    • execute

      public boolean execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree, PathsD openPaths)
      Executes the requested clipping operation and writes the nested closed-path result to a PolyTreeD.
      Parameters:
      clipType - the clipping operation to perform
      fillRule - the fill rule used during clipping
      polytree - receives the closed solution hierarchy
      openPaths - receives any open solution paths
      Returns:
      true when clipping completed successfully
    • execute

      public boolean execute(ClipType clipType, FillRule fillRule, PolyTreeD polytree)
      Executes the requested clipping operation and writes the nested closed-path result to a PolyTreeD.
      Parameters:
      clipType - the clipping operation to perform
      fillRule - the fill rule used during clipping
      polytree - receives the closed solution hierarchy
      Returns:
      true when clipping completed successfully
    • getPreserveCollinear

      public final boolean getPreserveCollinear()
      Returns whether collinear vertices are preserved in closed-path solutions.
      Returns:
      true when 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:
      true when 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 - true to 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

      public final void addSubject(Path64 path)
      Adds a closed subject path.
      Parameters:
      path - the path to add
    • addSubject

      public final void addSubject(Paths64 paths)
      Adds one or more closed subject paths (polygons) to the Clipper object.
    • addOpenSubject

      public final void addOpenSubject(Path64 path)
      Adds one or more open subject paths (polylines) to the Clipper object.
    • addOpenSubject

      public final void addOpenSubject(Paths64 paths)
      Adds one or more open subject paths (polylines) to the Clipper object.
      Parameters:
      paths - the open subject paths to add
    • addClip

      public final void addClip(Path64 path)
      Adds one or more clip polygons to the Clipper object.
    • addClip

      public final void addClip(Paths64 paths)
      Adds one or more clip polygons to the Clipper object.
      Parameters:
      paths - the clip polygons to add
    • addPath

      public final void addPath(Path64 path, PathType polytype)
      Adds a path as either a subject or clip polygon.
      Parameters:
      path - the path to add
      polytype - the role the path will play in the clipping operation
    • addPath

      public final void addPath(Path64 path, PathType polytype, boolean isOpen)
      Adds a path as either a closed polygon or an open path.
      Parameters:
      path - the path to add
      polytype - the role the path will play in the clipping operation
      isOpen - true when the path should be treated as open
    • addPaths

      public final void addPaths(Paths64 paths, PathType polytype)
      Adds multiple closed subject or clip polygons.
      Parameters:
      paths - the paths to add
      polytype - the role the paths will play in the clipping operation
    • addPaths

      public final void addPaths(Paths64 paths, PathType polytype, boolean isOpen)
      Adds multiple subject or clip paths.
      Parameters:
      paths - the paths to add
      polytype - the role the paths will play in the clipping operation
      isOpen - true when 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 a ClipperBase.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

      protected final void ExecuteInternal(ClipType ct, FillRule fillRule)
      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 perform
      fillRule - 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 linked ClipperBase.OutPt solution into a Path64.
      Parameters:
      op - the linked solution points to convert
      reverse - whether to traverse the points in reverse order
      isOpen - whether the source path is open
      path - receives the converted path
      Returns:
      true when a non-degenerate path was produced
    • BuildPaths

      protected final boolean BuildPaths(Paths64 solutionClosed, Paths64 solutionOpen)
      Builds closed and open path solutions from the current clipping result.
      Parameters:
      solutionClosed - receives closed solution paths
      solutionOpen - receives open solution paths
      Returns:
      always true
    • BuildTree

      protected void BuildTree(PolyPathBase polytree, Paths64 solutionOpen)
      Builds a polygon tree, preserving parent-child nesting information, and collects any open solution paths.
      Parameters:
      polytree - receives the closed solution hierarchy
      solutionOpen - receives open solution paths
    • getBounds

      public final Rect64 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