sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1678707 - in /sis/branches/JDK7: ./ core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/ core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/
Date Mon, 11 May 2015 09:46:09 GMT
Author: desruisseaux
Date: Mon May 11 09:46:09 2015
New Revision: 1678707

URL: http://svn.apache.org/r1678707
Log:
Merge from the JDK8 branch.

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon May 11 09:46:09 2015
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1678450
+/sis/branches/JDK8:1584960-1678706
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java?rev=1678707&r1=1678706&r2=1678707&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractSingleOperation.java
[UTF-8] Mon May 11 09:46:09 2015
@@ -28,9 +28,11 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.referencing.operation.transform.PassThroughTransform;
 import org.apache.sis.internal.referencing.OperationMethods;
+import org.apache.sis.internal.util.Constants;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
@@ -195,7 +197,7 @@ class AbstractSingleOperation extends Ab
         Integer expected = method.getSourceDimensions();
         if (expected != null && actual > expected) {
             /*
-             * The given MathTransform use more dimensions than the OperationMethod.
+             * The given MathTransform uses more dimensions than the OperationMethod.
              * Try to locate one and only one sub-transform, ignoring axis swapping and scaling.
              */
             MathTransform subTransform = null;
@@ -227,8 +229,16 @@ class AbstractSingleOperation extends Ab
             }
             isTarget = 1; // true: wrong dimension is the target one.
         }
-        throw new IllegalArgumentException(Errors.getResources(properties).getString(
-                Errors.Keys.MismatchedTransformDimension_3, isTarget, expected, actual));
+        /*
+         * At least one dimension does not match.  In principle this is an error, but we
make an exception for the
+         * "Affine parametric transformation" (EPSG:9624). The reason is that while OGC define
that transformation
+         * as two-dimensional, it can easily be extended to any number of dimensions. Note
that Apache SIS already
+         * has special handling for this operation (a TensorParameters dedicated class, etc.)
+         */
+        if (!IdentifiedObjects.isHeuristicMatchForName(method, Constants.AFFINE)) {
+            throw new IllegalArgumentException(Errors.getResources(properties).getString(
+                    Errors.Keys.MismatchedTransformDimension_3, isTarget, expected, actual));
+        }
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java?rev=1678707&r1=1678706&r2=1678707&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] Mon May 11 09:46:09 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java?rev=1678707&r1=1678706&r2=1678707&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
[UTF-8] Mon May 11 09:46:09 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