sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Partial debugging of ResampledGridGeometryTest.crs4D_to_crs3D() test case.
Date Wed, 27 May 2020 17:07:10 GMT
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 35f809711df49567c30f640f37635a1c5ed01458
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed May 27 19:04:45 2020 +0200

    Partial debugging of ResampledGridGeometryTest.crs4D_to_crs3D() test case.
---
 .../sis/coverage/grid/ResampledGridCoverage.java   | 10 +++++
 .../coverage/grid/ResampledGridCoverageTest.java   |  4 +-
 .../sis/referencing/cs/CoordinateSystems.java      | 52 +++++++++++++++++++++-
 .../apache/sis/referencing/cs/package-info.java    |  2 +-
 .../sis/referencing/cs/CoordinateSystemsTest.java  | 15 ++++++-
 5 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
index 6d67c06..f63b4c1 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java
@@ -431,6 +431,16 @@ final class ResampledGridCoverage extends GridCoverage {
         final GridExtent    sourceExtent;
         try {
             final GeneralEnvelope sourceBounds = sliceExtent.toCRS(toSourceCorner, toSourceCenter,
null);
+            if (sourceBounds.isEmpty()) {
+                final GridExtent se = source.gridGeometry.getExtent();
+                for (int i = sourceBounds.getDimension(); --i >= 0;) {
+                    double min = sourceBounds.getMinimum(i);
+                    double max = sourceBounds.getMaximum(i);
+                    if (Double.isNaN(min)) min = se.getLow (i);
+                    if (Double.isNaN(max)) max = se.getHigh(i);
+                    sourceBounds.setRange(i, min, max);
+                }
+            }
             sourceExtent = new GridExtent(sourceBounds, GridRoundingMode.ENCLOSING, null,
null, null);
             final int[] resampledDimensions = sliceExtent.getSubspaceDimensions(BIDIMENSIONAL);
             final int[] sourceDimensions  =  sourceExtent.getSubspaceDimensions(BIDIMENSIONAL);
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
index 8e47a12..5459f18 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/ResampledGridCoverageTest.java
@@ -389,8 +389,8 @@ public final strictfp class ResampledGridCoverageTest extends TestCase
{
          * shall be the lower-left corner of `sliceExtent`, which is (3,3) in this test.
          */
         targetImage = result.render(new GridExtent(3, 3, 2, 2));
-        assertPixelsEqual(sourceImage, new Rectangle (3, 3, 2, 2),
-                          targetImage, new Rectangle (0, 0, 2, 2));
+        assertPixelsEqual(sourceImage, new Rectangle(3, 3, 2, 2),
+                          targetImage, new Rectangle(0, 0, 2, 2));
     }
 
     /**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
index 71cebe3..b61f174 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.referencing.cs;
 
+import java.util.List;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Objects;
 import javax.measure.Unit;
@@ -55,7 +57,7 @@ import org.apache.sis.referencing.operation.matrix.MatrixSIS;
  * between two coordinate systems.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.4
  * @module
  */
@@ -237,6 +239,49 @@ public final class CoordinateSystems extends Static {
     }
 
     /**
+     * Adds all single coordinate systems in the given list.
+     * This method is used for decomposing a coordinate systems into its components.
+     */
+    private static void components(final CoordinateSystem cs, final List<CoordinateSystem>
addTo) {
+        if (cs instanceof DefaultCompoundCS) {
+            for (final CoordinateSystem c : ((DefaultCompoundCS) cs).getComponents()) {
+                components(c, addTo);
+            }
+        } else {
+            addTo.add(cs);
+        }
+    }
+
+    /**
+     * Returns {@code true} if all {@code CoordinateSystem} interfaces of {@code targetCS}
have a counterpart in
+     * {@code sourceCS}. This method is equivalent to {@link Classes#implementSameInterfaces(Class,
Class, Class)}
+     * except that it decomposes {@link DefaultCompoundCS} in its components before to check
the two collections
+     * of interfaces.
+     *
+     * <div class="note"><b>Example:</b>
+     * if {@code sourceCS} is a {@link DefaultCompoundCS} containing {@link EllipsoidalCS}
and a vertical or temporal
+     * coordinate system and {@code targetCS} is an {@link EllipsoidalCS} only, then this
method returns {@code true}.
+     * But if {@code targetCS} is a {@link CartesianCS} or contains any other CS which is
not a component of source CS,
+     * then this method returns {@code false}.</div>
+     */
+    static boolean hasAllTargetTypes(final CoordinateSystem sourceCS, final CoordinateSystem
targetCS) {
+        final List<CoordinateSystem> sources = new ArrayList<>(sourceCS.getDimension());
+        final List<CoordinateSystem> targets = new ArrayList<>(targetCS.getDimension());
+        components(sourceCS, sources);
+        components(targetCS, targets);
+next:   for (final CoordinateSystem cs : targets) {
+            for (int i=0; i<sources.size(); i++) {
+                if (Classes.implementSameInterfaces(sources.get(i).getClass(), cs.getClass(),
CoordinateSystem.class)) {
+                    sources.remove(i);
+                    continue next;
+                }
+            }
+            return false;           // Found no `sourceCS` component for at least one of
the `targetCS` components.
+        }
+        return true;
+    }
+
+    /**
      * Returns an affine transform between two coordinate systems.
      * Only units and axes order (e.g. transforming from
      * ({@linkplain AxisDirection#NORTH North}, {@linkplain AxisDirection#WEST West}) to
@@ -279,7 +324,10 @@ public final class CoordinateSystems extends Static {
         ArgumentChecks.ensureNonNull("sourceCS", sourceCS);
         ArgumentChecks.ensureNonNull("targetCS", targetCS);
         if (!Classes.implementSameInterfaces(sourceCS.getClass(), targetCS.getClass(), CoordinateSystem.class))
{
-            throw new IllegalArgumentException(Resources.format(Resources.Keys.IncompatibleCoordinateSystemTypes));
+            // Above line was a relatively cheap test. Try the more expansive test below
only if necessary.
+            if (!hasAllTargetTypes(sourceCS, targetCS)) {
+                throw new IllegalArgumentException(Resources.format(Resources.Keys.IncompatibleCoordinateSystemTypes));
+            }
         }
         final AxisDirection[] srcAxes = getAxisDirections(sourceCS);
         final AxisDirection[] dstAxes = getAxisDirections(targetCS);
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
index 1eba4b9..2b24494 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
@@ -33,7 +33,7 @@
  * and units between two coordinate systems, or filtering axes.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.8
+ * @version 1.1
  * @since   0.4
  * @module
  */
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
index 0efb380..c8d00ec 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/CoordinateSystemsTest.java
@@ -46,7 +46,7 @@ import static org.apache.sis.test.Assert.*;
  * Tests the {@link CoordinateSystems} class.
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 1.0
+ * @version 1.1
  * @since   0.4
  * @module
  */
@@ -160,6 +160,19 @@ public final strictfp class CoordinateSystemsTest extends TestCase {
     }
 
     /**
+     * Tests {@link CoordinateSystems#hasAllTargetTypes(CoordinateSystem, CoordinateSystem)}.
+     */
+    @Test
+    public void testHasAllTargetTypes() {
+        final DefaultCompoundCS cs = new DefaultCompoundCS(HardCodedCS.GEODETIC_2D, HardCodedCS.GRAVITY_RELATED_HEIGHT);
+        assertTrue (CoordinateSystems.hasAllTargetTypes(cs, HardCodedCS.GRAVITY_RELATED_HEIGHT));
+        assertFalse(CoordinateSystems.hasAllTargetTypes(cs, HardCodedCS.DAYS));
+        assertTrue (CoordinateSystems.hasAllTargetTypes(cs, HardCodedCS.GEODETIC_2D));
+        assertFalse(CoordinateSystems.hasAllTargetTypes(cs, HardCodedCS.CARTESIAN_2D));
+        assertTrue (CoordinateSystems.hasAllTargetTypes(cs, cs));
+    }
+
+    /**
      * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
for (λ,φ) ↔ (φ,λ).
      * This very common conversion is of critical importance to Apache SIS.
      *


Mime
View raw message