@Override void reduce(GeneralEnvelope result, Envelope other) { result.intersect(other); }
/** * Computes the envelope with the given coordinate reference system. This method is invoked from constructors. * The {@link #extent}, {@link #gridToCRS} and {@link #cornerToCRS} fields must be set before this method is invoked. * * @param specified the transform specified by the user. This is not necessarily {@link #gridToCRS}. * @param crs the coordinate reference system to declare in the envelope. * @param limits if non-null, intersect with that envelope. The CRS must be the same than {@code crs}. */ private ImmutableEnvelope computeEnvelope(final MathTransform specified, final CoordinateReferenceSystem crs, final Envelope limits) throws TransformException { final GeneralEnvelope env; if (extent != null && cornerToCRS != null) { env = extent.toCRS(cornerToCRS, specified); env.setCoordinateReferenceSystem(crs); if (limits != null) { env.intersect(limits); } } else if (crs != null) { env = new GeneralEnvelope(crs); env.setToNaN(); } else { return null; } return new ImmutableEnvelope(env); }
/** * Asserts that the intersection of the two following envelopes is equals to the given rectangle. * First, this method tests using the {@link Envelope2D} implementation. Then, it tests using the * {@link GeneralEnvelope} implementation. */ private static void assertIntersectEquals(final GeneralEnvelope e1, final GeneralEnvelope e2, final double xmin, final double ymin, final double xmax, final double ymax) { final Envelope2D r1 = new Envelope2D(e1); final Envelope2D r2 = new Envelope2D(e2); final Envelope2D ri = r1.createIntersection(r2); assertFalse("isEmpty", r1.isEmpty()); assertEnvelopeEquals(ri, xmin, ymin, xmax, ymax); assertEquals("Interchanged arguments.", ri, r2.createIntersection(r1)); // Compares with GeneralEnvelope. final GeneralEnvelope ei = new GeneralEnvelope(e1); ei.intersect(e2); assertFalse("isEmpty", e1.isEmpty()); assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax); assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false)); // Interchanges arguments. ei.setEnvelope(e2); ei.intersect(e1); assertFalse("isEmpty", e1.isEmpty()); assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax); assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false)); }