Class Clipper

java.lang.Object
com.github.micycle1.clipper2.Clipper

public final class Clipper extends Object
Line and polygon clipping, and offsetting.

This unit has been designed to hide the library's complexities behind a number of simple functions. However, not all of the library's features are accessible here. Less commonly needed features that provide more flexibility can still be accessed from the other units.

Boolean operations for polygon clipping:

  • AND (intersection) - regions covered by both subject and clip polygons
  • OR (union) - regions covered by subject or clip polygons, or both polygons
  • NOT (difference) - regions covered by subject, but not clip polygons
  • XOR (exclusive or) - regions covered by subject or clip polygons, but not both
Of these four operations, only difference is non-commutative. This means that subject and clip paths are interchangeable except when performing difference operations (and as long as subject paths are closed).

All polygon clipping is performed with a Clipper object with the specific boolean operation indicated by the ClipType parameter passed in its Execute method. With regard to open paths (polylines), clipping rules generally match those of closed paths (polygons). However, when there are both polyline and polygon subjects, the following clipping rules apply:

  • union operations - polylines will be clipped by any overlapping polygons so that only non-overlapped portions will be returned in the solution, together with solution polygons
  • intersection, difference and xor operations - polylines will be clipped by 'clip' polygons, and there will be no interaction between polylines and any subject polygons

Polygon Offsetting:

Geometric offsetting refers to the process of creating parallel curves that are offset a specified distance from their starting positions.

While all offsetting is performed by the ClipperOffset class in the Clipper.Offset unit, the complexities of constructing and using this class can usually be avoided by using instead the inflatePaths() function in this class. This function can both inflate and shrink polygons (using positive and negative offsets respectively). Offsetting can be performed using a number of JoinTypes and EndTypes. While both open paths and closed paths can be offset, logically only closed paths can be shrunk (ie with negative offsets).

