use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class DistanceWithLocation method computeLineLine.
private boolean computeLineLine(final LineString line1, final LineString line2) {
if (this.minDistance == Double.MAX_VALUE || line1.getBoundingBox().distance(line2.getBoundingBox()) <= this.minDistance) {
for (final Segment segment1 : line1.segments()) {
for (final Segment segment2 : line2.segments()) {
final double dist = segment1.distance(segment2);
if (dist < this.minDistance) {
this.minDistance = dist;
final Point[] closestPt = segment1.closestPoints(segment2);
final int segmentIndex1 = segment1.getSegmentIndex();
this.minDistanceLocation1 = new GeometryLocation(line1, segmentIndex1, closestPt[0]);
final int segmentIndex2 = segment2.getSegmentIndex();
this.minDistanceLocation2 = new GeometryLocation(line2, segmentIndex2, closestPt[1]);
if (this.minDistance <= this.terminateDistance) {
return true;
}
}
}
}
}
return false;
}
use of com.revolsys.geometry.model.segment.Segment in project com.revolsys.open by revolsys.
the class AbstractRecordLayerRenderer method getPointWithOrientationCentre.
private static PointDoubleXYOrientation getPointWithOrientationCentre(final GeometryFactory geometryFactory2dFloating, final Geometry geometry) {
double orientation = 0;
Point point = null;
if (geometry instanceof LineString) {
final LineString line = geometry.convertGeometry(geometryFactory2dFloating, 2);
final double totalLength = line.getLength();
final double centreLength = totalLength / 2;
double currentLength = 0;
for (final Segment segment : line.segments()) {
final double segmentLength = segment.getLength();
currentLength += segmentLength;
if (currentLength >= centreLength) {
final double segmentFraction = 1 - (currentLength - centreLength) / segmentLength;
point = segment.pointAlong(segmentFraction);
orientation = segment.getOrientaton();
break;
}
}
} else {
point = geometry.getPointWithin();
point = point.convertPoint2d(geometryFactory2dFloating);
}
return new PointDoubleXYOrientation(point, orientation);
}
Aggregations