use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.
the class Graph method moveNodesToMidpoint.
public boolean moveNodesToMidpoint(final String typePath, final Node<Record> node1, final Node<Record> node2) {
final Point point1 = node1.get3dCoordinates(typePath);
final Point point2 = node2.get3dCoordinates(typePath);
final Graph<Record> graph = node1.getGraph();
final Point midPoint = LineSegmentUtil.midPoint(GeometryFactory.fixed3d(0, 1000.0, 1000.0, 1.0), node2, node1);
final double x = midPoint.getX();
final double y = midPoint.getY();
final double z1 = point1.getZ();
final double z2 = point2.getZ();
double z;
if (z1 == 0 || !Double.isFinite(z1)) {
z = z2;
} else if (z2 == 0 || !Double.isFinite(z1)) {
z = z1;
} else {
z = Double.NaN;
}
final Point newPoint = new PointDoubleXYZ(x, y, z);
final Node<Record> newNode = graph.getNode(midPoint);
if (!Node.hasEdgesBetween(typePath, node1, newNode) && !Node.hasEdgesBetween(typePath, node2, newNode)) {
if (node1.equals(2, newNode)) {
moveNode(typePath, node2, node1, newPoint);
} else if (node2.equals(2, newNode)) {
moveNode(typePath, node1, node2, newPoint);
} else {
moveNode(typePath, node1, newNode, newPoint);
moveNode(typePath, node2, newNode, newPoint);
}
return true;
} else {
return false;
}
}
use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.
the class PlanarPolygon3D method averagePoint.
/**
* Computes a point which is the average of all coordinates
* in a sequence.
* If the sequence lies in a single plane,
* the computed point also lies in the plane.
*
* @param seq a coordinate sequence
* @return a Point with averaged ordinates
*/
private Point averagePoint(final LineString line) {
final int vertexCount = line.getVertexCount();
double sumX = 0;
double sumY = 0;
double sumZ = 0;
for (int i = 0; i < vertexCount; i++) {
sumX += line.getCoordinate(i, Geometry.X);
sumY += line.getCoordinate(i, Geometry.Y);
sumZ += line.getCoordinate(i, Geometry.Z);
}
final double x = sumX / vertexCount;
final double y = sumY / vertexCount;
final double z = sumZ / vertexCount;
return new PointDoubleXYZ(x, y, z);
}
use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.
the class MiscellaneousTest method testCoordinateNaN.
public void testCoordinateNaN() {
final Point c1 = GeometryFactory.DEFAULT_3D.point();
final Point c2 = new PointDoubleXY(3, 4);
assertEquals(3, c2.getX(), 1E-10);
assertEquals(4, c2.getY(), 1E-10);
assertTrue(Double.isNaN(c2.getZ()));
assertEquals(c1, c1);
assertEquals(c2, c2);
assertTrue(!c1.equals(c2));
assertEquals(new PointDoubleXY(3, 5), new PointDoubleXY(3, 5));
assertEquals(new PointDoubleXY(3, 5), new PointDoubleXY(3, 5));
assertTrue(new PointDoubleXYZ(3, 5, 0).equals(new PointDoubleXY(3, 5)));
}
use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.
the class CoordinatesTest method testEquals.
public void testEquals() {
final Point c1 = new PointDoubleXYZ(1.0, 2, 3);
final String s = "Not a coordinate";
assertTrue(!c1.equals(s));
final Point c2 = new PointDoubleXYZ(1.0, 2.0, 3.0);
assertTrue(c1.equals(2, c2));
final Point c3 = new PointDoubleXYZ(1.0, 22.0, 3.0);
assertTrue(!c1.equals(2, c3));
}
use of com.revolsys.geometry.model.impl.PointDoubleXYZ in project com.revolsys.open by revolsys.
the class CoordinatesTest method testEquals2D.
public void testEquals2D() {
final Point c1 = new PointDoubleXYZ(1.0, 2.0, 3.0);
final Point c2 = new PointDoubleXYZ(1.0, 2.0, 3.0);
assertTrue(c1.equals(2, c2));
final Point c3 = new PointDoubleXYZ(1.0, 22.0, 3.0);
assertTrue(!c1.equals(2, c3));
}
Aggregations