This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit c0494204bc0a64f07ed4f6dec421d25f76ebe21f Author: Martin Desruisseaux <[email protected]> AuthorDate: Sat May 28 11:19:36 2022 +0200 Method renaming, documentation update, more specific exception. --- .../java/org/apache/sis/coverage/grid/GridDerivation.java | 13 ++++++++----- .../main/java/org/apache/sis/coverage/grid/GridExtent.java | 2 +- .../org/apache/sis/coverage/grid/GridDerivationTest.java | 2 ++ .../src/main/java/org/apache/sis/geometry/Envelopes.java | 7 +++++-- .../operation/transform/WraparoundTransform.java | 6 +++++- .../test/java/org/apache/sis/geometry/EnvelopesTest.java | 6 +++--- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java index e1909ce0bc..d1eb24b974 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java @@ -806,7 +806,8 @@ public class GridDerivation { * As a consequence of above context, margin and chunk size are in units of the base extent. * They are not in units of cells of the size that we get after subsampling. * - * @param indices the envelope to intersect in units of {@link #base} grid coordinates. + * @param indices the envelopes to intersect in units of {@link #base} grid coordinates. + * Shall contains at least one element. * @throws DisjointExtentException if the given envelope does not intersect the grid extent. * * @see #getBaseExtentExpanded(boolean) @@ -814,13 +815,15 @@ public class GridDerivation { private void setBaseExtentClipped(final GeneralEnvelope... indices) { GridExtent sub = null; IllegalArgumentException error = null; - for (final GeneralEnvelope ix : indices) try { - final GridExtent c = new GridExtent(ix, rounding, clipping, margin, chunkSize, baseExtent, modifiedDimensions); + int i = 0; + do try { + // Intentional IndexOutOfBoundsException if the `indices` array does not contain at least one element. + GridExtent c = new GridExtent(indices[i], rounding, clipping, margin, chunkSize, baseExtent, modifiedDimensions); sub = (sub == null) ? c : sub.union(c); - } catch (IllegalArgumentException e) { + } catch (DisjointExtentException e) { if (error == null) error = e; else error.addSuppressed(e); - } + } while (++i < indices.length); if (sub == null) { throw error; // Should never be null because `indices` should never be empty. } diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java index 37822acd1d..0dab502a06 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java @@ -1067,7 +1067,7 @@ public class GridExtent implements GridEnvelope, LenientComparable, Serializable final GeneralEnvelope[] toEnvelopes(final MathTransform cornerToCRS, final MathTransform gridToCRS, final Envelope fallback) throws TransformException { - final GeneralEnvelope[] envelopes = Envelopes.transformWraparounds(cornerToCRS, toEnvelope()); + final GeneralEnvelope[] envelopes = Envelopes.wraparound(cornerToCRS, toEnvelope()); for (final GeneralEnvelope envelope : envelopes) { complete(envelope, gridToCRS, gridToCRS != cornerToCRS, fallback); } diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java index f13e80d1c9..c8b0f6902c 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridDerivationTest.java @@ -625,6 +625,8 @@ public final strictfp class GridDerivationTest extends TestCase { * Tests deriving a grid geometry with a request crossing the antimeridian. * The {@link GridGeometry} crossing the anti-meridian is the one given in * argument to {@link GridDerivation#subgrid(GridGeometry)}. + * + * <a href="https://issues.apache.org/jira/browse/SIS-548">SIS-548</a> */ @Test public void testAntiMeridianCrossingInSubgrid() { diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java index d7d7bd14d7..c420ab4918 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java @@ -365,7 +365,7 @@ public final class Envelopes extends Static { /** * Shared implementation of {@link #transform(MathTransform, Envelope)} - * and {@link #transformWraparounds(MathTransform, Envelope)}. + * and {@link #wraparound(MathTransform, Envelope)} public methods. * Offers also the opportunity to save the transformed center coordinates. * * @param transform the transform to use. @@ -989,9 +989,12 @@ poles: for (int i=0; i<dimension; i++) { * @return the transformed envelopes, or an empty array if {@code envelope} was null. * @throws TransformException if a transform failed. * + * @see #transform(MathTransform, Envelope) + * @see org.apache.sis.referencing.operation.transform.WraparoundTransform + * * @since 1.3 */ - public static GeneralEnvelope[] transformWraparounds(final MathTransform transform, final Envelope envelope) + public static GeneralEnvelope[] wraparound(final MathTransform transform, final Envelope envelope) throws TransformException { ArgumentChecks.ensureNonNull("transform", transform); diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java index 7b2db92578..d730226945 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java @@ -21,6 +21,7 @@ import java.util.Objects; import java.util.function.Function; import java.io.Serializable; import org.opengis.util.FactoryException; +import org.opengis.geometry.Envelope; import org.opengis.geometry.DirectPosition; import org.opengis.parameter.ParameterValueGroup; import org.opengis.parameter.ParameterDescriptorGroup; @@ -72,7 +73,10 @@ import static java.util.logging.Logger.getLogger; * * @author Martin Desruisseaux (Geomatys) * @version 1.1 - * @since 1.1 + * + * @see org.apache.sis.geometry.Envelopes#wraparound(MathTransform, Envelope) + * + * @since 1.1 * @module */ public class WraparoundTransform extends AbstractMathTransform implements Serializable { diff --git a/core/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java b/core/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java index fe740855aa..5f4967b33e 100644 --- a/core/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java +++ b/core/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java @@ -306,18 +306,18 @@ public final strictfp class EnvelopesTest extends TransformTestCase<GeneralEnvel } /** - * Tests {@link Envelopes#transformWraparounds(MathTransform, Envelope)}. + * Tests {@link Envelopes#wraparound(MathTransform, Envelope)}. * * @throws TransformException if a coordinate transformation failed. */ @Test - public void testTransformWraparounds() throws TransformException { + public void testWraparound() throws TransformException { final GeneralEnvelope envelope = new GeneralEnvelope(HardCodedCRS.WGS84); envelope.setRange(0, -200, -100); envelope.setRange(1, 5, 9); final MathTransform tr = WraparoundTransform.create(2, 0, 360, -180, 0); assertTrue(tr instanceof WraparoundTransform); - final GeneralEnvelope[] results = Envelopes.transformWraparounds(tr, envelope); + final GeneralEnvelope[] results = Envelopes.wraparound(tr, envelope); assertEquals(2, results.length); assertEnvelopeEquals(new GeneralEnvelope(new double[] {-200, 5}, new double[] {-100, 9}), results[0]); assertEnvelopeEquals(new GeneralEnvelope(new double[] { 160, 5}, new double[] { 260, 9}), results[1]);
