sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1712580 - /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
Date Wed, 04 Nov 2015 16:15:46 GMT
Author: desruisseaux
Date: Wed Nov  4 16:15:38 2015
New Revision: 1712580

URL: http://svn.apache.org/viewvc?rev=1712580&view=rev
Log:
Try to share existing instances.

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

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1712580&r1=1712579&r2=1712580&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
[UTF-8] Wed Nov  4 16:15:38 2015
@@ -205,7 +205,7 @@ public class ContextualParameters extend
      * The inverse of {@link #normalize} or {@link #denormalize} matrices, computed when
first needed.
      * Those matrices are cached only if {@link #isFrozen} is {@code true}.
      */
-    private transient MatrixSIS inverseNormalize, inverseDenormalize;
+    private transient Matrix inverseNormalize, inverseDenormalize;
 
     /**
      * The parameter values. Null elements in this array are empty slots available for adding
new parameter values.
@@ -510,10 +510,27 @@ public class ContextualParameters extend
         Matrix m;
         if ((m = MathTransforms.getMatrix(n)) != null)   normalize = m;
         if ((m = MathTransforms.getMatrix(d)) != null) denormalize = m;
+        inverseNormalize   = unique(factory, inverseNormalize);
+        inverseDenormalize = unique(factory, inverseDenormalize);
         return factory.createConcatenatedTransform(factory.createConcatenatedTransform(n,
kernel), d);
     }
 
     /**
+     * Invoked for opportunistically replacing inverse matrices by unique instances. We rely
on the fact that
+     * SIS's {@link DefaultMathTransformFactory} implementation caches the {@code MathTransform}
instances,
+     * and that SIS implementations of {@code MathTransform.getMatrix()} return a single
immutable matrix.
+     */
+    private static Matrix unique(final MathTransformFactory factory, Matrix matrix) throws
FactoryException {
+        if (matrix != null) {
+            final Matrix m = MathTransforms.getMatrix(factory.createAffineTransform(matrix));
+            if (m != null) {
+                matrix = m;
+            }
+        }
+        return matrix;
+    }
+
+    /**
      * Marks this contextual parameter as unmodifiable.
      *
      * @see #ensureModifiable()



Mime
View raw message