@Test public void testDistanceWhenMinZOfThisIsGreaterThanMaxZOfOther() { CoordinateReferenceSystem crs = DefaultEngineeringCRS.CARTESIAN_3D; ReferencedEnvelope3D a = new ReferencedEnvelope3D(2.0, 3.0, 2.0, 3.0, 2.0, 3.0, crs); ReferencedEnvelope3D b = new ReferencedEnvelope3D(0.0, 1.0, 0.0, 1.0, 0.0, 0.5, crs); assertEquals(Math.sqrt(1 * 1 + 1 * 1 + 1.5 * 1.5), a.distance(b), 0.00001); }
public double distance(ReferencedEnvelope3D env) { if (intersects(env)) return 0; double dx = 0.0; if (getMaxX() < env.getMinX()) dx = env.getMinX() - getMaxX(); else if (getMinX() > env.getMaxX()) dx = getMinX() - env.getMaxX(); double dy = 0.0; if (getMaxY() < env.getMinY()) dy = env.getMinY() - getMaxY(); else if (getMinY() > env.getMaxY()) dy = getMinY() - env.getMaxY(); double dz = 0.0; if (maxz < env.minz) dz = env.minz - maxz; else if (minz > env.maxz) dz = minz - env.maxz; if (dx == 0.0 && dz == 0) return dy; if (dy == 0.0 && dz == 0) return dx; if (dx == 0 && dy == 0) return dz; return Math.sqrt(dx * dx + dy * dy + dz * dz); }
ReferencedEnvelope3D extends ReferencedEnvelope implements BoundingBox3D { public double distance(ReferencedEnvelope3D env) { if (intersects(env)) return 0; double dx = 0.0; if (getMaxX() < env.getMinX()) dx = env.getMinX() - getMaxX(); else if (getMinX() > env.getMaxX()) dx = getMinX() - env.getMaxX(); double dy = 0.0; if (getMaxY() < env.getMinY()) dy = env.getMinY() - getMaxY(); else if (getMinY() > env.getMaxY()) dy = getMinY() - env.getMaxY(); double dz = 0.0; if (maxz < env.minz) dz = env.minz - maxz; else if (minz > env.maxz) dz = minz - env.maxz; if (dx == 0.0 && dz == 0) return dy; if (dy == 0.0 && dz == 0) return dx; if (dx == 0 && dy == 0) return dz; return Math.sqrt(dx * dx + dy * dy + dz * dz); } }
ReferencedEnvelope3D extends ReferencedEnvelope implements BoundingBox3D { public double distance(ReferencedEnvelope3D env) { if (intersects(env)) return 0; double dx = 0.0; if (getMaxX() < env.getMinX()) dx = env.getMinX() - getMaxX(); else if (getMinX() > env.getMaxX()) dx = getMinX() - env.getMaxX(); double dy = 0.0; if (getMaxY() < env.getMinY()) dy = env.getMinY() - getMaxY(); else if (getMinY() > env.getMaxY()) dy = getMinY() - env.getMaxY(); double dz = 0.0; if (maxz < env.minz) dz = env.minz - maxz; else if (minz > env.maxz) dz = minz - env.maxz; if (dx == 0.0 && dz == 0) return dy; if (dy == 0.0 && dz == 0) return dx; if (dx == 0 && dy == 0) return dz; return Math.sqrt(dx * dx + dy * dy + dz * dz); } ReferencedEnvelope3D();  ReferencedEnvelope3D(CoordinateReferenceSystem crs);  ReferencedEnvelope3D(
            final double x1,
            final double x2,
            final double y1,
            final double y2,
            final double z1,
            final double z2,
            final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final ReferencedEnvelope3D envelope);  ReferencedEnvelope3D(final BoundingBox3D bbox);  ReferencedEnvelope3D(final Envelope envelope, final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final org.opengis.geometry.Envelope envelope);  ReferencedEnvelope3D(
            final ReferencedEnvelope3D envelope, final CoordinateReferenceSystem crs); }
