sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: API change: rename GridOrientation.HOMOTHETIC as HOMOTHETY. Add an argument in `GridExtent.cornerToCRS(…) for axis order.
Date Thu, 24 Sep 2020 14:44:53 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 246dc017438c8caaff197f5d9ff14c627ceab643
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Sep 24 11:11:54 2020 +0200

    API change: rename GridOrientation.HOMOTHETIC as HOMOTHETY.
    Add an argument in `GridExtent.cornerToCRS(…) for axis order.
---
 .../org/apache/sis/coverage/grid/GridCoverage2D.java   |  2 +-
 .../java/org/apache/sis/coverage/grid/GridExtent.java  | 18 ++++++++++--------
 .../org/apache/sis/coverage/grid/GridGeometry.java     |  4 ++--
 .../org/apache/sis/coverage/grid/GridOrientation.java  |  8 ++++----
 .../sis/coverage/grid/GridCoverageBuilderTest.java     |  4 ++--
 .../org/apache/sis/coverage/grid/GridExtentTest.java   |  6 +++---
 .../org/apache/sis/coverage/grid/GridGeometryTest.java |  2 +-
 .../sis/coverage/grid/ResampledGridCoverageTest.java   |  2 +-
 .../sis/storage/geotiff/GridGeometryBuilder.java       |  2 +-
 9 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
index fe5df02..f846d48 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -304,7 +304,7 @@ public class GridCoverage2D extends GridCoverage {
                 } catch (TransformException e) {
                     throw new IllegalGridGeometryException(e);                  // Should
never happen.
                 } else {
-                    domain = new GridGeometry(extent, domain.envelope, GridOrientation.HOMOTHETIC);
+                    domain = new GridGeometry(extent, domain.envelope, GridOrientation.HOMOTHETY);
                 }
             }
         }
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 503fff0..6b8f174 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
@@ -1348,24 +1348,26 @@ public class GridExtent implements GridEnvelope, LenientComparable,
Serializable
      * This method assumes that all axes are in the same order (no axis swapping) and there
is no flipping of
      * axis direction except for those specified in the {@code flips} bitmask. The transform
maps cell corners.
      *
-     * @param  env    the target envelope. Despite this method name, the envelope CRS is
ignored.
-     * @param  flips  bitmask of axes to flip.
+     * @param  env               the target envelope. Despite this method name, the envelope
CRS is ignored.
+     * @param  flips             bitmask of target axes to flip (0 if none).
+     * @param  sourceDimensions  source dimension for each target dimension, or {@code null}
if dimensions are the same.
      * @return an affine transform from this grid extent to the given envelope, expressed
as a matrix.
      */
