sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: MathTransforms.translation(double...) shall return a MathTransform2D instance when vector length is 2. Add author name in GridResource for the part about grouping related sample dimensions together.
Date Fri, 21 Dec 2018 18:11:07 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 15f1424  MathTransforms.translation(double...) shall return a MathTransform2D instance
when vector length is 2. Add author name in GridResource for the part about grouping related
sample dimensions together.
15f1424 is described below

commit 15f1424a97cc9d333f21d47c0791bd2c2a860c4d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Dec 21 19:10:05 2018 +0100

    MathTransforms.translation(double...) shall return a MathTransform2D instance when vector
length is 2.
    Add author name in GridResource for the part about grouping related sample dimensions
together.
---
 .../referencing/operation/transform/MathTransforms.java  | 10 ++++++++--
 .../operation/transform/MathTransformsTest.java          | 16 ++++++++++++++++
 .../java/org/apache/sis/storage/netcdf/GridResource.java |  1 +
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
index 6ad3162..dfdc469 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
@@ -98,8 +98,14 @@ public final class MathTransforms extends Static {
      */
     public static LinearTransform translation(final double... vector) {
         ArgumentChecks.ensureNonNull("vector", vector);
-        TranslationTransform tr = new TranslationTransform(vector);
-        return tr.isIdentity() ? identity(vector.length) : tr;
+        final LinearTransform tr;
+        switch (vector.length) {
+            case 0:  return IdentityTransform.create(0);
+            case 1:  tr = new LinearTransform1D(1, vector[0]); break;
+            case 2:  tr = new AffineTransform2D(1, 0, 0, 1, vector[0], vector[1]); break;
+            default: tr = new TranslationTransform(vector); break;
+        }
+        return tr.isIdentity() ? IdentityTransform.create(vector.length) : tr;
     }
 
     /**
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
index b500d91..c8dce85 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/MathTransformsTest.java
@@ -20,6 +20,8 @@ import java.util.List;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransform1D;
+import org.opengis.referencing.operation.MathTransform2D;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.operation.matrix.Matrices;
 import org.apache.sis.referencing.operation.matrix.Matrix2;
@@ -196,4 +198,18 @@ public final strictfp class MathTransformsTest extends TestCase {
         DirectPosition actual = linear.transform(pos, null);
         assertEquals(expected, actual);
     }
+
+    /**
+     * Tests the interfaces implemented by the transforms returned by {@link MathTransforms#translation(double...)}.
+     */
+    @Test
+    public void testTranslation() {
+        MathTransform tr = MathTransforms.translation(4);
+        assertInstanceOf("1D", MathTransform1D.class, tr);
+        assertFalse("isIdentity", tr.isIdentity());
+
+        tr = MathTransforms.translation(4, 7);
+        assertInstanceOf("2D", MathTransform2D.class, tr);
+        assertFalse("isIdentity", tr.isIdentity());
+    }
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
index 1e803cb..8737d0e 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/GridResource.java
@@ -57,6 +57,7 @@ import ucar.nc2.constants.CDM;                      // We use only String
consta
  * the <var>u</var> and <var>v</var> components of wind vectors).
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module


Mime
View raw message