sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1678462 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform: ConcatenatedTransform.java MathTransforms.java
Date Sat, 09 May 2015 00:03:36 GMT
Author: desruisseaux
Date: Sat May  9 00:03:35 2015
New Revision: 1678462

URL: http://svn.apache.org/r1678462
Log:
Referencing: fixed a ClassCastException in the WKT formatting of some ProjectedCRS.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java?rev=1678462&r1=1678461&r2=1678462&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] Sat May  9 00:03:35 2015
@@ -89,7 +89,7 @@ class ConcatenatedTransform extends Abst
      * But it is serialized in order to avoid rounding errors if the inverse
      * transform is serialized instead of the original one.
      */
-    private ConcatenatedTransform inverse;
+    private MathTransform inverse;
 
     /**
      * Constructs a concatenated transform. This constructor is for subclasses only.
@@ -218,7 +218,35 @@ class ConcatenatedTransform extends Abst
          * Can not avoid the creation of a ConcatenatedTransform object.
          * Check for the type to create (1D, 2D, general case...)
          */
-        return createConcatenatedTransform(tr1, tr2);
+        assert tr1.getTargetDimensions() == dim1;
+        assert tr2.getSourceDimensions() == dim2;
+        final int dimSource = tr1.getSourceDimensions();
+        final int dimTarget = tr2.getTargetDimensions();
+        if (dimSource == 1 && dimTarget == 1) {
+            /*
+             * Result needs to be a MathTransform1D.
+             */
+            if (tr1 instanceof MathTransform1D && tr2 instanceof MathTransform1D)
{
+                return new ConcatenatedTransformDirect1D((MathTransform1D) tr1,
+                                                         (MathTransform1D) tr2);
+            } else {
+                return new ConcatenatedTransform1D(tr1, tr2);
+            }
+        } else if (dimSource == 2 && dimTarget == 2) {
+            /*
+             * Result needs to be a MathTransform2D.
+             */
+            if (tr1 instanceof MathTransform2D && tr2 instanceof MathTransform2D)
{
+                return new ConcatenatedTransformDirect2D((MathTransform2D) tr1,
+                                                         (MathTransform2D) tr2);
+            } else {
+                return new ConcatenatedTransform2D(tr1, tr2);
+            }
+        } else if (dimSource == dim1 && dim2 == dimTarget) {
+            return new ConcatenatedTransformDirect(tr1, tr2);
+        } else {
+            return new ConcatenatedTransform(tr1, tr2);
+        }
     }
 
     /**
@@ -297,44 +325,6 @@ class ConcatenatedTransform extends Abst
     }
 
     /**
-     * Continue the construction started by the {@link #create(MathTransform, MathTransform)}
method.
-     * The construction step is available separately for testing purpose (in a JUnit test),
and for
-     * {@link #inverse()} implementation.
-     */
-    static ConcatenatedTransform createConcatenatedTransform(
-            final MathTransform tr1, final MathTransform tr2)
-    {
-        final int dimSource = tr1.getSourceDimensions();
-        final int dimTarget = tr2.getTargetDimensions();
-        /*
-         * Checks if the result need to be a MathTransform1D.
-         */
-        if (dimSource == 1 && dimTarget == 1) {
-            if (tr1 instanceof MathTransform1D && tr2 instanceof MathTransform1D)
{
-                return new ConcatenatedTransformDirect1D((MathTransform1D) tr1,
-                                                         (MathTransform1D) tr2);
-            } else {
-                return new ConcatenatedTransform1D(tr1, tr2);
-            }
-        } else
-        /*
-         * Checks if the result need to be a MathTransform2D.
-         */
-        if (dimSource == 2 && dimTarget == 2) {
-            if (tr1 instanceof MathTransform2D && tr2 instanceof MathTransform2D)
{
-                return new ConcatenatedTransformDirect2D((MathTransform2D) tr1,
-                                                         (MathTransform2D) tr2);
-            } else {
-                return new ConcatenatedTransform2D(tr1, tr2);
-            }
-        } else if (dimSource == tr1.getTargetDimensions() && tr2.getSourceDimensions()
== dimTarget) {
-            return new ConcatenatedTransformDirect(tr1, tr2);
-        } else {
-            return new ConcatenatedTransform(tr1, tr2);
-        }
-    }
-
-    /**
      * Returns a name for the specified math transform.
      */
     private static String getName(final MathTransform transform) {
@@ -823,8 +813,10 @@ class ConcatenatedTransform extends Abst
     public synchronized MathTransform inverse() throws NoninvertibleTransformException {
         assert isValid();
         if (inverse == null) {
-            inverse = createConcatenatedTransform(transform2.inverse(), transform1.inverse());
-            inverse.inverse = this;
+            inverse = create(transform2.inverse(), transform1.inverse());
+            if (inverse instanceof ConcatenatedTransform) {
+                ((ConcatenatedTransform) inverse).inverse = this;
+            }
         }
         return inverse;
     }
@@ -915,8 +907,15 @@ class ConcatenatedTransform extends Abst
             formatter.newLine();
             if (step instanceof FormattableObject) {
                 formatter.append((FormattableObject) step); // May not implement MathTransform.
-            } else {
+            } else if (step instanceof MathTransform) {
                 formatter.append((MathTransform) step);
+            } else {
+                /*
+                 * Matrices may happen in a chain of pseudo-steps. For now wrap in a MathTransform.
+                 * We could define a Formatter.append(Matrix) method instead, but it is probably
not
+                 * worth the cost.
+                 */
+                formatter.append(MathTransforms.linear((Matrix) step));
             }
         }
         return WKTKeywords.Concat_MT;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java?rev=1678462&r1=1678461&r2=1678462&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] Sat May  9 00:03:35 2015
@@ -164,7 +164,9 @@ public final class MathTransforms extend
     {
         ensureNonNull("tr1", tr1);
         ensureNonNull("tr2", tr2);
-        return ConcatenatedTransform.create(tr1, tr2);
+        final MathTransform tr = ConcatenatedTransform.create(tr1, tr2);
+        assert isValid(getSteps(tr)) : tr;
+        return tr;
     }
 
     /**
@@ -258,6 +260,24 @@ public final class MathTransforms extend
     }
 
     /**
+     * Makes sure that the given list does not contains two consecutive linear transforms
+     * (because their matrices should have been multiplied together).
+     * This is used for assertion purposes only.
+     */
+    private static boolean isValid(final List<MathTransform> steps) {
+        boolean wasLinear = false;
+        for (final MathTransform step : steps) {
+            if (step instanceof LinearTransform) {
+                if (wasLinear) return false;
+                wasLinear = true;
+            } else {
+                wasLinear = false;
+            }
+        }
+        return true;
+    }
+
+    /**
      * Returns all single components of the given (potentially concatenated) transform.
      * This method makes the following choice:
      *



Mime
View raw message