sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Add a MathTransforms.translation(double...) method, together with a TranslationTransform internal implementation.
Date Fri, 14 Dec 2018 13:29:15 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 ea9b376fd69ec3bf2dc11307a48038ae86dfd3c8
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Dec 14 13:16:47 2018 +0100

    Add a MathTransforms.translation(double...) method, together with a TranslationTransform
internal implementation.
---
 .../apache/sis/coverage/grid/PixelTranslation.java |  15 ++-
 .../operation/transform/MathTransforms.java        |  15 +++
 .../operation/transform/ProjectiveTransform.java   |  25 +++-
 .../operation/transform/ScaleTransform.java        |   7 +-
 ...aleTransform.java => TranslationTransform.java} | 136 +++++++++------------
 .../transform/TranslationTransformTest.java        | 114 +++++++++++++++++
 .../sis/test/suite/ReferencingTestSuite.java       |   1 +
 7 files changed, 220 insertions(+), 93 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/PixelTranslation.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/PixelTranslation.java
index d63564b..4dfd58e 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/PixelTranslation.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/PixelTranslation.java
@@ -18,6 +18,7 @@ package org.apache.sis.coverage.grid;
 
 import java.util.Map;
 import java.util.HashMap;
+import java.util.Arrays;
 import java.io.Serializable;
 
 import org.opengis.referencing.operation.Matrix;
@@ -338,22 +339,20 @@ public final class PixelTranslation extends Static implements Serializable
{
     }
 
     /**
-     * Creates an affine transform that apply the same linear conversion for all dimensions.
+     * Creates an affine transform that apply the same translation for all dimensions.
      * For each dimension, input values <var>x</var> are converted into output
values <var>y</var>
      * using the following equation:
      *
-     * <blockquote><var>y</var> &nbsp;=&nbsp; <var>x</var>
× {@code scale} + {@code offset}</blockquote>
+     * <blockquote><var>y</var> = <var>x</var> + {@code offset}</blockquote>
      *
      * @param  dimension  the input and output dimensions.
      * @param  offset     the {@code offset} term in the linear equation.
-     * @return the linear transform for the given scale and offset.
+     * @return the linear transform for the given offset.
      */
     private static MathTransform translate(final int dimension, final double offset) {
-        final Matrix matrix = Matrices.createIdentity(dimension + 1);
-        for (int i=0; i<dimension; i++) {
-            matrix.setElement(i, dimension, offset);
-        }
-        return MathTransforms.linear(matrix);
+        final double[] vector = new double[dimension];
+        Arrays.fill(vector, offset);
+        return MathTransforms.translation(vector);
     }
 
     /**
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 0236156..6ad3162 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
@@ -88,6 +88,21 @@ public final class MathTransforms extends Static {
     }
 
     /**
+     * Creates a transform which applies the given translation.
+     * The source and target dimensions of the transform are the length of the given vector.
+     *
+     * @param  vector  the translation vector.
+     * @return a transform applying the given translation.
+     *
+     * @since 1.0
+     */
+    public static LinearTransform translation(final double... vector) {
+        ArgumentChecks.ensureNonNull("vector", vector);
+        TranslationTransform tr = new TranslationTransform(vector);
+        return tr.isIdentity() ? identity(vector.length) : tr;
+    }
+
+    /**
      * Creates a one-dimensional affine transform for the given coefficients.
      * Input values <var>x</var> will be converted into output values <var>y</var>
using the following equation:
      *
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
index 6a61047..fe6fec3 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
@@ -97,7 +97,7 @@ class ProjectiveTransform extends AbstractLinearTransform implements ExtendedPre
             return this;
         }
         final int n = (numRow - 1) * numCol;
-        for (int i = 0; i != numCol;) {
+        for (int i = 0; i < numCol;) {
             if (elt[n + i] != (++i == numCol ? 1 : 0)) {
                 return this;            // Transform is not affine (ignoring if square or
not).
             }
@@ -105,14 +105,29 @@ class ProjectiveTransform extends AbstractLinearTransform implements
ExtendedPre
         /*
          * Note: we could check for CopyTransform case here, but this check is rather done
in
          * MathTransforms.linear(Matrix) in order to avoid ProjectiveTransform instantiation.
+         *
+         * Check which elements are non-zero. For ScaleTransform, they must be on the diagonal.
+         * For TranslationTransform, they must be in the last column. Note that the transform
+         * should not be identity (except for testing purpose) since the identity case should
+         * have been handled by MathTransforms.linear(Matrix) before to reach this point.
          */
