/** * Sets this envelope to the intersection if this envelope with the specified one. * * <p>This method assumes that the specified envelope uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param envelope the {@code Envelope} to intersect to this envelope. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * dimension. */ public void intersect(final Envelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { double min = Math.max(ordinates[i], envelope.getMinimum(i)); double max = Math.min(ordinates[i + dim], envelope.getMaximum(i)); if (min > max) { // Make an empty envelope (min==max) // while keeping it legal (min<=max). min = max = 0.5 * (min + max); } ordinates[i] = min; ordinates[i + dim] = max; } }
/** * Adds a point to this envelope. The resulting envelope is the smallest envelope that contains * both the original envelope and the specified point. After adding a point, a call to {@link * #contains} with the added point as an argument will return {@code true}, except if one of the * point's ordinates was {@link Double#NaN} (in which case the corresponding ordinate have been * ignored). * * <p>This method assumes that the specified point uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param position The point to add. * @throws MismatchedDimensionException if the specified point doesn't have the expected * dimension. */ public void add(final DirectPosition position) throws MismatchedDimensionException { ensureNonNull("position", position); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("position", position.getDimension(), dim); assert equalsIgnoreMetadata(crs, position.getCoordinateReferenceSystem()) : position; for (int i = 0; i < dim; i++) { final double value = position.getOrdinate(i); if (value < ordinates[i] || Double.isNaN(ordinates[i])) ordinates[i] = value; if (value > ordinates[i + dim] || Double.isNaN(ordinates[i + dim])) ordinates[i + dim] = value; } assert isEmpty() || contains(position); }
/** * Tests if a specified coordinate is inside the boundary of this envelope. * * <p>This method assumes that the specified point uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param position The point to text. * @return {@code true} if the specified coordinates are inside the boundary of this envelope; * {@code false} otherwise. * @throws MismatchedDimensionException if the specified point doesn't have the expected * dimension. */ public boolean contains(final DirectPosition position) throws MismatchedDimensionException { ensureNonNull("position", position); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("point", position.getDimension(), dim); assert equalsIgnoreMetadata(crs, position.getCoordinateReferenceSystem()) : position; for (int i = 0; i < dim; i++) { final double value = position.getOrdinate(i); if (!(value >= ordinates[i])) return false; if (!(value <= ordinates[i + dim])) return false; // Use '!' in order to take 'NaN' in account. } return true; }
return false; assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dimension; i++) { double epsilon;
final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { double inner = envelope.getMaximum(i);
/** * Adds an envelope object to this envelope. The resulting envelope is the union of the two * {@code Envelope} objects. * * <p>This method assumes that the specified envelope uses the same CRS than this envelope. For * performance reason, it will no be verified unless J2SE assertions are enabled. * * @param envelope the {@code Envelope} to add to this envelope. * @throws MismatchedDimensionException if the specified envelope doesn't have the expected * dimension. */ public void add(final Envelope envelope) throws MismatchedDimensionException { ensureNonNull("envelope", envelope); final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { final double min = envelope.getMinimum(i); final double max = envelope.getMaximum(i); if (min < ordinates[i]) ordinates[i] = min; if (max > ordinates[i + dim]) ordinates[i + dim] = max; } assert isEmpty() || contains(envelope, true); }
final int dim = ordinates.length / 2; AbstractDirectPosition.ensureDimensionMatch("envelope", envelope.getDimension(), dim); assert equalsIgnoreMetadata(crs, envelope.getCoordinateReferenceSystem()) : envelope; for (int i = 0; i < dim; i++) { double inner = envelope.getMinimum(i);