Class OffsetSegmentGenerator

java.lang.Object
org.locationtech.jts.operation.buffer.OffsetSegmentGenerator

class OffsetSegmentGenerator extends Object
Generates segments which form an offset curve. Supports all end cap and join options provided for buffering. This algorithm implements various heuristics to produce smoother, simpler curves which are still within a reasonable tolerance of the true curve.
  • Field Details

    • OFFSET_SEGMENT_SEPARATION_FACTOR

      private static final double OFFSET_SEGMENT_SEPARATION_FACTOR
      Factor which controls how close offset segments can be to skip adding a filler or mitre.
      See Also:
    • INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR

      private static final double INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR
      Factor which controls how close curve vertices on inside turns can be to be snapped
      See Also:
    • CURVE_VERTEX_SNAP_DISTANCE_FACTOR

      private static final double CURVE_VERTEX_SNAP_DISTANCE_FACTOR
      Factor which controls how close curve vertices can be to be snapped
      See Also:
    • MAX_CLOSING_SEG_LEN_FACTOR

      private static final int MAX_CLOSING_SEG_LEN_FACTOR
      Factor which determines how short closing segs can be for round buffers
      See Also:
    • maxCurveSegmentError

      private double maxCurveSegmentError
      the max error of approximation (distance) between a quad segment and the true fillet curve
    • filletAngleQuantum

      private double filletAngleQuantum
      The angle quantum with which to approximate a fillet curve (based on the input # of quadrant segments)
    • closingSegLengthFactor

      private int closingSegLengthFactor
      The Closing Segment Length Factor controls how long "closing segments" are. Closing segments are added at the middle of inside corners to ensure a smoother boundary for the buffer offset curve. In some cases (particularly for round joins with default-or-better quantization) the closing segments can be made quite short. This substantially improves performance (due to fewer intersections being created). A closingSegFactor of 0 results in lines to the corner vertex A closingSegFactor of 1 results in lines halfway to the corner vertex A closingSegFactor of 80 results in lines 1/81 of the way to the corner vertex (this option is reasonable for the very common default situation of round joins and quadrantSegs >= 8)
    • segList

      private OffsetSegmentString segList
    • distance

      private double distance
    • precisionModel

      private PrecisionModel precisionModel
    • bufParams

      private BufferParameters bufParams
    • li

      private LineIntersector li
    • s0

      private Coordinate s0
    • s1

      private Coordinate s1
    • s2

      private Coordinate s2
    • seg0

      private LineSegment seg0
    • seg1

      private LineSegment seg1
    • offset0

      private LineSegment offset0
    • offset1

      private LineSegment offset1
    • side

      private int side
    • hasNarrowConcaveAngle

      private boolean hasNarrowConcaveAngle
  • Constructor Details

  • Method Details

    • hasNarrowConcaveAngle

      public boolean hasNarrowConcaveAngle()
      Tests whether the input has a narrow concave angle (relative to the offset distance). In this case the generated offset curve will contain self-intersections and heuristic closing segments. This is expected behaviour in the case of Buffer curves. For pure Offset Curves, the output needs to be further treated before it can be used.
      Returns:
      true if the input has a narrow concave angle
    • init

      private void init(double distance)
    • initSideSegments

      public void initSideSegments(Coordinate s1, Coordinate s2, int side)
    • getCoordinates

      public Coordinate[] getCoordinates()
    • closeRing

      public void closeRing()
    • addSegments

      public void addSegments(Coordinate[] pt, boolean isForward)
    • addFirstSegment

      public void addFirstSegment()
    • addLastSegment

      public void addLastSegment()
      Add last offset point
    • addNextSegment

      public void addNextSegment(Coordinate p, boolean addStartPoint)
    • addCollinear

      private void addCollinear(boolean addStartPoint)
    • addOutsideTurn

      private void addOutsideTurn(int orientation, boolean addStartPoint)
      Adds the offset points for an outside (convex) turn
      Parameters:
      orientation -
      addStartPoint -
    • addInsideTurn

      private void addInsideTurn(int orientation, boolean addStartPoint)
      Adds the offset points for an inside (concave) turn.
      Parameters:
      orientation -
      addStartPoint -
    • computeOffsetSegment

      private void computeOffsetSegment(LineSegment seg, int side, double distance, LineSegment offset)
      Compute an offset segment for an input segment on a given side and at a given distance. The offset points are computed in full double precision, for accuracy.
      Parameters:
      seg - the segment to offset
      side - the side of the segment (Position) the offset lies on
      distance - the offset distance
      offset - the points computed for the offset segment
    • addLineEndCap

      public void addLineEndCap(Coordinate p0, Coordinate p1)
      Add an end cap around point p1, terminating a line segment coming from p0
    • addMitreJoin

      private void addMitreJoin(Coordinate p, LineSegment offset0, LineSegment offset1, double distance)
      Adds a mitre join connecting the two reflex offset segments. The mitre will be beveled if it exceeds the mitre ratio limit.
      Parameters:
      offset0 - the first offset segment
      offset1 - the second offset segment
      distance - the offset distance
    • addLimitedMitreJoin

      private void addLimitedMitreJoin(LineSegment offset0, LineSegment offset1, double distance, double mitreLimit)
      Adds a limited mitre join connecting the two reflex offset segments. A limited mitre is a mitre which is beveled at the distance determined by the mitre ratio limit.
      Parameters:
      offset0 - the first offset segment
      offset1 - the second offset segment
      distance - the offset distance
      mitreLimit - the mitre limit ratio
    • addBevelJoin

      private void addBevelJoin(LineSegment offset0, LineSegment offset1)
      Adds a bevel join connecting the two offset segments around a reflex corner.
      Parameters:
      offset0 - the first offset segment
      offset1 - the second offset segment
    • addCornerFillet

      private void addCornerFillet(Coordinate p, Coordinate p0, Coordinate p1, int direction, double radius)
      Add points for a circular fillet around a reflex corner. Adds the start and end points
      Parameters:
      p - base point of curve
      p0 - start point of fillet curve
      p1 - endpoint of fillet curve
      direction - the orientation of the fillet
      radius - the radius of the fillet
    • addDirectedFillet

      private void addDirectedFillet(Coordinate p, double startAngle, double endAngle, int direction, double radius)
      Adds points for a circular fillet arc between two specified angles. The start and end point for the fillet are not added - the caller must add them if required.
      Parameters:
      direction - is -1 for a CW angle, 1 for a CCW angle
      radius - the radius of the fillet
    • createCircle

      public void createCircle(Coordinate p)
      Creates a CW circle around a point
    • createSquare

      public void createSquare(Coordinate p)
      Creates a CW square around a point