Class OffsetSegmentGenerator
- java.lang.Object
-
- org.locationtech.jts.operation.buffer.OffsetSegmentGenerator
-
class OffsetSegmentGenerator extends java.lang.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 Summary
Fields Modifier and Type Field Description private BufferParameters
bufParams
private int
closingSegLengthFactor
The Closing Segment Length Factor controls how long "closing segments" are.private static double
CURVE_VERTEX_SNAP_DISTANCE_FACTOR
Factor which controls how close curve vertices can be to be snappedprivate double
distance
private double
filletAngleQuantum
The angle quantum with which to approximate a fillet curve (based on the input # of quadrant segments)private boolean
hasNarrowConcaveAngle
private static double
INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR
Factor which controls how close curve vertices on inside turns can be to be snappedprivate LineIntersector
li
private static int
MAX_CLOSING_SEG_LEN_FACTOR
Factor which determines how short closing segs can be for round buffersprivate double
maxCurveSegmentError
the max error of approximation (distance) between a quad segment and the true fillet curveprivate static double
OFFSET_SEGMENT_SEPARATION_FACTOR
Factor which controls how close offset segments can be to skip adding a filler or mitre.private LineSegment
offset0
private LineSegment
offset1
private PrecisionModel
precisionModel
private Coordinate
s0
private Coordinate
s1
private Coordinate
s2
private LineSegment
seg0
private LineSegment
seg1
private OffsetSegmentString
segList
private int
side
-
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 void
addBevelJoin(LineSegment offset0, LineSegment offset1)
Adds a bevel join connecting the two offset segments around a reflex corner.private void
addCollinear(boolean addStartPoint)
private void
addCornerFillet(Coordinate p, Coordinate p0, Coordinate p1, int direction, double radius)
Add points for a circular fillet around a reflex corner.private void
addDirectedFillet(Coordinate p, double startAngle, double endAngle, int direction, double radius)
Adds points for a circular fillet arc between two specified angles.void
addFirstSegment()
private void
addInsideTurn(int orientation, boolean addStartPoint)
Adds the offset points for an inside (concave) turn.void
addLastSegment()
Add last offset pointprivate void
addLimitedMitreJoin(LineSegment offset0, LineSegment offset1, double distance, double mitreLimit)
Adds a limited mitre join connecting the two reflex offset segments.void
addLineEndCap(Coordinate p0, Coordinate p1)
Add an end cap around point p1, terminating a line segment coming from p0private void
addMitreJoin(Coordinate p, LineSegment offset0, LineSegment offset1, double distance)
Adds a mitre join connecting the two reflex offset segments.void
addNextSegment(Coordinate p, boolean addStartPoint)
private void
addOutsideTurn(int orientation, boolean addStartPoint)
Adds the offset points for an outside (convex) turnvoid
addSegments(Coordinate[] pt, boolean isForward)
void
closeRing()
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.void
createCircle(Coordinate p)
Creates a CW circle around a pointvoid
createSquare(Coordinate p)
Creates a CW square around a pointCoordinate[]
getCoordinates()
boolean
hasNarrowConcaveAngle()
Tests whether the input has a narrow concave angle (relative to the offset distance).private void
init(double distance)
void
initSideSegments(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
-
-