-    final MatrixSIS cornerToCRS(final Envelope env, final long flips) {
+    final MatrixSIS cornerToCRS(final Envelope env, final long flips, final int[] sourceDimensions)
{
         final int          srcDim = getDimension();
         final int          tgtDim = env.getDimension();
         final MatrixSIS    affine = Matrices.create(tgtDim + 1, srcDim + 1, ExtendedPrecisionMatrix.ZERO);
         final DoubleDouble scale  = new DoubleDouble();
         final DoubleDouble offset = new DoubleDouble();
         for (int j=0; j<tgtDim; j++) {
-            if (j < srcDim) {
+            final int i = (sourceDimensions != null) ? sourceDimensions[j] : j;
+            if (i < srcDim) {
                 final boolean flip = (flips & Numerics.bitmask(j)) != 0;
-                offset.set(coordinates[j]);
-                scale.set(coordinates[j + srcDim]);
+                offset.set(coordinates[i]);
+                scale.set(coordinates[i + srcDim]);
                 scale.subtract(offset);
                 scale.add(1);                                   // == getSize(j) but without
overflow.
-                scale.inverseDivideGuessError(env.getSpan(j));  // == (envelope span) / (grid
size).
+                scale.inverseDivideGuessError(env.getSpan(i));  // == (envelope span) / (grid
size).
                 if (flip) scale.negate();
                 if (!offset.isZero()) {                         // Use `if` for keeping the
value if scale is NaN.
                     offset.multiply(scale);
@@ -1377,7 +1379,7 @@ public class GridExtent implements GridEnvelope, LenientComparable,
Serializable
                 scale.value = Double.NaN;
                 scale.error = Double.NaN;
             }
-            affine.setNumber(j, j, scale);
+            affine.setNumber(j, i, scale);
         }
         affine.setElement(tgtDim, srcDim, 1);
         return affine;
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index fb91cf6..5ae3434 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -571,7 +571,7 @@ public class GridGeometry implements LenientComparable, Serializable {
      */
     @Deprecated
     public GridGeometry(final GridExtent extent, final Envelope envelope) {
-        this(extent, envelope, GridOrientation.HOMOTHETIC);
+        this(extent, envelope, GridOrientation.HOMOTHETY);
     }
 
     /**
@@ -620,7 +620,7 @@ public class GridGeometry implements LenientComparable, Serializable {
                  * matrix multiplication. Use double-double arithmetic everywhere.
                  */
                 ArgumentChecks.ensureNonNull("orientation", orientation);
-                final MatrixSIS affine = extent.cornerToCRS(env, orientation.flip);
+                final MatrixSIS affine = extent.cornerToCRS(env, orientation.flip, null);
                 cornerToCRS = MathTransforms.linear(affine);
                 final int srcDim = cornerToCRS.getSourceDimensions();       // Translation
column in matrix.
                 final int tgtDim = cornerToCRS.getTargetDimensions();       // Number of
matrix rows before last row.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridOrientation.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridOrientation.java
index 02b2bd1..cff41ae 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridOrientation.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridOrientation.java
@@ -54,15 +54,15 @@ public enum GridOrientation {
      * <var>S<sub>y</sub></var> &gt; 0 and
      * <var>S<sub>z</sub></var> &gt; 0.
      */
-    HOMOTHETIC(0),
+    HOMOTHETY(0),
 
     /**
      * The {@code gridToCRS} transform applies scales and translations with a flip of the
second axis (<var>y</var>).
-     * This is the same kind of conversion than {@link #HOMOTHETIC} except that the <var>S<sub>y</sub></var>
term in
+     * This is the same kind of conversion than {@link #HOMOTHETY} except that the <var>S<sub>y</sub></var>
term in
      * the matrix is replaced by −<var>S<sub>y</sub></var>.
      *
      * <p>{@code REFLECTION_Y} is commonly used when the grid is a {@link java.awt.image.RenderedImage}.
-     * By contrast, an {@link #HOMOTHETIC} transform often results in <var>y</var>
axis oriented toward up,
+     * By contrast, an {@link #HOMOTHETY} transform often results in <var>y</var>
axis oriented toward up,
      * instead of down as commonly expected with rendered images.
      * This {@code REFLECTION_Y} value matches the common usage for grids backed by images.</p>
      */
@@ -74,7 +74,7 @@ public enum GridOrientation {
 
     /**
      * Bitmask of axes to flip.
-     * This is the argument to give in calls to {@link GridExtent#cornerToCRS(Envelope, long)}.
+     * This is the argument to give in calls to {@link GridExtent#cornerToCRS(Envelope, long,
int[])}.
      */
     final int flip;
 
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
index cd5e839..74137f2 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
@@ -139,7 +139,7 @@ public final strictfp class GridCoverageBuilderTest extends TestCase {
         final GeneralEnvelope env = new GeneralEnvelope(HardCodedCRS.WGS84);
         env.setRange(0, 0, 10);     // Scale factor of 2 for grid size of 10.
         env.setRange(1, 0,  4);     // Scale factor of ½ for grid size of 8.
-        GridGeometry grid = new GridGeometry(new GridExtent(8, 5), env, GridOrientation.HOMOTHETIC);
+        GridGeometry grid = new GridGeometry(new GridExtent(8, 5), env, GridOrientation.HOMOTHETY);
         assertSame(builder, builder.setDomain(grid));
         try {
             builder.build();
@@ -147,7 +147,7 @@ public final strictfp class GridCoverageBuilderTest extends TestCase {
         } catch (IllegalStateException ex) {
             assertNotNull(ex.getMessage());
         }
-        grid = new GridGeometry(new GridExtent(width, height), env, GridOrientation.HOMOTHETIC);
+        grid = new GridGeometry(new GridExtent(width, height), env, GridOrientation.HOMOTHETY);
         assertSame(builder, builder.setDomain(grid));
         return builder.build();
     }
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
index a87ffe1..1a67174 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -269,7 +269,7 @@ public final strictfp class GridExtentTest extends TestCase {
     }
 
     /**
-     * Tests {@link GridExtent#cornerToCRS(Envelope, long)}.
+     * Tests {@link GridExtent#cornerToCRS(Envelope, long, int[])}.
      */
     @Test
     public void testCornerToCRS() {
@@ -286,7 +286,7 @@ public final strictfp class GridExtentTest extends TestCase {
         assertMatrixEquals("cornerToCRS", new Matrix3(
                 0.5,  0,   50,
                 0,    2,   40,
-                0,    0,    1), extent.cornerToCRS(aoi, 0), STRICT);
+                0,    0,    1), extent.cornerToCRS(aoi, 0, null), STRICT);
         /*
          * Y axis flip.
          * Verification:  y  =  −2 × −25 + 20  =  70  (the maximum value declared in
envelope).
@@ -294,7 +294,7 @@ public final strictfp class GridExtentTest extends TestCase {
         assertMatrixEquals("cornerToCRS", new Matrix3(
                 0.5,  0,   50,
                 0,   -2,   20,
-                0,    0,    1), extent.cornerToCRS(aoi, 2), STRICT);
+                0,    0,    1), extent.cornerToCRS(aoi, 2, null), STRICT);
     }
 
     /**
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index 8ea4d2d..42acf36 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -343,7 +343,7 @@ public final strictfp class GridGeometryTest extends TestCase {
          * Simplest case: no axis flip.
          * Verification:  y  =  2 × −25 + 40  =  −10  (the minimum value declared in
envelope).
          */
-        GridGeometry grid = new GridGeometry(extent, aoi, GridOrientation.HOMOTHETIC);
+        GridGeometry grid = new GridGeometry(extent, aoi, GridOrientation.HOMOTHETY);
         Matrix matrix = MathTransforms.getMatrix(grid.getGridToCRS(PixelInCell.CELL_CORNER));
         assertMatrixEquals("cornerToCRS", new Matrix3(
                 0.5,  0,   50,
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 7fe355e..fb15991 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
@@ -105,7 +105,7 @@ public final strictfp class ResampledGridCoverageTest extends TestCase
{
         final int y = random.nextInt(32) - 10;
         final GridGeometry gg = new GridGeometry(
                 new GridExtent(null, new long[] {x, y}, new long[] {x+width, y+height}, false),
-                new Envelope2D(HardCodedCRS.WGS84, 20, 15, 60, 62), GridOrientation.HOMOTHETIC);
+                new Envelope2D(HardCodedCRS.WGS84, 20, 15, 60, 62), GridOrientation.HOMOTHETY);
         return new GridCoverage2D(gg, null, image);
     }
 
diff --git a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
index a45aec1..3a6973f 100644
--- a/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
+++ b/storage/sis-geotiff/src/main/java/org/apache/sis/storage/geotiff/GridGeometryBuilder.java
@@ -335,7 +335,7 @@ final class GridGeometryBuilder {
                 envelope = new GeneralEnvelope(crs);
                 envelope.setToNaN();
             }
-            gridGeometry = new GridGeometry(extent, envelope, GridOrientation.HOMOTHETIC);
+            gridGeometry = new GridGeometry(extent, envelope, GridOrientation.HOMOTHETY);
             canNotCreate(e);
             /*
              * Note: we catch TransformExceptions because they may be caused by erroneous
data in the GeoTIFF file,


Mime
View raw message