ReferencedEnvelope3D extends ReferencedEnvelope implements BoundingBox3D { public double distance(ReferencedEnvelope3D env) { if (intersects(env)) return 0; double dx = 0.0; if (getMaxX() < env.getMinX()) dx = env.getMinX() - getMaxX(); else if (getMinX() > env.getMaxX()) dx = getMinX() - env.getMaxX(); double dy = 0.0; if (getMaxY() < env.getMinY()) dy = env.getMinY() - getMaxY(); else if (getMinY() > env.getMaxY()) dy = getMinY() - env.getMaxY(); double dz = 0.0; if (maxz < env.minz) dz = env.minz - maxz; else if (minz > env.maxz) dz = minz - env.maxz; if (dx == 0.0 && dz == 0) return dy; if (dy == 0.0 && dz == 0) return dx; if (dx == 0 && dy == 0) return dz; return Math.sqrt(dx * dx + dy * dy + dz * dz); } ReferencedEnvelope3D();  ReferencedEnvelope3D(CoordinateReferenceSystem crs);  ReferencedEnvelope3D(
            final double x1,
            final double x2,
            final double y1,
            final double y2,
            final double z1,
            final double z2,
            final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final ReferencedEnvelope3D envelope);  ReferencedEnvelope3D(final BoundingBox3D bbox);  ReferencedEnvelope3D(final Envelope envelope, final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final org.opengis.geometry.Envelope envelope);  ReferencedEnvelope3D(
            final ReferencedEnvelope3D envelope, final CoordinateReferenceSystem crs); static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q); static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2); void init(); void init(double x1, double x2, double y1, double y2, double z1, double z2); void init(Coordinate p1, Coordinate p2); void init(Coordinate p); @Override void init(Envelope env); void init(ReferencedEnvelope3D env); void setToNull(); double getDepth(); double getMinZ(); double getMaxZ(); double getVolume(); double minExtent(); double maxExtent(); void expandToInclude(Coordinate p); void expandBy(double distance); void expandBy(double deltaX, double deltaY, double deltaZ); void expandToInclude(double x, double y, double z); @Override void expandToInclude(DirectPosition pt); void translate(double transX, double transY, double transZ); Coordinate centre(); boolean intersects(ReferencedEnvelope3D other); boolean intersects(Coordinate p); @SuppressWarnings("deprecation") boolean overlaps(Coordinate p); boolean intersects(double x, double y, double z); boolean contains(Coordinate p); boolean contains(double x, double y, double z); boolean covers(double x, double y, double z); boolean covers(Coordinate p); boolean covers(ReferencedEnvelope3D other); double distance(ReferencedEnvelope3D env); void init(BoundingBox bounds); int getDimension(); double getMinimum(final int dimension); double getMaximum(final int dimension); double getMedian(final int dimension); double getSpan(final int dimension); DirectPosition getLowerCorner(); DirectPosition getUpperCorner(); boolean isEmpty(); boolean contains(DirectPosition pos); boolean contains(final BoundingBox3D bbox); boolean intersects(final BoundingBox3D bbox); ReferencedEnvelope3D intersection(ReferencedEnvelope3D env); void include(final BoundingBox3D bbox); void expandToInclude(ReferencedEnvelope3D other); void include(double x, double y, double z); void setBounds(final BoundingBox3D bbox); BoundingBox toBounds(final CoordinateReferenceSystem targetCRS); ReferencedEnvelope transform(CoordinateReferenceSystem targetCRS, boolean lenient); ReferencedEnvelope transform(
            final CoordinateReferenceSystem targetCRS,
            final boolean lenient,
            final int numPointsForTransformation); @Override int hashCode(); @Override boolean equals(final Object other); boolean boundsEquals3D(final org.opengis.geometry.Envelope other, double eps); @Override void include(double x, double y); }