Note: Offsetting shouldn't be confused with the process of polygon translation.

  • Field Details

    • InvalidRect64

      public static final Rect64 InvalidRect64
      Sentinel invalid Rect64 used while computing integer bounds.
    • InvalidRectD

      public static final RectD InvalidRectD
      Sentinel invalid RectD used while computing floating-point bounds.
  • Constructor Details

    • Clipper

      public Clipper()
  • Method Details

    • intersect

      public static Paths64 intersect(Paths64 subject, Paths64 clip, FillRule fillRule)
      Intersects two sets of integer paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the intersected paths.
    • intersect

      public static PathsD intersect(PathsD subject, PathsD clip, FillRule fillRule)
      Intersects two sets of floating-point paths using the default precision.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the intersected paths.
    • intersect

      public static PathsD intersect(PathsD subject, PathsD clip, FillRule fillRule, int precision)
      Intersects two sets of floating-point paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      precision - the decimal precision to use when scaling coordinates.
      Returns:
      the intersected paths.
    • union

      public static Paths64 union(Paths64 subject, FillRule fillRule)
      Unites the supplied integer subject paths.
      Parameters:
      subject - the subject paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the unioned paths.
    • union

      public static Paths64 union(Paths64 subject, Paths64 clip, FillRule fillRule)
      Unites two sets of integer paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the unioned paths.
    • union

      public static PathsD union(PathsD subject, FillRule fillRule)
      Unites the supplied floating-point subject paths using the default precision.
      Parameters:
      subject - the subject paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the unioned paths.
    • union

      public static PathsD union(PathsD subject, PathsD clip, FillRule fillRule)
      Unites two sets of floating-point paths using the default precision.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the unioned paths.
    • union

      public static PathsD union(PathsD subject, PathsD clip, FillRule fillRule, int precision)
      Unites two sets of floating-point paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      precision - the decimal precision to use when scaling coordinates.
      Returns:
      the unioned paths.
    • difference

      public static Paths64 difference(Paths64 subject, Paths64 clip, FillRule fillRule)
      Subtracts the clip paths from the subject paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the difference of the subject and clip paths.
    • difference

      public static PathsD difference(PathsD subject, PathsD clip, FillRule fillRule)
      Subtracts the clip paths from the subject paths using the default precision.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the difference of the subject and clip paths.
    • difference

      public static PathsD difference(PathsD subject, PathsD clip, FillRule fillRule, int precision)
      Subtracts the clip paths from the subject paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      precision - the decimal precision to use when scaling coordinates.
      Returns:
      the difference of the subject and clip paths.
    • xor

      public static Paths64 xor(Paths64 subject, Paths64 clip, FillRule fillRule)
      Computes the exclusive-or of two sets of integer paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the exclusive-or of the subject and clip paths.
    • xor

      public static PathsD xor(PathsD subject, PathsD clip, FillRule fillRule)
      Computes the exclusive-or of two sets of floating-point paths using the default precision.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the exclusive-or of the subject and clip paths.
    • xor

      public static PathsD xor(PathsD subject, PathsD clip, FillRule fillRule, int precision)
      Computes the exclusive-or of two sets of floating-point paths.
      Parameters:
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      precision - the decimal precision to use when scaling coordinates.
      Returns:
      the exclusive-or of the subject and clip paths.
    • booleanOp

      public static Paths64 booleanOp(ClipType clipType, Paths64 subject, Paths64 clip, FillRule fillRule)
      Applies the requested boolean operation to integer subject and clip paths.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the resulting paths.
    • booleanOp

      public static void booleanOp(ClipType clipType, @Nullable @Nullable Paths64 subject, @Nullable @Nullable Paths64 clip, PolyTree64 polytree, FillRule fillRule)
      This function is a generic alternative to the Intersect, Difference, Union and XOR functions.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths, or null.
      polytree - the destination polytree that receives the result.
      fillRule - the polygon fill rule to apply.
    • booleanOp

      public static PathsD booleanOp(ClipType clipType, PathsD subject, PathsD clip, FillRule fillRule)
      Applies the requested boolean operation to floating-point subject and clip paths using the default precision.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths.
      fillRule - the polygon fill rule to apply.
      Returns:
      the resulting paths.
    • booleanOp

      public static PathsD booleanOp(ClipType clipType, PathsD subject, @Nullable @Nullable PathsD clip, FillRule fillRule, int precision)
      This function is a generic alternative to the Intersect, Difference, Union and XOR functions.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths, or null.
      fillRule - the polygon fill rule to apply.
      precision - The desired coordinate precision (up to 8 decimal places).
      Returns:
      the resulting paths.
    • booleanOp

      public static void booleanOp(ClipType clipType, @Nullable @Nullable PathsD subject, @Nullable @Nullable PathsD clip, PolyTreeD polytree, FillRule fillRule)
      Applies the requested boolean operation to floating-point paths and stores the result in a PolyTreeD using the default precision.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths, or null.
      polytree - the destination polytree that receives the result.
      fillRule - the polygon fill rule to apply.
    • booleanOp

      public static void booleanOp(ClipType clipType, @Nullable @Nullable PathsD subject, @Nullable @Nullable PathsD clip, PolyTreeD polytree, FillRule fillRule, int precision)
      Applies the requested boolean operation to floating-point paths and stores the result in a PolyTreeD.
      Parameters:
      clipType - the boolean operation to perform.
      subject - the subject paths.
      clip - the clip paths, or null.
      polytree - the destination polytree that receives the result.
      fillRule - the polygon fill rule to apply.
      precision - the decimal precision to use when scaling coordinates.
    • inflatePaths

      public static Paths64 inflatePaths(Paths64 paths, double delta, JoinType joinType, EndType endType)
      Inflates or shrinks integer paths with default miter and arc settings.
      Parameters:
      paths - the paths to offset.
      delta - the offset distance.
      joinType - the join type to apply at vertices.
      endType - the end treatment to apply.
      Returns:
      the offset paths.
      See Also:
    • inflatePaths

      public static Paths64 inflatePaths(Paths64 paths, double delta, JoinType joinType, EndType endType, double miterLimit, double arcTolerance)
      Inflates or shrinks integer paths.
      Parameters:
      paths - the paths to offset.
      delta - the offset distance.
      joinType - the join type to apply at vertices.
      endType - the end treatment to apply.
      miterLimit - the miter limit in multiples of delta.
      arcTolerance - the tolerance used when flattening round joins.
      Returns:
      the offset paths.
      See Also:
    • inflatePaths

      public static PathsD inflatePaths(PathsD paths, double delta, JoinType joinType, EndType endType, double miterLimit)
      Inflates or shrinks floating-point paths with a custom miter limit.
      Parameters:
      paths - the paths to offset.
      delta - the offset distance.
      joinType - the join type to apply at vertices.
      endType - the end treatment to apply.
      miterLimit - the miter limit in multiples of delta.
      Returns:
      the offset paths.
      See Also:
    • inflatePaths

      public static PathsD inflatePaths(PathsD paths, double delta, JoinType joinType, EndType endType)
      Inflates or shrinks floating-point paths with default settings.
      Parameters:
      paths - the paths to offset.
      delta - the offset distance.
      joinType - the join type to apply at vertices.
      endType - the end treatment to apply.
      Returns:
      the offset paths.
      See Also:
    • inflatePaths

      public static PathsD inflatePaths(PathsD paths, double delta, JoinType joinType, EndType endType, double miterLimit, double arcTolerance, int precision)
      These functions encapsulate ClipperOffset, the class that performs both polygon and open path offsetting.

      When using this function to inflate polygons (ie closed paths), it's important that you select EndType.Polygon. If instead you select one of the open path end types (including EndType.Joined), you'll inflate the polygon's outline.

      With closed paths (polygons), a positive delta specifies how much outer polygon contours will expand and how much inner "hole" contours will contract (and the converse with negative deltas).

      With open paths (polylines), including EndType.Joined, delta specifies the width of the inflated line.

      Caution: Offsetting self-intersecting polygons may produce unexpected results.

      Parameters:
      paths - A Paths object that is to undergo offsetting.
      delta - With closed paths (polygons), a positive delta specifies how much outer polygon contours will expand and how much inner "hole" contours will contract (and the converse with negative deltas).

      With open paths (polylines), including EndType.Join, delta specifies the width of the inflated line.

      joinType - see JoinType
      endType - see EndType
      miterLimit - Sets the maximum distance in multiples of delta that vertices can be offset from their original positions before squaring is applied. (Squaring truncates a miter by 'cutting it off' at 1 × delta distance from the original vertex.)

      The default value for MiterLimit is 2 (ie twice delta). This is also the smallest MiterLimit that's allowed. If mitering was unrestricted (ie without any squaring), then offsets at very acute angles would generate unacceptably long 'spikes'.

      arcTolerance - Sets the distance the flattened path will deviate from the 'true' arc (only relevant when offsetting with JoinType.Round and/or EndType.Round).
      precision - The number of decimal places of precision to consider when paths is type PathsD. (Maximum is 8 decimal places)
      Returns:
      the offset paths.
    • rectClip

      public static Paths64 rectClip(Rect64 rect, Paths64 paths)
    • rectClip

      public static Paths64 rectClip(Rect64 rect, Path64 path)
    • rectClip

      public static PathsD rectClip(RectD rect, PathsD paths)
    • rectClip

      public static PathsD rectClip(RectD rect, PathsD paths, int precision)
    • rectClip

      public static PathsD rectClip(RectD rect, PathD path)
    • rectClip

      public static PathsD rectClip(RectD rect, PathD path, int precision)
    • rectClipLines

      public static Paths64 rectClipLines(Rect64 rect, Paths64 paths)
    • rectClipLines

      public static Paths64 rectClipLines(Rect64 rect, Path64 path)
    • rectClipLines

      public static PathsD rectClipLines(RectD rect, PathsD paths)
    • rectClipLines

      public static PathsD rectClipLines(RectD rect, PathsD paths, int precision)
    • rectClipLines

      public static PathsD rectClipLines(RectD rect, PathD path)
    • rectClipLines

      public static PathsD rectClipLines(RectD rect, PathD path, int precision)
    • minkowskiSum

      public static Paths64 minkowskiSum(Path64 pattern, Path64 path, boolean isClosed)
    • minkowskiSum

      public static PathsD minkowskiSum(PathD pattern, PathD path, boolean isClosed)
    • minkowskiDiff

      public static Paths64 minkowskiDiff(Path64 pattern, Path64 path, boolean isClosed)
    • minkowskiDiff

      public static PathsD minkowskiDiff(PathD pattern, PathD path, boolean isClosed)
    • area

      public static double area(Path64 path)
      Returns the area of the supplied polygon. It's assumed that the path is closed and does not self-intersect. Depending on the path's winding orientation, this value may be positive or negative. If the winding is clockwise, then the area will be positive and conversely, if winding is counter-clockwise, then the area will be negative.
      Parameters:
      path - the path whose area will be calculated.
      Returns:
      the signed area of the path.
    • area

      public static double area(Paths64 paths)
      Returns the area of the supplied polygon. It's assumed that the path is closed and does not self-intersect. Depending on the path's winding orientation, this value may be positive or negative. If the winding is clockwise, then the area will be positive and conversely, if winding is counter-clockwise, then the area will be negative.
      Parameters:
      paths - the paths whose total area will be calculated.
      Returns:
      the sum of the signed areas of all supplied paths.
    • area

      public static double area(PathD path)
      Returns the signed area of the supplied floating-point polygon.
      Parameters:
      path - the path whose area will be calculated.
      Returns:
      the signed area of the path.
    • area

      public static double area(PathsD paths)
      Returns the combined signed area of the supplied floating-point polygons.
      Parameters:
      paths - the paths whose total area will be calculated.
      Returns:
      the sum of the signed areas of all supplied paths.
    • isPositive

      public static boolean isPositive(Path64 poly)
      This function assesses the winding orientation of closed paths.

      Positive winding paths will be oriented in an anti-clockwise direction in Cartesian coordinates (where coordinate values increase when heading rightward and upward). Nevertheless it's common for graphics libraries to use inverted Y-axes (where Y values decrease heading upward). In these libraries, paths with Positive winding will be oriented clockwise.

      Note: Self-intersecting polygons have indeterminate orientation since some path segments will commonly wind in opposite directions to other segments.

      Parameters:
      poly - the polygon to test.
      Returns:
      true when the polygon has positive winding.
    • isPositive

      public static boolean isPositive(PathD poly)
      This function assesses the winding orientation of closed paths.

      Positive winding paths will be oriented in an anti-clockwise direction in Cartesian coordinates (where coordinate values increase when heading rightward and upward). Nevertheless it's common for graphics libraries to use inverted Y-axes (where Y values decrease heading upward). In these libraries, paths with Positive winding will be oriented clockwise.

      Note: Self-intersecting polygons have indeterminate orientation since some path segments will commonly wind in opposite directions to other segments.

      Parameters:
      poly - the polygon to test.
      Returns:
      true when the polygon has positive winding.
    • path64ToString

      public static String path64ToString(Path64 path)
    • paths64ToString

      public static String paths64ToString(Paths64 paths)
    • pathDToString

      public static String pathDToString(PathD path)
    • pathsDToString

      public static String pathsDToString(PathsD paths)
    • offsetPath

      public static Path64 offsetPath(Path64 path, long dx, long dy)
    • scalePoint64

      public static Point64 scalePoint64(Point64 pt, double scale)
    • scalePointD

      public static PointD scalePointD(Point64 pt, double scale)
    • scaleRect

      public static Rect64 scaleRect(RectD rec, double scale)
    • scalePath

      public static Path64 scalePath(Path64 path, double scale)
    • scalePaths

      public static Paths64 scalePaths(Paths64 paths, double scale)
    • scalePath

      public static PathD scalePath(PathD path, double scale)
    • scalePaths

      public static PathsD scalePaths(PathsD paths, double scale)
    • scalePath64

      public static Path64 scalePath64(PathD path, double scale)
    • scalePaths64

      public static Paths64 scalePaths64(PathsD paths, double scale)
    • scalePathD

      public static PathD scalePathD(Path64 path, double scale)
    • scalePathsD

      public static PathsD scalePathsD(Paths64 paths, double scale)
    • path64

      public static Path64 path64(PathD path)
    • paths64

      public static Paths64 paths64(PathsD paths)
    • pathsD

      public static PathsD pathsD(Paths64 paths)
    • pathD

      public static PathD pathD(Path64 path)
    • translatePath

      public static Path64 translatePath(Path64 path, long dx, long dy)
    • translatePaths

      public static Paths64 translatePaths(Paths64 paths, long dx, long dy)
    • translatePath

      public static PathD translatePath(PathD path, double dx, double dy)
    • translatePaths

      public static PathsD translatePaths(PathsD paths, double dx, double dy)
    • reversePath

      public static Path64 reversePath(Path64 path)
    • reversePath

      public static PathD reversePath(PathD path)
    • reversePaths

      public static Paths64 reversePaths(Paths64 paths)
    • reversePaths

      public static PathsD reversePaths(PathsD paths)
    • getBounds

      public static Rect64 getBounds(Path64 path)
      Returns the bounds of an integer path.
      Parameters:
      path - the path to measure.
      Returns:
      the path bounds, or an empty rectangle when the path is empty.
    • getBounds

      public static Rect64 getBounds(Paths64 paths)
      Returns the bounds of multiple integer paths.
      Parameters:
      paths - the paths to measure.
      Returns:
      the combined bounds, or an empty rectangle when no points are supplied.
    • getBounds

      public static RectD getBounds(PathD path)
      Returns the bounds of a floating-point path.
      Parameters:
      path - the path to measure.
      Returns:
      the path bounds, or an empty rectangle when the path is empty.
    • getBounds

      public static RectD getBounds(PathsD paths)
      Returns the bounds of multiple floating-point paths.
      Parameters:
      paths - the paths to measure.
      Returns:
      the combined bounds, or an empty rectangle when no points are supplied.
    • makePath

      public static Path64 makePath(int[] arr)
      Creates an integer path from alternating x,y coordinate pairs.
      Parameters:
      arr - the coordinate array.
      Returns:
      the constructed path.
    • makePath

      public static Path64 makePath(long[] arr)
    • makePath

      public static PathD makePath(double[] arr)
      Creates a floating-point path from alternating x,y coordinate pairs.
      Parameters:
      arr - the coordinate array.
      Returns:
      the constructed path.
    • sqr

      public static double sqr(double value)
    • sqr

      public static double sqr(long value)
    • distanceSqr

      public static double distanceSqr(Point64 pt1, Point64 pt2)
      Returns the squared distance between two integer points.
      Parameters:
      pt1 - the first point.
      pt2 - the second point.
      Returns:
      the squared Euclidean distance between the two points.
    • midPoint

      public static Point64 midPoint(Point64 pt1, Point64 pt2)
    • midPoint

      public static PointD midPoint(PointD pt1, PointD pt2)
    • inflateRect

      public static void inflateRect(Rect64 rec, int dx, int dy)
      Expands or contracts an integer rectangle in place.
      Parameters:
      rec - the rectangle to modify.
      dx - the horizontal delta to apply on both sides.
      dy - the vertical delta to apply on both sides.
    • inflateRect

      public static void inflateRect(RectD rec, double dx, double dy)
      Expands or contracts a floating-point rectangle in place.
      Parameters:
      rec - the rectangle to modify.
      dx - the horizontal delta to apply on both sides.
      dy - the vertical delta to apply on both sides.
    • pointsNearEqual

      public static boolean pointsNearEqual(PointD pt1, PointD pt2, double distanceSqrd)
    • stripNearDuplicates

      public static PathD stripNearDuplicates(PathD path, double minEdgeLenSqrd, boolean isClosedPath)
    • stripDuplicates

      public static Path64 stripDuplicates(Path64 path, boolean isClosedPath)
    • polyTreeToPaths64

      public static Paths64 polyTreeToPaths64(PolyTree64 polyTree)
    • addPolyNodeToPathsD

      public static void addPolyNodeToPathsD(PolyPathD polyPath, PathsD paths)
      Flattens a floating-point polytree into a path collection.
      Parameters:
      polyPath - the current polytree node.
      paths - the destination path collection.
    • polyTreeToPathsD

      public static PathsD polyTreeToPathsD(PolyTreeD polyTree)
    • perpendicDistFromLineSqrd

      public static double perpendicDistFromLineSqrd(PointD pt, PointD line1, PointD line2)
    • perpendicDistFromLineSqrd

      public static double perpendicDistFromLineSqrd(Point64 pt, Point64 line1, Point64 line2)
    • rDP

      public static void rDP(Path64 path, int begin, int end, double epsSqrd, List<Boolean> flags)
    • ramerDouglasPeuckerPath

      public static Path64 ramerDouglasPeuckerPath(Path64 path, double epsilon)
      The Ramer-Douglas-Peucker algorithm is very useful in removing path segments that don't contribute meaningfully to the path's shape. The algorithm's aggressiveness is determined by the epsilon parameter, with larger values removing more vertices. (Somewhat simplistically, the algorithm removes vertices that are less than epsilon distance from imaginary lines passing through their adjacent vertices.)

      This function can be particularly useful when offsetting paths (ie inflating/shrinking) where the offsetting process often creates tiny segments. These segments don't enhance curve quality, but they will slow path processing (whether during file storage, or when rendering, or in subsequent offsetting procedures).

      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      Returns:
      the simplified path.
    • ramerDouglasPeucker

      public static Paths64 ramerDouglasPeucker(Paths64 paths, double epsilon)
      The Ramer-Douglas-Peucker algorithm is very useful in removing path segments that don't contribute meaningfully to the path's shape. The algorithm's aggressiveness is determined by the epsilon parameter, with larger values removing more vertices. (Somewhat simplistically, the algorithm removes vertices that are less than epsilon distance from imaginary lines passing through their adjacent vertices.)

      This function can be particularly useful when offsetting paths (ie inflating/shrinking) where the offsetting process often creates tiny segments. These segments don't enhance curve quality, but they will slow path processing (whether during file storage, or when rendering, or in subsequent offsetting procedures).

      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      Returns:
      the simplified paths.
    • rDP

      public static void rDP(PathD path, int begin, int end, double epsSqrd, List<Boolean> flags)
    • ramerDouglasPeucker

      public static PathD ramerDouglasPeucker(PathD path, double epsilon)
      Simplifies a floating-point path using the Ramer-Douglas-Peucker algorithm.
      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      Returns:
      the simplified path.
    • ramerDouglasPeucker

      public static PathsD ramerDouglasPeucker(PathsD paths, double epsilon)
      Simplifies floating-point paths using the Ramer-Douglas-Peucker algorithm.
      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      Returns:
      the simplified paths.
    • simplifyPath

      public static Path64 simplifyPath(Path64 path, double epsilon)
      Simplifies a path assuming an open path by default.
      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      Returns:
      the simplified path.
    • simplifyPath

      public static Path64 simplifyPath(Path64 path, double epsilon, boolean isClosedPath)
      Removes vertices that are less than the specified epsilon distance from an imaginary line that passes through its 2 adjacent vertices. Logically, smaller epsilon values will be less aggressive in removing vertices than larger epsilon values.

      This function is strongly recommended before offsetting (ie before inflating/shrinking) when paths may contain redundant segments. And removing redundant segments is especially important when offsetting paths that have themselves been offset.

      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      isClosedPath - whether the path should be treated as closed.
      Returns:
      the simplified path.
    • simplifyPaths

      public static Paths64 simplifyPaths(Paths64 paths, double epsilon)
      Simplifies multiple integer paths assuming open paths by default.
      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      Returns:
      the simplified paths.
    • simplifyPaths

      public static Paths64 simplifyPaths(Paths64 paths, double epsilon, boolean isClosedPath)
      Simplifies multiple integer paths.
      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      isClosedPath - whether the paths should be treated as closed.
      Returns:
      the simplified paths.
    • simplifyPath

      public static PathD simplifyPath(PathD path, double epsilon)
      Simplifies a floating-point path assuming an open path by default.
      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      Returns:
      the simplified path.
    • simplifyPath

      public static PathD simplifyPath(PathD path, double epsilon, boolean isClosedPath)
      Removes vertices that are less than the specified epsilon distance from an imaginary line that passes through its 2 adjacent vertices. Logically, smaller epsilon values will be less aggressive in removing vertices than larger epsilon values.

      This function is strongly recommended before offsetting (ie before inflating/shrinking) when paths may contain redundant segments. And removing redundant segments is especially important when offsetting paths that have themselves been offset.

      Parameters:
      path - the path to simplify.
      epsilon - the maximum permitted deviation from the original path.
      isClosedPath - whether the path should be treated as closed.
      Returns:
      the simplified path.
    • simplifyPaths

      public static PathsD simplifyPaths(PathsD paths, double epsilon)
      Simplifies multiple floating-point paths assuming open paths by default.
      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      Returns:
      the simplified paths.
    • simplifyPaths

      public static PathsD simplifyPaths(PathsD paths, double epsilon, boolean isClosedPath)
      Simplifies multiple floating-point paths.
      Parameters:
      paths - the paths to simplify.
      epsilon - the maximum permitted deviation from the original paths.
      isClosedPath - whether the paths should be treated as closed.
      Returns:
      the simplified paths.
    • trimCollinear

      public static Path64 trimCollinear(Path64 path)
      This function removes the vertices between adjacent collinear segments. It will also remove duplicate vertices (adjacent vertices with identical coordinates).

      Note: Duplicate vertices will be removed automatically from clipping solutions, but not collinear edges unless the Clipper object's PreserveCollinear property had been disabled.

      Parameters:
      path - the path to trim.
      Returns:
      the trimmed path.
    • trimCollinear

      public static Path64 trimCollinear(Path64 path, boolean isOpen)
      This function removes the vertices between adjacent collinear segments. It will also remove duplicate vertices (adjacent vertices with identical coordinates).

      Note: Duplicate vertices will be removed automatically from clipping solutions, but not collinear edges unless the Clipper object's PreserveCollinear property had been disabled.

      Parameters:
      path - the path to trim.
      isOpen - whether the path should be treated as open.
      Returns:
      the trimmed path.
    • trimCollinear

      public static PathD trimCollinear(PathD path, int precision)
      This function removes the vertices between adjacent collinear segments. It will also remove duplicate vertices (adjacent vertices with identical coordinates).

      With floating point paths, the precision parameter indicates the decimal precision that's required when determining collinearity.

      Note: Duplicate vertices will be removed automatically from clipping solutions, but not collinear edges unless the Clipper object's PreserveCollinear property had been disabled.

      Parameters:
      path - the path to trim.
      precision - the decimal precision used to test collinearity.
      Returns:
      the trimmed path.
    • trimCollinear

      public static PathD trimCollinear(PathD path, int precision, boolean isOpen)
      This function removes the vertices between adjacent collinear segments. It will also remove duplicate vertices (adjacent vertices with identical coordinates).

      With floating point paths, the precision parameter indicates the decimal precision that's required when determining collinearity.

      Note: Duplicate vertices will be removed automatically from clipping solutions, but not collinear edges unless the Clipper object's PreserveCollinear property had been disabled.

      Parameters:
      path - the path to trim.
      precision - the decimal precision used to test collinearity.
      isOpen - whether the path should be treated as open.
      Returns:
      the trimmed path.
    • pointInPolygon

      public static PointInPolygonResult pointInPolygon(Point64 pt, Path64 polygon)
    • pointInPolygon

      public static PointInPolygonResult pointInPolygon(PointD pt, PathD polygon)
    • pointInPolygon

      public static PointInPolygonResult pointInPolygon(PointD pt, PathD polygon, int precision)
    • ellipse

      public static Path64 ellipse(Point64 center, double radiusX, double radiusY)
      Approximates an integer ellipse using an automatically chosen step count.
      Parameters:
      center - the ellipse center.
      radiusX - the horizontal radius.
      radiusY - the vertical radius.
      Returns:
      the approximated ellipse path.
    • ellipse

      public static Path64 ellipse(Point64 center, double radiusX)
      Approximates an integer circle using an automatically chosen step count.
      Parameters:
      center - the circle center.
      radiusX - the radius to use on both axes.
      Returns:
      the approximated circle path.
    • ellipse

      public static Path64 ellipse(Point64 center, double radiusX, double radiusY, int steps)
      Approximates an integer ellipse.
      Parameters:
      center - the ellipse center.
      radiusX - the horizontal radius.
      radiusY - the vertical radius.
      steps - the number of vertices to generate, or 0 to choose automatically.
      Returns:
      the approximated ellipse path.
    • ellipse

      public static PathD ellipse(PointD center, double radiusX, double radiusY)
      Approximates a floating-point ellipse using an automatically chosen step count.
      Parameters:
      center - the ellipse center.
      radiusX - the horizontal radius.
      radiusY - the vertical radius.
      Returns:
      the approximated ellipse path.
    • ellipse

      public static PathD ellipse(PointD center, double radiusX)
      Approximates a floating-point circle using an automatically chosen step count.
      Parameters:
      center - the circle center.
      radiusX - the radius to use on both axes.
      Returns:
      the approximated circle path.
    • ellipse

      public static PathD ellipse(PointD center, double radiusX, double radiusY, int steps)
      Approximates a floating-point ellipse.
      Parameters:
      center - the ellipse center.
      radiusX - the horizontal radius.
      radiusY - the vertical radius.
      steps - the number of vertices to generate, or 0 to choose automatically.
      Returns:
      the approximated ellipse path.