Class Clipper64

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

public class Clipper64 extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Adds one or more clip polygons to the Clipper object.
    final void
    Adds one or more clip polygons to the Clipper object.
    final void
    Adds one or more open subject paths (polylines) to the Clipper object.
    final void
    Adds one or more open subject paths (polylines) to the Clipper object.
    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.
    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
    addReuseableData(com.github.micycle1.clipper2.engine.ClipperBase.ReuseableDataContainer64 reuseableData)
    Loads preprocessed reusable path data into this clipper instance.
    final void
    Adds a closed subject path.
    final void
    Adds one or more closed subject paths (polygons) to the Clipper object.
    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.
    final boolean
    execute(ClipType clipType, FillRule fillRule, Paths64 solutionClosed)
    Executes the requested clipping operation and returns only closed solution paths.
    final boolean
    execute(ClipType clipType, FillRule fillRule, Paths64 solutionClosed, Paths64 solutionOpen)
    Once subject and clip paths have been assigned (via addSubject(), addOpenSubject() and addClip() methods), execute() can then perform the specified clipping operation (intersection, union, difference or XOR).
    final boolean
    execute(ClipType clipType, FillRule fillRule, PolyTree64 polytree)
    Executes the requested clipping operation and writes the nested closed-path result to a PolyTree64.
    final boolean
    execute(ClipType clipType, FillRule fillRule, PolyTree64 polytree, Paths64 openPaths)
    Executes the requested clipping operation and writes the nested closed-path result to a PolyTree64.
    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

    • 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 (via addSubject(), addOpenSubject() and addClip() 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 perform
      fillRule - the fill rule used during clipping
      solutionClosed - receives the closed solution paths
      solutionOpen - receives any open solution paths
      Returns:
      true when clipping completed successfully
    • execute

      public final boolean execute(ClipType clipType, FillRule fillRule, Paths64 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 the closed solution paths
      Returns:
      true when 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 a PolyTree64.
      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 final boolean execute(ClipType clipType, FillRule fillRule, PolyTree64 polytree)
      Executes the requested clipping operation and writes the nested closed-path result to a PolyTree64.
      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
    • 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:
      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
    • 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