addLineEndCap method
Add an end cap around point p1, terminating a line segment coming from p0
Implementation
void addLineEndCap(Coordinate p0, Coordinate p1) {
LineSegment seg = new LineSegment.fromCoordinates(p0, p1);
LineSegment offsetL = new LineSegment.empty();
computeOffsetSegment(seg, Position.LEFT, distance, offsetL);
LineSegment offsetR = new LineSegment.empty();
computeOffsetSegment(seg, Position.RIGHT, distance, offsetR);
double dx = p1.x - p0.x;
double dy = p1.y - p0.y;
double angle = math.atan2(dy, dx);
switch (bufParams.getEndCapStyle()) {
case BufferParameters.CAP_ROUND:
// add offset seg points with a fillet between them
segList.addPt(offsetL.p1);
addDirectedFillet(p1, angle + math.pi / 2, angle - math.pi / 2,
Orientation.CLOCKWISE, distance);
segList.addPt(offsetR.p1);
break;
case BufferParameters.CAP_FLAT:
// only offset segment points are added
segList.addPt(offsetL.p1);
segList.addPt(offsetR.p1);
break;
case BufferParameters.CAP_SQUARE:
// add a square defined by extensions of the offset segment endpoints
Coordinate squareCapSideOffset = new Coordinate.empty2D();
squareCapSideOffset.x = distance.abs() * math.cos(angle);
squareCapSideOffset.y = distance.abs() * math.sin(angle);
Coordinate squareCapLOffset = new Coordinate(
offsetL.p1.x + squareCapSideOffset.x,
offsetL.p1.y + squareCapSideOffset.y);
Coordinate squareCapROffset = new Coordinate(
offsetR.p1.x + squareCapSideOffset.x,
offsetR.p1.y + squareCapSideOffset.y);
segList.addPt(squareCapLOffset);
segList.addPt(squareCapROffset);
break;
}
}