Class OffsetSegmentGenerator
- java.lang.Object
-
- org.locationtech.jts.operation.buffer.OffsetSegmentGenerator
-
class OffsetSegmentGenerator extends java.lang.ObjectGenerates 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
Fields Modifier and Type Field Description private BufferParametersbufParamsprivate intclosingSegLengthFactorThe Closing Segment Length Factor controls how long "closing segments" are.private static doubleCURVE_VERTEX_SNAP_DISTANCE_FACTORFactor which controls how close curve vertices can be to be snappedprivate doubledistanceprivate doublefilletAngleQuantumThe angle quantum with which to approximate a fillet curve (based on the input # of quadrant segments)private booleanhasNarrowConcaveAngleprivate static doubleINSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTORFactor which controls how close curve vertices on inside turns can be to be snappedprivate LineIntersectorliprivate static intMAX_CLOSING_SEG_LEN_FACTORFactor which determines how short closing segs can be for round buffersprivate doublemaxCurveSegmentErrorthe max error of approximation (distance) between a quad segment and the true fillet curveprivate static doubleOFFSET_SEGMENT_SEPARATION_FACTORFactor which controls how close offset segments can be to skip adding a filler or mitre.private LineSegmentoffset0private LineSegmentoffset1private PrecisionModelprecisionModelprivate Coordinates0private Coordinates1private Coordinates2private LineSegmentseg0private LineSegmentseg1private OffsetSegmentStringsegListprivate intside
-
Constructor Summary
Constructors Constructor Description OffsetSegmentGenerator(PrecisionModel precisionModel, BufferParameters bufParams, double distance)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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.voidaddFirstSegment()private voidaddInsideTurn(int orientation, boolean addStartPoint)Adds the offset points for an inside (concave) turn.voidaddLastSegment()Add 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)voidcloseRing()private 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.voidcreateCircle(Coordinate p)Creates a CW circle around a pointvoidcreateSquare(Coordinate p)Creates a CW square around a pointCoordinate[]getCoordinates()booleanhasNarrowConcaveAngle()Tests 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 Detail
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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 Detail
-
OffsetSegmentGenerator
public OffsetSegmentGenerator(PrecisionModel precisionModel, BufferParameters bufParams, double distance)
-
-
Method Detail
-
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 offsetside- the side of the segment (Position) the offset lies ondistance- the offset distanceoffset- 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 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
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 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
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
-
-