+        boolean isScale       = true;                       // ScaleTransform accepts non-square
matrix.
+        boolean isTranslation = (numRow == numCol);         // TranslationTransform is restricted
to square matrix.
         for (int i=0; i<n; i++) {
-            // Non-zero elements are allowed to appear only on the diagonal.
-            if (elt[i] != 0 && (i / numCol) != (i % numCol)) {
-                return this;
+            if (elt[i] != 0) {
+                final int col  = (i % numCol);
+                isScale       &= (i / numCol) == col;
+                isTranslation &= (col == numCol - 1);
+                if (!(isScale | isTranslation)) {
+                    return this;
+                }
             }
         }
-        return new ScaleTransform(numRow, numCol, elt);
+        if (isTranslation) {
+            return new TranslationTransform(numRow, elt);
+        } else {
+            return new ScaleTransform(numRow, numCol, elt);
+        }
     }
 
     /**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
index 309969d..429c98e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
@@ -73,17 +73,18 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
     ScaleTransform(final int numRow, final int numCol, final double[] elements) {
         numDroppedDimensions = numCol - numRow;
         final int n = numRow * numCol;
-        factors = new double[numRow - 1];
+        final int tgtDim = numRow - 1;
+        factors = new double[tgtDim];
         double[] errors = null;
         int lastError = -1;
-        for (int i=0; i<factors.length; i++) {
+        for (int i=0; i<tgtDim; i++) {
             int j = numCol*i + i;
             factors[i] = elements[j];
             if ((j += n) < elements.length) {
                 final double e = elements[j];
                 if (e != 0) {
                     if (errors == null) {
-                        errors = new double[numRow];
+                        errors = new double[tgtDim];
                     }
                     errors[i] = e;
                     lastError = i;
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
similarity index 67%
copy from core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
copy to core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
index 309969d..fbf79a0 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ScaleTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TranslationTransform.java
@@ -20,70 +20,70 @@ import java.util.Arrays;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.referencing.operation.matrix.Matrices;
-import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.internal.referencing.ExtendedPrecisionMatrix;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ArraysExt;
 
 
 /**
- * An affine transform that multiply the ordinate values by constant values, and optionally
drop the last ordinates.
- * This is an optimization of {@link ProjectiveTransform} for a common case.
+ * An affine transform that translate the ordinate values by constant values.
  *
  * <div class="note"><b>Note:</b> we do not provide two-dimensional specialization
because
  * {@link org.apache.sis.internal.referencing.j2d.AffineTransform2D} should be used in such
case.</div>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 1.0
  *
  * @see <a href="http://issues.apache.org/jira/browse/SIS-176">SIS-176</a>
  *
- * @since 0.7
+ * @since 1.0
  * @module
  */
