use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class TaggedLineStringSimplifier method simplifySection.
private void simplifySection(final int i, final int j, int depth) {
depth += 1;
final int[] sectionIndex = new int[2];
if (i + 1 == j) {
final LineSegment newSeg = this.taggedLine.getSegment(i);
this.taggedLine.addToResult(newSeg);
// leave this segment in the input index, for efficiency
return;
}
boolean isValidToSimplify = true;
/**
* Following logic ensures that there is enough points in the output taggedLine.
* If there is already more points than the minimum, there's nothing to check.
* Otherwise, if in the worst case there wouldn't be enough points,
* don't flatten this segment (which avoids the worst case scenario)
*/
if (this.taggedLine.getResultSize() < this.taggedLine.getMinimumSize()) {
final int worstCaseSize = depth + 1;
if (worstCaseSize < this.taggedLine.getMinimumSize()) {
isValidToSimplify = false;
}
}
final double[] distance = new double[1];
final int furthestPtIndex = findFurthestPoint(i, j, distance);
// flattening must be less than distanceTolerance
if (distance[0] > this.distanceTolerance) {
isValidToSimplify = false;
}
// test if flattened section would cause intersection
// final LineSegment candidateSeg = new LineSegmentDouble();
final Point p0 = this.line.getVertex(i);
final Point p1 = this.line.getVertex(j);
final LineSegment candidateSeg = new LineSegmentDouble(p0, p1);
sectionIndex[0] = i;
sectionIndex[1] = j;
if (hasBadIntersection(this.taggedLine, sectionIndex, candidateSeg)) {
isValidToSimplify = false;
}
if (isValidToSimplify) {
final LineSegment newSeg = flatten(i, j);
this.taggedLine.addToResult(newSeg);
return;
}
simplifySection(i, furthestPtIndex, depth);
simplifySection(furthestPtIndex, j, depth);
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class OffsetSegmentGenerator method addLineEndCap.
/**
* Add an end cap around point p1, terminating a line segment coming from p0
*/
public void addLineEndCap(final double x1, final double y1, final double x2, final double y2) {
final LineSegment offsetL = newOffsetSegment(x1, y1, x2, y2, Position.LEFT, this.distance);
final LineSegment offsetR = newOffsetSegment(x1, y1, x2, y2, Position.RIGHT, this.distance);
final double dx = x2 - x1;
final double dy = y2 - y1;
final double angle = Math.atan2(dy, dx);
final double leftX2 = offsetL.getX(1);
final double leftY2 = offsetL.getY(1);
final double rightX2 = offsetR.getX(1);
final double rightY2 = offsetR.getY(1);
switch(this.bufParams.getEndCapStyle()) {
case ROUND:
// add offset seg points with a fillet between them
this.segList.addPoint(leftX2, leftY2);
addFillet(x2, y2, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this.distance);
this.segList.addPoint(rightX2, rightY2);
break;
case BUTT:
// only offset segment points are added
this.segList.addPoint(leftX2, leftY2);
this.segList.addPoint(rightX2, rightY2);
break;
case SQUARE:
final double absDistance = Math.abs(this.distance);
// add a square defined by extensions of the offset segment endpoints
final double squareCapSideOffsetX = absDistance * Math.cos(angle);
final double squareCapSideOffsetY = absDistance * Math.sin(angle);
final double lx = leftX2 + squareCapSideOffsetX;
final double ly = leftY2 + squareCapSideOffsetY;
this.segList.addPoint(lx, ly);
final double rx = rightX2 + squareCapSideOffsetX;
final double ry = rightY2 + squareCapSideOffsetY;
this.segList.addPoint(rx, ry);
break;
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class KochSnowflakeBuilder method getGeometry.
@Override
public Geometry getGeometry() {
final int level = recursionLevelForSize(this.numPts);
final LineSegment baseLine = getSquareBaseLine();
final Point[] pts = getBoundary(level, baseLine.getPoint(0), baseLine.getLength());
return this.geometryFactory.polygon(this.geometryFactory.linearRing(pts));
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class RandomOffsetLineStringGenerator method computeRandomOffset.
private Point computeRandomOffset(final Point p0, final Point p1, final double segFrac) {
final double len = p0.distancePoint(p1);
final double len2 = len / 2;
final double offsetLen = len * Math.random() - len2;
final LineSegment seg = new LineSegmentDouble(p0, p1);
return seg.pointAlongOffset(segFrac, offsetLen);
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineSegmentTest method testOrientationIndexCoordinate.
public void testOrientationIndexCoordinate() {
final LineSegment seg = new LineSegmentDouble(2, 0, 0, 10, 10);
checkOrientationIndex(seg, 10, 11, 1);
checkOrientationIndex(seg, 10, 9, -1);
checkOrientationIndex(seg, 11, 11, 0);
checkOrientationIndex(seg, 11, 11.0000001, 1);
checkOrientationIndex(seg, 11, 10.9999999, -1);
checkOrientationIndex(seg, -2, -1.9999999, 1);
checkOrientationIndex(seg, -2, -2.0000001, -1);
}
Aggregations