Class OffsetSegmentGenerator
java.lang.Object
org.locationtech.jts.operation.buffer.OffsetSegmentGenerator
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 Summary
FieldsModifier and TypeFieldDescriptionprivate BufferParametersprivate intThe Closing Segment Length Factor controls how long "closing segments" are.private static final doubleFactor which controls how close curve vertices can be to be snappedprivate doubleprivate doubleThe angle quantum with which to approximate a fillet curve (based on the input # of quadrant segments)private booleanprivate static final doubleFactor which controls how close curve vertices on inside turns can be to be snappedprivate LineIntersectorprivate static final intFactor which determines how short closing segs can be for round buffersprivate doublethe max error of approximation (distance) between a quad segment and the true fillet curveprivate static final doubleFactor which controls how close offset segments can be to skip adding a filler or mitre.private LineSegmentprivate LineSegmentprivate PrecisionModelprivate Coordinateprivate Coordinateprivate Coordinateprivate LineSegmentprivate LineSegmentprivate OffsetSegmentStringprivate int -
Constructor Summary
ConstructorsConstructorDescriptionOffsetSegmentGenerator(PrecisionModel precisionModel, BufferParameters bufParams, double distance) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddBevelJoin(LineSegment offset0, LineSegment offset1) Adds a bevel join connecting the two offset segments around a reflex corner.private voidaddCollinear(boolean addStartPoint) private voidaddCornerFillet(Coordinate p, Coordinate p0, Coordinate p1, int direction, double radius) Add points for a circular fillet around a reflex corner.private voidaddDirectedFillet(Coordinate p, double startAngle, double endAngle, int direction, double radius) Adds points for a circular fillet arc between two specified angles.voidprivate voidaddInsideTurn(int orientation, boolean addStartPoint) Adds the offset points for an inside (concave) turn.voidAdd last offset pointprivate voidaddLimitedMitreJoin(LineSegment offset0, LineSegment offset1, double distance, double mitreLimit) Adds a limited mitre join connecting the two reflex offset segments.voidaddLineEndCap(Coordinate p0, Coordinate p1) Add an end cap around point p1, terminating a line segment coming from p0private voidaddMitreJoin(Coordinate p, LineSegment offset0, LineSegment offset1, double distance) Adds a mitre join connecting the two reflex offset segments.voidaddNextSegment(Coordinate p, boolean addStartPoint) private voidaddOutsideTurn(int orientation, boolean addStartPoint) Adds the offset points for an outside (convex) turnvoidaddSegments(Coordinate[] pt, boolean isForward) voidprivate voidcomputeOffsetSegment(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.voidCreates a CW circle around a pointvoidCreates a CW square around a pointbooleanTests whether the input has a narrow concave angle (relative to the offset distance).private voidinit(double distance) voidinitSideSegments(Coordinate s1, Coordinate s2, int side)
-
Field Details
-
OFFSET_SEGMENT_SEPARATION_FACTOR
private static final double OFFSET_SEGMENT_SEPARATION_FACTORFactor 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_FACTORFactor 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_FACTORFactor 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_FACTORFactor which determines how short closing segs can be for round buffers- See Also:
-
maxCurveSegmentError
private double maxCurveSegmentErrorthe max error of approximation (distance) between a quad segment and the true fillet curve -
filletAngleQuantum
private double filletAngleQuantumThe angle quantum with which to approximate a fillet curve (based on the input # of quadrant segments) -
closingSegLengthFactor
private int closingSegLengthFactorThe 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
-
distance
private double distance -
precisionModel
-
bufParams
-
li
-
s0
-
s1
-
s2
-
seg0
-
seg1
-
offset0
-
offset1
-
side
private int side -
hasNarrowConcaveAngle
private boolean hasNarrowConcaveAngle
-
-
Constructor Details
-
OffsetSegmentGenerator
public OffsetSegmentGenerator(PrecisionModel precisionModel, BufferParameters bufParams, double distance)
-
-
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
-
getCoordinates
-
closeRing
public void closeRing() -
addSegments
-
addFirstSegment
public void addFirstSegment() -
addLastSegment
public void addLastSegment()Add last offset point -
addNextSegment
-
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
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 offsetside- the side of the segment (Position) the offset lies ondistance- the offset distanceoffset- the points computed for the offset segment
-
addLineEndCap
Add an end cap around point p1, terminating a line segment coming from p0 -
addMitreJoin
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 segmentoffset1- the second offset segmentdistance- 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 segmentoffset1- the second offset segmentdistance- the offset distancemitreLimit- the mitre limit ratio
-
addBevelJoin
Adds a bevel join connecting the two offset segments around a reflex corner.- Parameters:
offset0- the first offset segmentoffset1- 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 curvep0- start point of fillet curvep1- endpoint of fillet curvedirection- the orientation of the filletradius- 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 angleradius- the radius of the fillet
-
createCircle
Creates a CW circle around a point -
createSquare
Creates a CW square around a point
-