-final class ScaleTransform extends AbstractLinearTransform implements ExtendedPrecisionMatrix
{
+final class TranslationTransform extends AbstractLinearTransform implements ExtendedPrecisionMatrix
{
     /**
      * Serial number for inter-operability with different versions.
      */
-    private static final long serialVersionUID = 8527439133082104085L;
+    private static final long serialVersionUID = 7382503993222285134L;
 
     /**
-     * Multiplication factors, to be applied in the same order than ordinate values.
+     * Translation terms, to be applied in the same order than ordinate values.
      * The length of this array is the number of target dimensions.
      */
-    private final double[] factors;
+    private final double[] offsets;
 
     /**
      * The error terms in double-double arithmetic, or {@code null} if none.
-     * May be shorter than {@code factors} if all remaining errors are zero.
+     * May be shorter than {@code offsets} if all remaining errors are zero.
      */
     private final double[] errors;
 
     /**
-     * Number of ordinate values to drop after the values that we multiplied.
-     * Values to drop happen for example in Geographic 3D to 2D conversions.
+     * Constructs a translation transform for the given offset vector.
      */
-    private final int numDroppedDimensions;
+    TranslationTransform(final double[] offsets) {
+        this.offsets = offsets.clone();
+        this.errors  = null;
+    }
 
     /**
-     * Constructs a scale transform from a matrix having the given elements.
-     * This constructors assumes that the matrix is affine and contains only
-     * scale coefficients (this is not verified).
+     * Constructs a translation transform from a matrix having the given elements.
+     * This constructors assumes that the matrix is square, affine and contains only
+     * translation terms (this is not verified).
      */
-    ScaleTransform(final int numRow, final int numCol, final double[] elements) {
-        numDroppedDimensions = numCol - numRow;
-        final int n = numRow * numCol;
-        factors = new double[numRow - 1];
+    TranslationTransform(final int size, final double[] elements) {
+        final int n = size * size;
+        final int dim = size - 1;
+        offsets = new double[dim];
         double[] errors = null;
         int lastError = -1;
-        for (int i=0; i<factors.length; i++) {
-            int j = numCol*i + i;
-            factors[i] = elements[j];
+        for (int i=0; i<dim; i++) {
+            int j = dim + i*size;
+            offsets[i] = elements[j];
             if ((j += n) < elements.length) {
                 final double e = elements[j];
                 if (e != 0) {
                     if (errors == null) {
-                        errors = new double[numRow];
+                        errors = new double[dim];
                     }
                     errors[i] = e;
                     lastError = i;
@@ -98,12 +98,14 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     public double[] getExtendedElements() {
+        final int dim = offsets.length;
         final int numCol = getNumCol();
         final int n = getNumRow() * numCol;
         final double[] elements = new double[(errors == null) ? n : (n << 1)];
-        for (int i=0; i<factors.length; i++) {
-            final int j = numCol*i + i;
-            elements[j] = factors[i];
+        for (int i=0; i<dim; i++) {
+            int j = i*numCol;
+            elements[j +    i] = 1;
+            elements[j += dim] = offsets[i];
             if (errors != null && i < errors.length) {
                 elements[j + n] = errors[i];
             }
@@ -117,7 +119,7 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     public int getSourceDimensions() {
-        return factors.length + numDroppedDimensions;
+        return offsets.length;
     }
 
     /**
@@ -125,7 +127,7 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     public int getTargetDimensions() {
-        return factors.length;
+        return offsets.length;
     }
 
     /**
@@ -133,32 +135,25 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     public double getElement(final int row, final int column) {
-        final int dstDim = factors.length;
-        final int srcDim = dstDim + numDroppedDimensions;
-        ArgumentChecks.ensureBetween("row",    0, dstDim, row);
-        ArgumentChecks.ensureBetween("column", 0, srcDim, column);
-        if (row == dstDim) {
-            return (column == srcDim) ? 1 : 0;
+        final int dim = offsets.length;
+        ArgumentChecks.ensureBetween("row",    0, dim, row);
+        ArgumentChecks.ensureBetween("column", 0, dim, column);
+        if (column == row) {
+            return 1;
+        } else if (column == dim) {
+            return offsets[row];
         } else {
-            return (row == column) ? factors[row] : 0;
+            return 0;
         }
     }
 
     /**
      * Tests whether this transform does not move any points.
-     *
-     * <div class="note"><b>Note:</b> this method should always returns
{@code false}, since
-     * {@code MathTransforms.linear(…)} should have created specialized implementations
for identity cases.
-     * Nevertheless we perform the full check as a safety, in case someone instantiated this
class directly
-     * instead than using a factory method.</div>
      */
     @Override
     public boolean isIdentity() {
-        if (numDroppedDimensions != 0) {
-            return false;
-        }
-        for (int i=0; i<factors.length; i++) {
-            if (factors[i] != 1) {
+        for (int i=0; i<offsets.length; i++) {
+            if (offsets[i] != 0) {
                 return false;
             }
         }
@@ -199,18 +194,16 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
     @Override
     public void transform(double[] srcPts, int srcOff, final double[] dstPts, int dstOff,
int numPts) {
         if (srcPts == dstPts) {
-            final int dstDim = factors.length;
-            final int srcDim = dstDim + numDroppedDimensions;
-            if (IterationStrategy.suggest(srcOff, srcDim, dstOff, dstDim, numPts) != IterationStrategy.ASCENDING)
{
-                srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*srcDim);
+            final int dim = offsets.length;
+            if (IterationStrategy.suggest(srcOff, dim, dstOff, dim, numPts) != IterationStrategy.ASCENDING)
{
+                srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*dim);
                 srcOff = 0;
             }
         }
         while (--numPts >= 0) {
-            for (int i=0; i<factors.length; i++) {
-                dstPts[dstOff++] = srcPts[srcOff++] * factors[i];
+            for (int i=0; i<offsets.length; i++) {
+                dstPts[dstOff++] = srcPts[srcOff++] + offsets[i];
             }
-            srcOff += numDroppedDimensions;
         }
     }
 
@@ -233,18 +226,16 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
     @Override
     public void transform(float[] srcPts, int srcOff, final float[] dstPts, int dstOff, int
numPts) {
         if (srcPts == dstPts) {
-            final int dstDim = factors.length;
-            final int srcDim = dstDim + numDroppedDimensions;
-            if (IterationStrategy.suggest(srcOff, srcDim, dstOff, dstDim, numPts) != IterationStrategy.ASCENDING)
{
-                srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*srcDim);
+            final int dim = offsets.length;
+            if (IterationStrategy.suggest(srcOff, dim, dstOff, dim, numPts) != IterationStrategy.ASCENDING)
{
+                srcPts = Arrays.copyOfRange(srcPts, srcOff, srcOff + numPts*dim);
                 srcOff = 0;
             }
         }
         while (--numPts >= 0) {
-            for (int i=0; i<factors.length; i++) {
-                dstPts[dstOff++] = (float) (srcPts[srcOff++] * factors[i]);
+            for (int i=0; i<offsets.length; i++) {
+                dstPts[dstOff++] = (float) (srcPts[srcOff++] + offsets[i]);
             }
-            srcOff += numDroppedDimensions;
         }
     }
 
@@ -260,10 +251,9 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
     @Override
     public void transform(final double[] srcPts, int srcOff, final float[] dstPts, int dstOff,
int numPts) {
         while (--numPts >= 0) {
-            for (int i=0; i<factors.length; i++) {
-                dstPts[dstOff++] = (float) (srcPts[srcOff++] * factors[i]);
+            for (int i=0; i<offsets.length; i++) {
+                dstPts[dstOff++] = (float) (srcPts[srcOff++] + offsets[i]);
             }
-            srcOff += numDroppedDimensions;
         }
     }
 
@@ -279,10 +269,9 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
     @Override
     public void transform(final float[] srcPts, int srcOff, final double[] dstPts, int dstOff,
int numPts) {
         while (--numPts >= 0) {
-            for (int i=0; i<factors.length; i++) {
-                dstPts[dstOff++] = srcPts[srcOff++] * factors[i];
+            for (int i=0; i<offsets.length; i++) {
+                dstPts[dstOff++] = srcPts[srcOff++] + offsets[i];
             }
-            srcOff += numDroppedDimensions;
         }
     }
 
@@ -294,12 +283,7 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     public Matrix derivative(final DirectPosition point) {
-        final int n = factors.length;
-        final MatrixSIS matrix = Matrices.createZero(n, n + numDroppedDimensions);
-        for (int i=0; i<n; i++) {
-            matrix.setElement(i, i, factors[i]);
-        }
-        return matrix;
+        return Matrices.createIdentity(offsets.length);
     }
 
     /**
@@ -309,7 +293,7 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     protected int computeHashCode() {
-        return Arrays.hashCode(factors) + 31 * super.computeHashCode();
+        return Arrays.hashCode(offsets) + 31 * super.computeHashCode();
     }
 
     /**
@@ -317,9 +301,7 @@ final class ScaleTransform extends AbstractLinearTransform implements
ExtendedPr
      */
     @Override
     protected boolean equalsSameClass(final Object object) {
-        final ScaleTransform that = (ScaleTransform) object;
-        return numDroppedDimensions == that.numDroppedDimensions
-               && Arrays.equals(factors, that.factors)
-               && Arrays.equals(errors,  that.errors);
+        final TranslationTransform that = (TranslationTransform) object;
+        return Arrays.equals(offsets, that.offsets) && Arrays.equals(errors, that.errors);
     }
 }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TranslationTransformTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TranslationTransformTest.java
new file mode 100644
index 0000000..ae4c4aa
--- /dev/null
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TranslationTransformTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.operation.transform;
+
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.referencing.operation.matrix.MatrixSIS;
+import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.referencing.operation.matrix.Matrix4;
+import org.apache.sis.internal.referencing.ExtendedPrecisionMatrix;
+import org.apache.sis.internal.util.DoubleDouble;
+
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.DependsOn;
+import org.opengis.test.Assert;
+import org.junit.Test;
+
+import static org.opengis.test.Assert.*;
+
+
+/**
+ * Tests the {@link TranslationTransform} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+@DependsOn(AbstractMathTransformTest.class)
+public final strictfp class TranslationTransformTest extends MathTransformTestCase {
+    /**
+     * Sets the {@link #transform} field to the {@link TranslationTransform} instance to
test.
+     *
+     * @param  dimensions  expected number of source and target dimensions.
+     * @param  matrix      the data to use for creating the transform.
+     */
+    private void create(final int dimensions, final MatrixSIS matrix) {
+        final double[] elements = matrix.getElements();
+        final TranslationTransform tr = new TranslationTransform(matrix.getNumRow(), elements);
+        assertEquals("sourceDimensions", dimensions, tr.getSourceDimensions());
+        assertEquals("targetDimensions", dimensions, tr.getTargetDimensions());
+        Assert.assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
+        assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
+        transform = tr;
+        validate();
+    }
+
+    /**
+     * Tests a transform created from a square matrix with no error terms.
+     *
+     * @throws TransformException should never happen.
+     */
+    @Test
+    public void testConstantDimension() throws TransformException {
+        create(3, new Matrix4(
+                1, 0, 0, 2,
+                0, 1, 0, 3,
+                0, 0, 1, 8,
+                0, 0, 0, 1));
+
+        verifyTransform(new double[] {1,1,1,   6, 0,  2,   2, Double.NaN,  6},
+                        new double[] {3,4,9,   8, 3, 10,   4, Double.NaN, 14});
+    }
+
+    /**
+     * Verifies that {@link TranslationTransform} stores the error terms when they exist.
+     */
+    @Test
+    @DependsOnMethod("testConstantDimension")
+    public void testExtendedPrecision() {
+        final Number O = 0;
+        final Number l = 1;
+        final DoubleDouble r = DoubleDouble.createDegreesToRadians();
+        final MatrixSIS matrix = Matrices.create(4, 4, new Number[] {
+            l, O, O, r,
+            O, l, O, r,
+            O, O, l, O,
+            O, O, O, l
+        });
+        final double[] elements = ((ExtendedPrecisionMatrix) matrix).getExtendedElements();
+        assertTrue (r.value > r.error);
+        assertFalse(r.error == 0);          // Paranoiac checks for making sure that next
assertion will test something.
+        assertArrayEquals(new double[] {    // Paranoiac check for making sure that getExtendedElements()
is not broken.
+                1, 0, 0, r.value,
+                0, 1, 0, r.value,
+                0, 0, 1, 0,
+                0, 0, 0, 1,
+                0, 0, 0, r.error,
+                0, 0, 0, r.error,
+                0, 0, 0, 0,
+                0, 0, 0, 0}, elements, 0);
+
+        final TranslationTransform tr = new TranslationTransform(4, elements);
+        assertEquals("sourceDimensions", 3, tr.getSourceDimensions());
+        assertEquals("targetDimensions", 3, tr.getTargetDimensions());
+        Assert.assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
+        assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
+        transform = tr;
+        validate();
+    }
+}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
index b90206e..c50883b 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
@@ -110,6 +110,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.operation.transform.CoordinateDomainTest.class,
     org.apache.sis.referencing.operation.transform.IterationStrategyTest.class,
     org.apache.sis.referencing.operation.transform.AbstractMathTransformTest.class,
+    org.apache.sis.referencing.operation.transform.TranslationTransformTest.class,
     org.apache.sis.referencing.operation.transform.ScaleTransformTest.class,
     org.apache.sis.referencing.operation.transform.ProjectiveTransformTest.class,
     org.apache.sis.referencing.operation.transform.LinearTransformTest.class,


Mime
View raw message