use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineSegment method getIntersection.
default LineSegment getIntersection(BoundingBox boundingBox) {
final GeometryFactory geometryFactory = getGeometryFactory();
boundingBox = boundingBox.convert(geometryFactory);
final Point lineStart = getPoint(0);
final Point lineEnd = getPoint(1);
final boolean contains1 = boundingBox.covers(lineStart);
final boolean contains2 = boundingBox.covers(lineEnd);
if (contains1) {
if (contains2) {
return this;
} else {
final Point c1 = lineStart;
final Point c2 = getCrossing(lineEnd, lineStart, boundingBox);
return new LineSegmentDoubleGF(geometryFactory, c1, c2);
}
} else {
if (contains2) {
final Point c1 = getCrossing(lineStart, lineEnd, boundingBox);
final Point c2 = lineEnd;
return new LineSegmentDoubleGF(geometryFactory, c1, c2);
} else {
final Point c1 = getCrossing(lineStart, lineEnd, boundingBox);
final Point c2 = getCrossing(lineEnd, lineStart, boundingBox);
return new LineSegmentDoubleGF(geometryFactory, c1, c2);
}
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineSegment method convertGeometry.
@Override
@SuppressWarnings("unchecked")
default <V extends Geometry> V convertGeometry(final GeometryFactory geometryFactory) {
final GeometryFactory factory = getGeometryFactory();
if (geometryFactory == factory) {
return (V) this;
} else {
final Point point1 = ProjectionFactory.convert(getPoint(0), factory, geometryFactory);
final Point point2 = ProjectionFactory.convert(getPoint(1), factory, geometryFactory);
return (V) new LineSegmentDoubleGF(geometryFactory, point1, point2);
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineSegment method extend.
default LineSegment extend(final double startDistance, final double endDistance) {
final double angle = angle();
final Point c1 = CoordinatesUtil.offset(getPoint(0), angle, -startDistance);
final Point c2 = CoordinatesUtil.offset(getPoint(1), angle, endDistance);
return new LineSegmentDoubleGF(getGeometryFactory(), c1, c2);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineSegment method pointAlong.
/**
* Computes the {@link Coordinates} that lies a given
* fraction along the line defined by this segment.
* A fraction of <code>0.0</code> returns the start point of the segment;
* a fraction of <code>1.0</code> returns the end point of the segment.
* If the fraction is < 0.0 or > 1.0 the point returned
* will lie before the start or beyond the end of the segment.
*
* @param projectionFactor the fraction of the segment length along the line
* @return the point at that distance
*/
default Point pointAlong(final double projectionFactor) {
final GeometryFactory geometryFactory = getGeometryFactory();
final int axisCount = getAxisCount();
final double[] coordinates = new double[axisCount];
for (int i = 0; i < axisCount; i++) {
final double value1 = getCoordinate(0, i);
final double value2 = getCoordinate(1, i);
final double delta = value2 - value1;
double newValue = value1 + delta * projectionFactor;
newValue = geometryFactory.makePrecise(i, newValue);
coordinates[i] = newValue;
}
return newPoint(coordinates);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class BoundingBoxDoubleXY method newBoundingBox.
public static BoundingBox newBoundingBox(final Point... points) {
double minX = Double.POSITIVE_INFINITY;
double maxX = Double.NEGATIVE_INFINITY;
double minY = Double.POSITIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
for (final Point point : points) {
final double x = point.getX();
final double y = point.getY();
if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
return newBoundingBoxXY(minX, minY, maxX, maxY);
}
Aggregations