use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.
the class CoordinatesUtil method average.
static Point average(final Point c1, final Point c2) {
final int axisCount = Math.min(c1.getAxisCount(), c2.getAxisCount());
final double[] coordinates = new double[axisCount];
for (int i = 0; i < axisCount; i++) {
final double value1 = c1.getCoordinate(i);
final double value2 = c2.getCoordinate(i);
double value;
if (Double.isNaN(value1) || Double.isNaN(value1)) {
value = value2;
} else if (Double.isNaN(value2) || Double.isNaN(value2)) {
value = value1;
} else {
value = MathUtil.avg(value1, value2);
}
coordinates[i] = value;
}
return new PointDouble(coordinates);
}
use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.
the class LineSegmentUtil method project.
public static Point project(final GeometryFactory geometryFactory, final Point lineStart, final Point lineEnd, final Point point) {
if (point.equals(2, lineStart) || point.equals(2, lineEnd)) {
return point;
} else {
final double r = projectionFactor(lineStart, lineEnd, point);
final int axisCount = CoordinatesUtil.getAxisCount(point, lineStart, lineEnd);
Point projectedPoint = project(axisCount, lineStart, lineEnd, r);
if (geometryFactory != null) {
projectedPoint = geometryFactory.getPreciseCoordinates(projectedPoint);
}
if (projectedPoint.equals(2, lineStart)) {
return lineStart;
} else if (projectedPoint.equals(2, lineEnd)) {
return lineEnd;
} else {
if (axisCount > 2) {
final double z = projectedPoint.getZ();
if (!Double.isFinite(z) || z == 0) {
final double[] coordinates = projectedPoint.getCoordinates(axisCount);
for (int axisIndex = 2; axisIndex < axisCount; axisIndex++) {
coordinates[axisIndex] = point.getCoordinate(axisIndex);
}
if (geometryFactory == null) {
return new PointDouble(coordinates);
} else {
return geometryFactory.point(coordinates);
}
}
}
return projectedPoint;
}
}
}
use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.
the class WKTReader method getPreciseCoordinate.
private Point getPreciseCoordinate() throws IOException, ParseException {
final double x = this.geometryFactory.makePrecise(0, getNextNumber());
final double y = this.geometryFactory.makePrecise(1, getNextNumber());
final Point coord;
if (isNumberNext()) {
final double z = getNextNumber();
coord = new PointDouble(x, y, z);
} else {
coord = new PointDouble(x, y);
}
return coord;
}
use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.
the class CoordinateTest method testClone.
public void testClone() {
for (final Point point : //
Arrays.asList(//
new PointDouble(), //
new PointDouble(100.0, 200.0), //
new PointDouble(100.0, 200.0, 50.0), new PointDouble(100.0, 200.0, 50.0, 4.0))) {
final Point clone = point.newPoint2D();
assertEquals3d(point, clone);
}
}
use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.
the class CoordinateTest method testCompareTo.
public void testCompareTo() {
final Point lowest = new PointDouble(10.0, 100.0, 50.0);
final Point highest = new PointDouble(20.0, 100.0, 50.0);
final Point equalToHighest = new PointDouble(20.0, 100.0, 50.0);
final Point higherStill = new PointDouble(20.0, 200.0, 50.0);
assertEquals(-1, lowest.compareTo(highest));
assertEquals(1, highest.compareTo(lowest));
assertEquals(-1, highest.compareTo(higherStill));
assertEquals(0, highest.compareTo(equalToHighest));
}
Aggregations