ReferencedEnvelope3D extends ReferencedEnvelope implements BoundingBox3D { public double distance(ReferencedEnvelope3D env) { if (intersects(env)) return 0; double dx = 0.0; if (getMaxX() < env.getMinX()) dx = env.getMinX() - getMaxX(); else if (getMinX() > env.getMaxX()) dx = getMinX() - env.getMaxX(); double dy = 0.0; if (getMaxY() < env.getMinY()) dy = env.getMinY() - getMaxY(); else if (getMinY() > env.getMaxY()) dy = getMinY() - env.getMaxY(); double dz = 0.0; if (maxz < env.minz) dz = env.minz - maxz; else if (minz > env.maxz) dz = minz - env.maxz; if (dx == 0.0 && dz == 0) return dy; if (dy == 0.0 && dz == 0) return dx; if (dx == 0 && dy == 0) return dz; return Math.sqrt(dx * dx + dy * dy + dz * dz); } ReferencedEnvelope3D();  ReferencedEnvelope3D(CoordinateReferenceSystem crs);  ReferencedEnvelope3D(
            final double x1,
            final double x2,
            final double y1,
            final double y2,
            final double z1,
            final double z2,
            final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final ReferencedEnvelope3D envelope);  ReferencedEnvelope3D(final BoundingBox3D bbox);  ReferencedEnvelope3D(final Envelope envelope, final CoordinateReferenceSystem crs);  ReferencedEnvelope3D(final org.opengis.geometry.Envelope envelope);  ReferencedEnvelope3D(
            final ReferencedEnvelope3D envelope, final CoordinateReferenceSystem crs); static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q); static boolean intersects(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2); void init(); void init(double x1, double x2, double y1, double y2, double z1, double z2); void init(Coordinate p1, Coordinate p2); void init(Coordinate p); @Override void init(Envelope env); void init(ReferencedEnvelope3D env); void setToNull(); double getDepth(); double getMinZ(); double getMaxZ(); double getVolume(); double minExtent(); double maxExtent(); void expandToInclude(Coordinate p); void expandBy(double distance); void expandBy(double deltaX, double deltaY, double deltaZ); void expandToInclude(double x, double y, double z); @Override void expandToInclude(DirectPosition pt); void translate(double transX, double transY, double transZ); Coordinate centre(); boolean intersects(ReferencedEnvelope3D other); boolean intersects(Coordinate p); @SuppressWarnings("deprecation") boolean overlaps(Coordinate p); boolean intersects(double x, double y, double z); boolean contains(Coordinate p); boolean contains(double x, double y, double z); boolean covers(double x, double y, double z); boolean covers(Coordinate p); boolean covers(ReferencedEnvelope3D other); double distance(ReferencedEnvelope3D env); void init(BoundingBox bounds); int getDimension(); double getMinimum(final int dimension); double getMaximum(final int dimension); double getMedian(final int dimension); double getSpan(final int dimension); DirectPosition getLowerCorner(); DirectPosition getUpperCorner(); boolean isEmpty(); boolean contains(DirectPosition pos); boolean contains(final BoundingBox3D bbox); boolean intersects(final BoundingBox3D bbox); ReferencedEnvelope3D intersection(ReferencedEnvelope3D env); void include(final BoundingBox3D bbox); void expandToInclude(ReferencedEnvelope3D other); void include(double x, double y, double z); void setBounds(final BoundingBox3D bbox); BoundingBox toBounds(final CoordinateReferenceSystem targetCRS); ReferencedEnvelope transform(CoordinateReferenceSystem targetCRS, boolean lenient); ReferencedEnvelope transform(
            final CoordinateReferenceSystem targetCRS,
            final boolean lenient,
            final int numPointsForTransformation); @Override int hashCode(); @Override boolean equals(final Object other); boolean boundsEquals3D(final org.opengis.geometry.Envelope other, double eps); @Override void include(double x, double y); static ReferencedEnvelope3D EVERYTHING; }