Search in sources :

Example 1 with PointDouble

use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.

the class BoundingBoxTest method testConstructorCoordinatesArray.

@Test
public void testConstructorCoordinatesArray() {
    final BoundingBox emptyList = BoundingBoxDoubleXY.newBoundingBox(new Point[0]);
    assertBoundingBox(null, emptyList, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    // Different number of axis and values
    for (int axisCount = 2; axisCount < 6; axisCount++) {
        for (int valueCount = 1; valueCount < 10; valueCount++) {
            Point[] points = new Point[valueCount];
            final double[] bounds = RectangleUtil.newBounds(axisCount);
            for (int i = 0; i < valueCount; i++) {
                final double[] values = new double[axisCount];
                for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
                    final double value = Math.random() * 360 - 180;
                    values[axisIndex] = value;
                    final double min = bounds[axisIndex];
                    if (Double.isNaN(min) || value < min) {
                        bounds[axisIndex] = value;
                    }
                    final double max = bounds[axisCount + axisIndex];
                    if (Double.isNaN(max) || value > max) {
                        bounds[axisCount + axisIndex] = value;
                    }
                }
                points[i] = new PointDouble(values);
            }
            final GeometryFactory noGf = GeometryFactory.DEFAULT_3D.convertAxisCount(axisCount);
            final BoundingBox noGeometryFactory = noGf.newBoundingBox(axisCount, points);
            assertBoundingBox(null, noGeometryFactory, noGf, false, axisCount, bounds);
            final GeometryFactory gfFloating = GeometryFactory.floating(4326, axisCount);
            assertBoundingBox(null, gfFloating.newBoundingBox(axisCount, points), gfFloating, false, axisCount, bounds);
            final double[] scales = GeometryFactory.newScalesFixed(axisCount, 10.0);
            final GeometryFactory gfFixed = GeometryFactory.fixed(4326, axisCount, scales);
            points = gfFixed.getPrecise(points);
            final double[] boundsPrecise = gfFixed.copyPrecise(bounds);
            assertBoundingBox(null, gfFixed.newBoundingBox(axisCount, points), gfFixed, false, axisCount, boundsPrecise);
        }
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 2 with PointDouble

use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.

the class BoundingBoxTest method testConstructorIterable.

@Test
public void testConstructorIterable() {
    final BoundingBox emptyNull = BoundingBoxDoubleXY.newBoundingBox((Iterable<Point>) null);
    assertBoundingBox(null, emptyNull, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    final BoundingBox emptyList = BoundingBoxDoubleXY.newBoundingBox(new ArrayList<Point>());
    assertBoundingBox(null, emptyList, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    final BoundingBox emptyListWithNulls = BoundingBoxDoubleXY.newBoundingBox(Collections.<Point>singleton(null));
    assertBoundingBox(null, emptyListWithNulls, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    final BoundingBox emptyNullCoordinatesList = BoundingBoxDoubleXY.newBoundingBox((Iterable<Point>) null);
    assertBoundingBox(null, emptyNullCoordinatesList, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    final BoundingBox emptyCoordinatesList = BoundingBoxDoubleXY.newBoundingBox(new ArrayList<Point>());
    assertBoundingBox(null, emptyCoordinatesList, GeometryFactory.DEFAULT_3D, true, 2, NULL_BOUNDS);
    // Different number of axis and values
    for (int axisCount = 2; axisCount < 6; axisCount++) {
        for (int valueCount = 1; valueCount < 10; valueCount++) {
            final List<Point> points = new ArrayList<>();
            final double[] bounds = RectangleUtil.newBounds(axisCount);
            for (int i = 0; i < valueCount; i++) {
                final double[] values = new double[axisCount];
                for (int axisIndex = 0; axisIndex < axisCount; axisIndex++) {
                    final double value = Math.random() * 360 - 180;
                    values[axisIndex] = value;
                    final double min = bounds[axisIndex];
                    if (Double.isNaN(min) || value < min) {
                        bounds[axisIndex] = value;
                    }
                    final double max = bounds[axisCount + axisIndex];
                    if (Double.isNaN(max) || value > max) {
                        bounds[axisCount + axisIndex] = value;
                    }
                }
                points.add(new PointDouble(values));
            }
            final GeometryFactory noGf = GeometryFactory.DEFAULT_3D.convertAxisCount(axisCount);
            final BoundingBox noGeometryFactory = noGf.newBoundingBox(axisCount, points);
            assertBoundingBox(null, noGeometryFactory, noGf, false, axisCount, bounds);
            final GeometryFactory gfFloating = GeometryFactory.floating(4326, axisCount);
            assertBoundingBox(null, gfFloating.newBoundingBox(axisCount, points), gfFloating, false, axisCount, bounds);
            final double[] scales = GeometryFactory.newScalesFixed(axisCount, 10.0);
            final GeometryFactory gfFixed = GeometryFactory.fixed(4326, axisCount, scales);
            final double[] boundsPrecise = gfFixed.copyPrecise(bounds);
            assertBoundingBox(null, gfFixed.newBoundingBox(axisCount, points), gfFixed, false, axisCount, boundsPrecise);
        }
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Test(org.junit.Test)

Example 3 with PointDouble

use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.

the class CoordinatesTest method testClone.

public void testClone() {
    for (final Point point : // 
    Arrays.asList(// 
    new PointDoubleXY(100.0, 200.0), // 
    new PointDoubleXYZ(100.0, 200.0, 50.0), new PointDouble(100.0, 200.0, 50.0, 4.0))) {
        final Point clone = point.newPoint();
        assertEquals3d(point, clone);
    }
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) PointDoubleXYZ(com.revolsys.geometry.model.impl.PointDoubleXYZ) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 4 with PointDouble

use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.

the class CoordinateTest method testEquals3D.

public void testEquals3D() {
    final Point c1 = new PointDouble(1.0, 2.0, 3.0);
    final Point c2 = new PointDouble(1.0, 2.0, 3.0);
    assertTrue(c1.equals(3, c2));
    final Point c3 = new PointDouble(1.0, 22.0, 3.0);
    assertTrue(!c1.equals(3, c3));
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) Point(com.revolsys.geometry.model.Point)

Example 5 with PointDouble

use of com.revolsys.geometry.model.impl.PointDouble in project com.revolsys.open by revolsys.

the class CoordinateTest method testConstructor2D.

public void testConstructor2D() {
    final Point c = new PointDouble(350.2, 4566.8);
    assertEquals(c, 350.2, 4566.8);
}
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