sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1735169 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/operation/matrix/ main/java/org/apache/sis/referencing/operation/transform/ test/java/org/apache/sis/refer...
Date Tue, 15 Mar 2016 21:18:03 GMT
Author: desruisseaux
Date: Tue Mar 15 21:18:03 2016
New Revision: 1735169

URL: http://svn.apache.org/viewvc?rev=1735169&view=rev
Log:
Improvement: EllipsoidToCentric delegate to SphericalToCartesian when the given Ellipsoid
is actually a sphere.
Improvement: NonSquareMatrix need to omit rows containing only a translation term if and only
if the last row is [0 0 ... 0 1].
Bug fix: ProjectiveTransform should not delegate to ScaleTransform when the matrix has less
columns than rows (the matrix looks like diagonal but is not).
Bug fix: missing RangeMeaning enumeration value when creating the axis for geocentric radius
(this was causing the build to fail on Jenkins).


Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -394,6 +394,7 @@ final class StandardDefinitions {
                        abrv = "r";                          // See HardCodedAxes.GEOCENTRIC_RADIUS
in tests.
                        unit = SI.METRE;
                        dir  = AxisDirection.UP;
+                       rm   = RangeMeaning.EXACT;
                        min  = 0;
                        break;
             case 108:  // Used in Ellipsoidal 3D.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -191,7 +191,7 @@ class GeneralMatrix extends MatrixSIS im
      */
     static int indexOfErrors(final int numRow, final int numCol, final double[] elements)
{
         assert elements.length % (numRow * numCol) == 0;
-        return (numRow * numCol) % elements.length; // A % B is for getting 0 without branching
if A == B.
+        return (numRow * numCol) % elements.length;         // A % B is for getting 0 without
branching if A == B.
     }
 
     /**
@@ -337,7 +337,7 @@ class GeneralMatrix extends MatrixSIS im
                 if (copy) {
                     elements = elements.clone();
                 }
-                return elements; // Internal array already uses extended precision.
+                return elements;                                // Internal array already
uses extended precision.
             } else {
                 elements = Arrays.copyOf(elements, length);
             }
@@ -415,7 +415,7 @@ class GeneralMatrix extends MatrixSIS im
      * @see Matrices#create(int, int, Number[])
      */
     final boolean setElements(final Number[] newValues) {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numRow = this.numRow;                         // Protection against accidental
changes.
         final int numCol = this.numCol;
         final int length = numRow * numCol;
         if (newValues.length != length) {
@@ -494,9 +494,18 @@ class GeneralMatrix extends MatrixSIS im
      */
     @Override
     public final boolean isAffine() {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        return isAffine(true);
+    }
+
+    /**
+     * Implementation of {@link #isAffine()} with control on whether we require the matrix
to be square.
+     *
+     * @param square {@code true} if the matrix must be square, or {@code false} for allowing
non-square matrices.
+     */
+    final boolean isAffine(final boolean square) {
+        final int numRow = this.numRow;                     // Protection against accidental
changes.
         final int numCol = this.numCol;
-        if (numRow == numCol) {
+        if (numRow == numCol || !square) {
             int i = numRow * numCol;
             if (elements[--i] == 1) {
                 final int base = (numRow - 1) * numCol;
@@ -526,7 +535,7 @@ class GeneralMatrix extends MatrixSIS im
      */
     @Override
     public final boolean isIdentity() {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numRow = this.numRow;                     // Protection against accidental
changes.
         final int numCol = this.numCol;
         if (numRow != numCol) {
             return false;
@@ -553,9 +562,9 @@ class GeneralMatrix extends MatrixSIS im
      */
     @Override
     public void transpose() {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numRow = this.numRow;                                 // Protection against
accidental changes.
         final int numCol = this.numCol;
-        final int errors = indexOfErrors(numRow, numCol, elements); // Where error values
start, or 0 if none.
+        final int errors = indexOfErrors(numRow, numCol, elements);     // Where error values
start, or 0 if none.
         for (int j=0; j<numRow; j++) {
             for (int i=0; i<j; i++) {
                 final int lo = j*numCol + i;
@@ -574,7 +583,7 @@ class GeneralMatrix extends MatrixSIS im
      * The matrix sizes much match - this is not verified unless assertions are enabled.
      */
     final void setToProduct(final Matrix A, final Matrix B) {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numRow = this.numRow;         // Protection against accidental changes.
         final int numCol = this.numCol;
         final int nc = A.getNumCol();
         assert B.getNumRow() == nc;
@@ -597,20 +606,20 @@ class GeneralMatrix extends MatrixSIS im
             for (int i=0; i<numCol; i++) {
                 sum.clear();
                 double max = 0;
-                int iB = i;       // Index of values in a single column of B.
-                int iA = j * nc;  // Index of values in a single row of A.
+                int iB = i;                                 // Index of values in a single
column of B.
+                int iA = j * nc;                            // Index of values in a single
row of A.
                 final int nextRow = iA + nc;
                 while (iA < nextRow) {
                     dot.setFrom (eltA, iA, errA);
                     dot.multiply(eltB, iB, errB);
                     sum.add(dot);
-                    iB += numCol; // Move to next row of B.
-                    iA++;         // Move to next column of A.
+                    iB += numCol;                           // Move to next row of B.
+                    iA++;                                   // Move to next column of A.
                     final double value = Math.abs(dot.value);
                     if (value > max) max = value;
                 }
                 if (Math.abs(sum.value) < Math.ulp(max) * ZERO_THRESHOLD) {
-                    sum.clear(); // Sum is not significant according double arithmetic.
+                    sum.clear();                            // Sum is not significant according
double arithmetic.
                 }
                 sum.storeTo(elements, k++, errorOffset);
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -227,28 +227,39 @@ next:   do {
     }
 
     /**
-     * Inverse a matrix for a transform where target points has more ordinates than source
points.
+     * Inverses a matrix for a transform where target points has more ordinates than source
points.
      * In other words, the target matrices will be a transform that discard some ordinate
values.
      * We will discard the ones for which the row contains only 0 or NaN elements.
+     *
+     * <p>In the special case where the last row is of the form [0 0 … 0 1] as in
affine transforms,
+     * this method also omits rows that contain only a translation term. We allow that because
if we
+     * do not omit those rows, then the matrix will be non-invertible anyway. This is true
only when
+     * the last row contains only zero except in the last column ([0 0 … 0 n] where <var>n</var>
can
+     * be any value). We restrict <var>n</var> to 1 for now because a different
value may indicate a
+     * matrix created for another purpose than coordinate conversions.</p>
      */
     private MatrixSIS inverseDimensionIncrease() throws NoninvertibleMatrixException {
-        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numRow = this.numRow;                     // Protection against accidental
changes.
         final int numCol = this.numCol;
         int j  = numRow;
-        int oi = numRow - numCol; // Initialized to the maximal amount of rows that we may
discard.
+        int oi = numRow - numCol;   // Initialized to the maximal amount of rows that we
may discard.
         final int[] omitted = new int[oi];
+        final boolean ignoreTranslation = isAffine(false);
+        if (ignoreTranslation) j--;                         // Last row already verified
by isAffine().
 next:   do {
             if (--j < 0) {
-                throw nonInvertible(); // Not enough rows that we can omit.
+                throw nonInvertible();                      // Not enough rows that we can
omit.
             }
             final int offset = j * numCol;
-            for (int i=offset + numCol; --i >= offset;) {
+            int i = offset + numCol;
+            if (ignoreTranslation) i--;
+            while (--i >= offset) {
                 final double element = elements[i];
                 if (element != 0 && !Double.isNaN(element)) {
                     continue next;
                 }
             }
-            omitted[--oi] = j; // Found a row which contains only 0 or NaN elements.
+            omitted[--oi] = j;                  // Found a row which contains only 0 or NaN
elements.
         } while (oi != 0);
         /*
          * Found enough rows containing only zero elements. Create a square matrix omitting
those rows,
@@ -258,7 +269,7 @@ next:   do {
         int i = 0;
         for (j=0; j<numRow; j++) {
             if (oi != omitted.length && j == omitted[oi]) oi++;
-            else copyRow(this, j, squareMatrix, i++); // Copy only if not skipped.
+            else copyRow(this, j, squareMatrix, i++);                   // Copy only if not
skipped.
         }
         if (indexOfErrors(numRow, numCol, elements) == 0) {
             inferErrors(squareMatrix.elements);
@@ -329,6 +340,7 @@ next:   do {
      * {@inheritDoc}
      */
     @Override
+    @SuppressWarnings("CloneDoesntCallSuperClone")
     public MatrixSIS clone() {
         return new NonSquareMatrix(this);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransform.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -46,6 +46,7 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.referencing.provider.GeocentricToGeographic;
 import org.apache.sis.internal.referencing.provider.GeographicToGeocentric;
 import org.apache.sis.internal.referencing.provider.Geographic3Dto2D;
+import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
 import org.apache.sis.metadata.iso.ImmutableIdentifier;
 import org.apache.sis.referencing.operation.matrix.Matrix3;
@@ -347,6 +348,19 @@ public class EllipsoidToCentricTransform
             final double semiMajor, final double semiMinor, final Unit<Length> unit,
             final boolean withHeight, final TargetType target) throws FactoryException
     {
+        if (Math.abs(semiMajor - semiMinor) <= semiMajor * (Formulas.LINEAR_TOLERANCE
/ ReferencingServices.AUTHALIC_RADIUS)) {
+            /*
+             * If semi-major axis length is almost equal to semi-minor axis length, uses
spherical equations instead.
+             * We need to add the sphere radius to the elevation before to perform spherical
to Cartesian conversion.
+             */
+            final MatrixSIS translate = Matrices.createDiagonal(4, withHeight ? 4 : 3);
+            translate.setElement(2, withHeight ? 3 : 2, semiMajor);
+            if (!withHeight) {
+                translate.setElement(3, 2, 1);
+            }
+            final MathTransform tr = SphericalToCartesian.INSTANCE.completeTransform();
+            return factory.createConcatenatedTransform(factory.createAffineTransform(translate),
tr);
+        }
         EllipsoidToCentricTransform tr = new EllipsoidToCentricTransform(semiMajor, semiMinor,
unit, withHeight, target);
         return tr.context.completeTransform(factory, tr);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -92,6 +92,9 @@ class ProjectiveTransform extends Abstra
      * Otherwise returns {@code this} unchanged.
      */
     final LinearTransform optimize() {
+        if (numCol < numRow) {
+            return this;
+        }
         final int n = (numRow - 1) * numCol;
         for (int i = 0; i != numCol;) {
             if (elt[n + i] != (++i == numCol ? 1 : 0)) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/StandardDefinitionsTest.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -150,7 +150,7 @@ public final strictfp class StandardDefi
      */
     @Test
     public void testCreateAxis() {
-        for (final short code : new short[] {1, 2, 106, 107, 110, 114, 113}) {
+        for (final short code : new short[] {1, 2, 60, 61, 62, 106, 107, 110, 114, 113})
{
             final CoordinateSystemAxis actual = StandardDefinitions.createAxis(code);
             Validators.validate(actual);
             switch (code) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -534,7 +534,7 @@ public abstract strictfp class MatrixTes
     /**
      * Tests {@link MatrixSIS#solve(Matrix)}.
      *
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
     @Test
     @DependsOnMethod("testMultiply")
@@ -575,7 +575,7 @@ public abstract strictfp class MatrixTes
      * Tests {@link MatrixSIS#inverse()}.
      * SIS implements the {@code inverse} operation as a special case of the {@code solve}
operation.
      *
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
     @Test
     @DependsOnMethod("testSolve")

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -17,9 +17,11 @@
 package org.apache.sis.referencing.operation.matrix;
 
 import java.util.Random;
+import org.opengis.test.Assert;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestUtilities;
 import org.junit.AfterClass;
+import org.junit.Test;
 
 import static java.lang.Double.NaN;
 import static org.junit.Assert.*;
@@ -37,7 +39,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.7
  * @module
  */
 @DependsOn(SolverTest.class)
@@ -76,8 +78,9 @@ public final strictfp class NonSquareMat
     /**
      * Tests {@link NonSquareMatrix#inverse()} with a non-square matrix.
      *
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
+    @Test
     @Override
     public void testInverse() throws NoninvertibleMatrixException {
         testDimensionReduction(null, 1, 0);
@@ -85,10 +88,51 @@ public final strictfp class NonSquareMat
     }
 
     /**
+     * Tests inversion of a matrix with a column containing only a translation term.
+     * The purpose is to test the algorithm that selects the rows to omit.
+     *
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
+     */
+    @Test
+    public void testInverseWithTranslationTerm() throws NoninvertibleMatrixException {
+        final NonSquareMatrix m = new NonSquareMatrix(5, 3, new double[] {
+            2, 0, 0,
+            0, 0, 0,
+            0, 4, 0,
+            0, 0, 3,
+            0, 0, 1
+        });
+        MatrixSIS inverse = m.inverse();
+        Assert.assertMatrixEquals("Inverse of non-square matrix.", new NonSquareMatrix(3,
5, new double[] {
+            0.5, 0,   0,    0,   0,
+            0,   0,   0.25, 0,   0,
+            0,   0,   0,    0,   1}), inverse, STRICT);
+
+        Assert.assertMatrixEquals("Back to original.", new NonSquareMatrix(5, 3, new double[]
{
+            2, 0, 0,
+            0, 0, NaN,
+            0, 4, 0,
+            0, 0, NaN,
+            0, 0, 1}), inverse.inverse(), STRICT);
+        /*
+         * Change the [0 0 3] row into [1 0 3]. The NonSquareMarix class should no longer
omit that row.
+         * As a consequence, the matrix can not be inverted anymore.
+         */
+        m.setElement(3, 0, 1);
+        try {
+            m.inverse();
+            fail("Matrix should not be invertible.");
+        } catch (NoninvertibleMatrixException e) {
+            assertNotNull(e.getMessage());
+        }
+    }
+
+    /**
      * Tests {@link NonSquareMatrix#solve(Matrix)} with a non-square matrix.
      *
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
+    @Test
     @Override
     public void testSolve() throws NoninvertibleMatrixException {
         testDimensionReduction(new Matrix3(
@@ -110,7 +154,7 @@ public final strictfp class NonSquareMat
      * @param  Y    The matrix to give to {@code solve(Y)}, {@code null} for testing {@code
inverse()}.
      * @param  sf   The scale factor by which to multiply all expected scale elements.
      * @param  uks  Value of unknown scales (O for {@code inverse()}, or NaN for {@code solve(Y)}).
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
     private static void testDimensionReduction(final MatrixSIS Y, final double sf, final
double uks)
             throws NoninvertibleMatrixException
@@ -137,7 +181,7 @@ public final strictfp class NonSquareMat
      *
      * @param  Y    The matrix to give to {@code solve(Y)}, {@code null} for testing {@code
inverse()}.
      * @param  sf   The scale factor by which to multiply all expected scale elements.
-     * @throws NoninvertibleMatrixException Should never happen.
+     * @throws NoninvertibleMatrixException if the matrix can not be inverted.
      */
     private static void testDimensionIncrease(final MatrixSIS Y, final double sf)
             throws NoninvertibleMatrixException

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/EllipsoidToCentricTransformTest.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -59,8 +59,22 @@ public final strictfp class EllipsoidToC
      * Convenience method for creating an instance from an ellipsoid.
      */
     private void createGeodeticConversion(final Ellipsoid ellipsoid, boolean is3D) throws
FactoryException {
-        transform = EllipsoidToCentricTransform.createGeodeticConversion(
-                DefaultFactories.forBuildin(MathTransformFactory.class), ellipsoid, is3D);
+        final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
+        transform = EllipsoidToCentricTransform.createGeodeticConversion(factory, ellipsoid,
is3D);
+        /*
+         * If the ellipsoid is a sphere, then EllipsoidToCentricTransform.createGeodeticConversion(…)
created a
+         * SphericalToCartesian instance instead than an EllipsoidToCentricTransform instance.
 Create manually
+         * the EllipsoidToCentricTransform here and wrap the two transform in a comparator
for making sure that
+         * the two implementations are consistent.
+         */
+        if (ellipsoid.isSphere()) {
+            EllipsoidToCentricTransform tr = new EllipsoidToCentricTransform(
+                    ellipsoid.getSemiMajorAxis(),
+                    ellipsoid.getSemiMinorAxis(),
+                    ellipsoid.getAxisUnit(), is3D,
+                    EllipsoidToCentricTransform.TargetType.CARTESIAN);
+            transform = new TransformResultComparator(transform, tr.context.completeTransform(factory,
tr), 1E-2);
+        }
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ProjectiveTransformTest.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -21,7 +21,9 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransform1D;
 import org.opengis.referencing.operation.MathTransform2D;
 import org.opengis.referencing.operation.MathTransformFactory;
+import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.internal.referencing.provider.Affine;
 import org.apache.sis.parameter.Parameterized;
 
@@ -31,6 +33,7 @@ import org.apache.sis.test.DependsOn;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 import org.junit.After;
+import org.junit.Test;
 import static org.opengis.test.Assert.*;
 
 // Branch-dependent imports
@@ -100,6 +103,35 @@ public strictfp class ProjectiveTransfor
      */
 
     /**
+     * Tests {@link ProjectiveTransform#optimize()}. In particular this method verifies that
a non-square matrix
+     * that looks like diagonal is not confused with a real diagonal matrix.
+     *
+     * @throws TransformException if a coordinate conversion failed.
+     *
+     * @since 0.7
+     */
+    @Test
+    public void testOptimize() throws TransformException {
+        matrix = Matrices.create(5, 4, new double[] {
+            2, 0, 0, 0,
+            0, 3, 0, 0,
+            0, 0, 4, 0,
+            0, 0, 0, 5,
+            0, 0, 0, 1
+        });
+        transform = new ProjectiveTransform(matrix).optimize();
+        assertInstanceOf("Non-diagonal matrix shall not be handled by ScaleTransform.", ProjectiveTransform.class,
transform);
+        verifyConsistency(1, 2, 3,   -3, -2, -1);
+        /*
+         * Remove the "problematic" row. The new transform should now be optimizable.
+         */
+        matrix = ((MatrixSIS) matrix).removeRows(3, 4);
+        transform = new ProjectiveTransform(matrix).optimize();
+        assertInstanceOf("Diagonal matrix should be handled by a specialized class.", ScaleTransform.class,
transform);
+        verifyConsistency(1, 2, 3,   -3, -2, -1);
+    }
+
+    /**
      * {@code true} if {@link #ensureImplementRightInterface()} should skip its check for
a transform
      * of the given dimension. {@code ProjectiveTransformTest} needs to skip the case for
dimension 1
      * because there is no {@code ProjectiveTransform1D} class. However {@link LinearTransformTest}

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java?rev=1735169&r1=1735168&r2=1735169&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/TransformResultComparator.java
[UTF-8] Tue Mar 15 21:18:03 2016
@@ -23,13 +23,12 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
-import org.apache.sis.geometry.GeneralDirectPosition;
 
 import static org.opengis.test.Assert.*;
 
 
 /**
- * Compares the projection results of two {@link MathTransform} implementations.
+ * Compares the results of two {@link MathTransform} implementations.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
@@ -111,9 +110,9 @@ final strictfp class TransformResultComp
      */
     @Override
     public DirectPosition transform(DirectPosition ptSrc, DirectPosition ptDst) throws TransformException
{
-        GeneralDirectPosition clone = new GeneralDirectPosition(ptSrc);
+        final double[] expected = reference.transform(ptSrc, ptDst).getCoordinate();
         final DirectPosition value = tested.transform(ptSrc, ptDst);
-        assertEquals("transform(DirectPosition, …)", reference.transform(clone, null),
value);
+        assertArrayEquals("transform(DirectPosition, …)", expected, value.getCoordinate(),
tolerance);
         return value;
     }
 



Mime
View raw message