/** * Returns the difference between the maximum and minimum z values. * * @return max z - min z, or 0 if this is a null <code>Envelope</code> */ public double getDepth() { if (isNull()) { return 0; } return maxz - minz; }
/** * Check if the region defined by <code>other</code> overlaps (intersects) the region of this * <code>Envelope</code>. * * @param other the <code>Envelope</code> which this <code>Envelope</code> is being checked for * overlapping * @return <code>true</code> if the <code>Envelope</code>s overlap */ public boolean intersects(ReferencedEnvelope3D other) { if (isNull() || other.isNull()) { return false; } return super.intersects((Envelope) other) && !(other.minz > maxz || other.maxz < minz); }
/** * Tests if the given point lies in or on the envelope. * * @param x the x-coordinate of the point which this <code>Envelope</code> is being checked for * containing * @param y the y-coordinate of the point which this <code>Envelope</code> is being checked for * containing * @return <code>true</code> if <code>(x, y)</code> lies in the interior or on the boundary of * this <code>Envelope</code>. */ public boolean covers(double x, double y, double z) { if (isNull()) return false; return covers(x, y) && z >= minz && z <= maxz; }
/** * Check if the point <code>(x, y)</code> overlaps (lies inside) the region of this <code> * Envelope</code>. * * @param x the x-ordinate of the point * @param y the y-ordinate of the point * @param z the z-ordinate of the point * @return <code>true</code> if the point overlaps this <code>Envelope</code> */ public boolean intersects(double x, double y, double z) { if (isNull()) return false; return intersects(x, y) && !(z > maxz || z < minz); }
/** * Tests if the <code>Envelope other</code> lies wholely inside this <code>Envelope</code> * (inclusive of the boundary). * * @param other the <code>Envelope</code> to check * @return true if this <code>Envelope</code> covers the <code>other</code> */ public boolean covers(ReferencedEnvelope3D other) { if (isNull() || other.isNull()) { return false; } return super.covers(other) && other.getMinZ() >= minz && other.getMaxZ() <= maxz; }
/** * Gets the minimum extent of this envelope across all three dimensions. * * @return the minimum extent of this envelope */ public double minExtent() { if (isNull()) return 0.0; return Math.min(getWidth(), Math.min(getHeight(), getDepth())); }
/** * Gets the maximum extent of this envelope across both dimensions. * * @return the maximum extent of this envelope */ public double maxExtent() { if (isNull()) return 0.0; return Math.max(getWidth(), Math.max(getHeight(), getDepth())); }
/** * Expands this envelope by a given distance in all directions. Both positive and negative * distances are supported. * * @param deltaX the distance to expand the envelope along the the X axis * @param deltaY the distance to expand the envelope along the the Y axis */ public void expandBy(double deltaX, double deltaY, double deltaZ) { if (isNull()) return; minz -= deltaZ; maxz += deltaZ; expandBy(deltaX, deltaY); // check for envelope disappearing if (minz > maxz) setToNull(); }
/** Compares the specified object with this envelope for equality. */ @Override public boolean equals(final Object other) { if (!(other instanceof ReferencedEnvelope3D)) { return false; } ReferencedEnvelope3D otherEnvelope = (ReferencedEnvelope3D) other; if (isNull()) { return otherEnvelope.isNull(); } if (super.equals(other) && minz == otherEnvelope.getMinZ() && minz == otherEnvelope.getMinZ()) { final CoordinateReferenceSystem otherCRS = (other instanceof ReferencedEnvelope3D) ? ((ReferencedEnvelope3D) other).crs : null; return CRS.equalsIgnoreMetadata(crs, otherCRS); } return false; }
/** * Enlarges this <code>Envelope</code> so that it contains the given point. Has no effect if the * point is already on or within the envelope. * * @param x the value to lower the minimum x to or to raise the maximum x to * @param y the value to lower the minimum y to or to raise the maximum y to * @param z the value to lower the minimum z to or to raise the maximum z to */ public void expandToInclude(double x, double y, double z) { if (isNull()) { expandToInclude(x, y); minz = z; maxz = z; } else { expandToInclude(x, y); if (z < minz) { minz = z; } if (z > maxz) { maxz = z; } } }
/** * Enlarges this <code>Envelope</code> so that it contains the <code>other</code> Envelope. Has * no effect if <code>other</code> is wholly on or within the envelope. * * @param other the <code>Envelope</code> to expand to include */ public void expandToInclude(ReferencedEnvelope3D other) { ensureCompatibleReferenceSystem(other); if (other.isNull()) { return; } if (isNull()) { super.expandToInclude(other); minz = other.getMinZ(); maxz = other.getMaxZ(); } else { super.expandToInclude(other); if (other.minz < minz) { minz = other.minz; } if (other.maxz > maxz) { maxz = other.maxz; } } }
/** * Computes the coordinate of the centre of this envelope (as long as it is non-null * * @return the centre coordinate of this envelope <code>null</code> if the envelope is null */ public Coordinate centre() { if (isNull()) return null; return new Coordinate( (getMinX() + getMaxX()) / 2.0, (getMinY() + getMaxY()) / 2.0, (getMinZ() + getMaxZ()) / 2.0); }
/** * Translates this envelope by given amounts in the X and Y direction. * * @param transX the amount to translate along the X axis * @param transY the amount to translate along the Y axis * @param transZ the amount to translate along the Z axis */ public void translate(double transX, double transY, double transZ) { if (isNull()) { return; } init( getMinX() + transX, getMaxX() + transX, getMinY() + transY, getMaxY() + transY, getMinZ() + transZ, getMaxZ() + transZ); }
/** * Computes the intersection of two {@link Envelope}s. * * @param env the envelope to intersect with * @return a new Envelope representing the intersection of the envelopes (this will be the null * envelope if either argument is null, or they do not intersect */ public ReferencedEnvelope3D intersection(ReferencedEnvelope3D env) { ensureCompatibleReferenceSystem(env); if (isNull() || env.isNull() || !intersects(env)) return new ReferencedEnvelope3D(); double intMinX = getMinX() > env.getMinX() ? getMinX() : env.getMinX(); double intMinY = getMinY() > env.getMinY() ? getMinY() : env.getMinY(); double intMinZ = minz > env.minz ? minz : env.minz; double intMaxX = getMaxX() < env.getMaxX() ? getMaxX() : env.getMaxX(); double intMaxY = getMaxY() < env.getMaxY() ? getMaxY() : env.getMaxY(); double intMaxZ = maxz < env.maxz ? maxz : env.maxz; return new ReferencedEnvelope3D( intMinX, intMaxX, intMinY, intMaxY, intMinZ, intMaxZ, env.getCoordinateReferenceSystem()); }
assertTrue("This is a null 3d envelope", everything.isNull());
assertTrue(envelope.isNull()); assertFalse(envelope.intersects(1.0, 2.0, 3.0));