use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class LineSegment method distance.
default double distance(final LineSegment line) {
final double[] coordinates = new double[2];
final GeometryFactory geometryFactory = getGeometryFactory();
line.convertVertexCoordinates2d(0, geometryFactory, coordinates);
final double x1 = coordinates[X];
final double y1 = coordinates[Y];
line.convertVertexCoordinates2d(1, geometryFactory, coordinates);
final double x2 = coordinates[X];
final double y2 = coordinates[Y];
return distance(x1, y1, x2, y2);
}
use of com.revolsys.geometry.model.GeometryFactory 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.GeometryFactory 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.GeometryFactory in project com.revolsys.open by revolsys.
the class LineSegment method isPerpendicularTo.
default boolean isPerpendicularTo(Point point) {
if (Property.hasValuesAll(point, this)) {
final GeometryFactory geometryFactory = getGeometryFactory();
point = point.convertGeometry(geometryFactory, 2);
final double x = point.getX();
final double y = point.getY();
final double projectionFactor = projectionFactor(x, y);
if (projectionFactor >= 0.0 && projectionFactor <= 1.0) {
return true;
}
}
return false;
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class LineSegment method isPointOnLineMiddle.
default boolean isPointOnLineMiddle(Point point, final double maxDistance) {
if (point == null || point.isEmpty()) {
return false;
} else {
final GeometryFactory geometryFactory = getGeometryFactory();
point = point.convertGeometry(geometryFactory, 2);
final double x = point.getX();
final double y = point.getY();
return isPointOnLineMiddle(x, y, maxDistance);
}
}
Aggregations