/** * Intersects the specified <code>Envelope</code> with this <code>Envelope</code> and returns the result. * * @param other the Envelope to intersect with this instance * @return the set-theoretic intersection of this Envelope and the specified Envelope. * @throws IllegalArgumentException when the specified <code>Envelope</code> doesn't have the same coordinate reference system as this instance. */ public Envelope<P> intersect(Envelope<P> other) { if (this.isEmpty() || other.isEmpty()) return mkEmpty(); if (!this.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) throw new IllegalArgumentException("Envelopes have different CRS."); double minC0 = Math.max(getMinC0(), other.getMinC0()); double minC1 = Math.max(getMinC1(), other.getMinC1()); double maxC0 = Math.min(getMaxC0(), other.getMaxC0()); double maxC1 = Math.min(getMaxC1(), other.getMaxC1()); if (minC0 > maxC0 || minC1 > maxC1) return mkEmpty(); return new Envelope<P>(minC0, minC1, maxC0, maxC1, this.getCoordinateReferenceSystem()); }