Search in sources :

Example 16 with PointDouble

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);
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point)

Example 17 with PointDouble

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;
        }
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 18 with PointDouble

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;
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point)

Example 19 with PointDouble

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);
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point)

Example 20 with PointDouble

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));
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point)

Aggregations

PointDouble (com.revolsys.geometry.model.impl.PointDouble)24 Point (com.revolsys.geometry.model.Point)22 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 Test (org.junit.Test)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 ArrayList (java.util.ArrayList)2 KdNode (com.revolsys.geometry.index.kdtree.KdNode)1 KdTree (com.revolsys.geometry.index.kdtree.KdTree)1 LineString (com.revolsys.geometry.model.LineString)1 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)1 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)1 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)1 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)1 List (java.util.List)1