sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1600683 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/t...
Date Thu, 05 Jun 2014 15:48:57 GMT
Author: desruisseaux
Date: Thu Jun  5 15:48:56 2014
New Revision: 1600683

URL: http://svn.apache.org/r1600683
Log:
A little bit of consolidation.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/Affine.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
    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/ConcatenatedTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ISOMetadata.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -31,6 +31,7 @@ import org.apache.sis.xml.IdentifiedObje
 import org.apache.sis.metadata.MetadataStandard;
 import org.apache.sis.metadata.ModifiableMetadata;
 import org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCases;
+import org.apache.sis.util.collection.Containers;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.CharSequences;
 
@@ -82,6 +83,21 @@ public class ISOMetadata extends Modifia
      */
     protected ISOMetadata(final Object object) {
         if (object instanceof IdentifiedObject) {
+            if (object instanceof ISOMetadata && Containers.isNullOrEmpty(((ISOMetadata)
object).identifiers)) {
+                /*
+                 * If the other object is an ISOMetadata instance,  take a look at its 'identifiers'
collection
+                 * before to invoke object.getIdentifiers() in order to avoid unnecessary
initialization of its
+                 * backing collection. We do this optimization because the vast majority
of metadata objects do
+                 * not have 'identifiers' collection.
+                 *
+                 * Actually this optimization is a little bit dangerous, since users could
override getIdentifiers()
+                 * without invoking super.getIdentifiers(), in which case their identifiers
will not be copied.
+                 * For safety, we will do this optimization only if the implementation is
an Apache SIS one.
+                 */
+                if (object.getClass().getName().startsWith("org.apache.sis.")) {
+                    return;
+                }
+            }
             identifiers = copyCollection(((IdentifiedObject) object).getIdentifiers(), Identifier.class);
         }
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/Affine.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/Affine.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/Affine.java
(original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/provider/Affine.java
Thu Jun  5 15:48:56 2014
@@ -16,8 +16,12 @@
  */
 package org.apache.sis.referencing.operation.provider;
 
+import java.util.Map;
+import java.util.Collections;
 import org.opengis.parameter.ParameterDescriptorGroup;
 
-public class Affine {
+public abstract class Affine implements org.opengis.referencing.operation.OperationMethod
{
+    public static Map<String,Object> IDENTIFICATION = Collections.singletonMap(NAME_KEY,
"Affine");
+
     public static ParameterDescriptorGroup PARAMETERS; // TODO
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AffineTransform2D.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -27,6 +27,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.referencing.operation.matrix.Matrix2;
 import org.apache.sis.referencing.operation.matrix.AffineTransforms2D;
 import org.apache.sis.referencing.operation.provider.Affine;
@@ -157,7 +158,7 @@ final class AffineTransform2D extends Im
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return ProjectiveTransform.getParameterValues(getMatrix());
+        return TensorParameters.WKT1.createValueGroup(Affine.IDENTIFICATION, getMatrix());
     }
 
     /**

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=1600683&r1=1600682&r2=1600683&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] Thu Jun  5 15:48:56 2014
@@ -839,10 +839,16 @@ class ConcatenatedTransform extends Abst
 
     /**
      * Tests whether this transform does not move any points.
-     * Default implementation check if the two transforms are identity.
+     * Implementation checks if the two transforms are identity.
+     *
+     * <span class="note"><b>Note:</b> this method should always returns
{@code false}, since
+     * {@code create(…)} 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, or in case the given math transforms
+     * are mutable (they should not, be we can not control what the user gave to us).</span>
      */
     @Override
-    public final boolean isIdentity() {
+    public boolean isIdentity() {
         return transform1.isIdentity() && transform2.isIdentity();
     }
 
@@ -858,7 +864,7 @@ class ConcatenatedTransform extends Abst
      * Compares the specified object with this math transform for equality.
      */
     @Override
-    public final boolean equals(final Object object, final ComparisonMode mode) {
+    public boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) { // Slight optimization
             return true;
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform1D.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform1D.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -73,7 +73,7 @@ final class ConcatenatedTransform1D exte
     @Override
     public double derivative(final double value) throws TransformException {
         final DirectPosition1D p = new DirectPosition1D(value);
-        final Matrix m = derivative(p);
+        final Matrix m = super.derivative(p);
         assert (m.getNumRow() == 1) && (m.getNumCol() == 1);
         return m.getElement(0,0);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform2D.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform2D.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -18,12 +18,13 @@ package org.apache.sis.referencing.opera
 
 import java.awt.Shape;
 import java.awt.geom.Point2D;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform2D;
 import org.opengis.referencing.operation.Matrix;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.opengis.referencing.operation.TransformException;
-import org.apache.sis.geometry.GeneralDirectPosition;
+import org.apache.sis.geometry.DirectPosition2D;
 
 
 /**
@@ -96,7 +97,8 @@ final class ConcatenatedTransform2D exte
      */
     @Override
     public Matrix derivative(final Point2D point) throws TransformException {
-        return derivative(new GeneralDirectPosition(point.getX(), point.getY()));
+        return super.derivative(point instanceof DirectPosition ?
+                (DirectPosition) point : new DirectPosition2D(point.getX(), point.getY()));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -24,6 +24,7 @@ import org.opengis.referencing.operation
 import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptorGroup;
+import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.referencing.operation.provider.Affine;
 import org.apache.sis.referencing.operation.matrix.MatrixSIS;
 import org.apache.sis.referencing.operation.matrix.Matrices;
@@ -140,6 +141,11 @@ final class CopyTransform extends Abstra
 
     /**
      * Tests whether this transform does not move any points.
+     *
+     * <span 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.</span>
      */
     @Override
     public boolean isIdentity() {
@@ -312,7 +318,7 @@ final class CopyTransform extends Abstra
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return ProjectiveTransform.getParameterValues(getMatrix());
+        return TensorParameters.WKT1.createValueGroup(Affine.IDENTIFICATION, getMatrix());
     }
 
     /**
@@ -351,46 +357,52 @@ final class CopyTransform extends Abstra
     @Override
     public synchronized MathTransform inverse() throws NoninvertibleTransformException {
         if (inverse == null) {
-            CopyTransform copyInverse = this;
-            if (!isIdentity()) {
-                final int srcDim = this.srcDim;
-                final int dstDim = indices.length;
-                final int[] reverse = new int[srcDim];
-                Arrays.fill(reverse, -1);
-                for (int i=dstDim; --i>=0;) {
-                    reverse[indices[i]] = i;
-                }
-                /*
-                 * Check if there is any unassigned dimension. In such case,
-                 * delegates to the generic ProjectiveTransform with a matrix
-                 * which set the missing values to NaN.
-                 */
-                for (int j=srcDim; --j>=0;) {
-                    if (reverse[j] < 0) {
-                        final MatrixSIS matrix = Matrices.createZero(srcDim + 1, dstDim +
1);
-                        for (j=0; j<srcDim; j++) { // NOSONAR: the outer loop will not
continue.
-                            final int i = reverse[j];
-                            if (i >= 0) {
-                                matrix.setElement(j, i, 1);
-                            } else {
-                                matrix.setElement(j, dstDim, Double.NaN);
-                            }
+            /*
+             * Note: we do not perform the following optimization, because MathTransforms.linear(…)
+             *       should never instantiate this class in the identity case.
+             *
+             *       if (isIdentity()) {
+             *           inverse = this;
+             *       } else { ... }
+             */
+            final int srcDim = this.srcDim;
+            final int dstDim = indices.length;
+            final int[] reverse = new int[srcDim];
+            Arrays.fill(reverse, -1);
+            for (int i=dstDim; --i>=0;) {
+                reverse[indices[i]] = i;
+            }
+            /*
+             * Check if there is any unassigned dimension. In such case,
+             * delegates to the generic ProjectiveTransform with a matrix
+             * which set the missing values to NaN.
+             */
+            for (int j=srcDim; --j>=0;) {
+                if (reverse[j] < 0) {
+                    final MatrixSIS matrix = Matrices.createZero(srcDim + 1, dstDim + 1);
+                    for (j=0; j<srcDim; j++) { // NOSONAR: the outer loop will not continue.
+                        final int i = reverse[j];
+                        if (i >= 0) {
+                            matrix.setElement(j, i, 1);
+                        } else {
+                            matrix.setElement(j, dstDim, Double.NaN);
                         }
-                        matrix.setElement(srcDim, dstDim, 1);
-                        inverse = MathTransforms.linear(matrix);
-                        if (inverse instanceof ProjectiveTransform) {
-                            ((ProjectiveTransform) inverse).inverse = this;
-                        }
-                        return inverse;
                     }
+                    matrix.setElement(srcDim, dstDim, 1);
+                    inverse = MathTransforms.linear(matrix);
+                    if (inverse instanceof ProjectiveTransform) {
+                        ((ProjectiveTransform) inverse).inverse = this;
+                    }
+                    return inverse;
                 }
-                /*
-                 * At this point, we known that we can create the inverse transform.
-                 */
-                if (!Arrays.equals(reverse, indices)) {
-                    copyInverse = new CopyTransform(indices.length, reverse);
-                    copyInverse.inverse = this;
-                }
+            }
+            /*
+             * At this point, we known that we can create the inverse transform.
+             */
+            CopyTransform copyInverse = this;
+            if (!Arrays.equals(reverse, indices)) {
+                copyInverse = new CopyTransform(indices.length, reverse);
+                copyInverse.inverse = this;
             }
             inverse = copyInverse;
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -25,6 +25,7 @@ import org.opengis.referencing.operation
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.geometry.GeneralDirectPosition;
+import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.referencing.operation.provider.Affine;
 import org.apache.sis.referencing.operation.matrix.Matrices;
 
@@ -140,7 +141,7 @@ final class IdentityTransform extends Ab
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return ProjectiveTransform.getParameterValues(getMatrix());
+        return TensorParameters.WKT1.createValueGroup(Affine.IDENTIFICATION, getMatrix());
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java?rev=1600683&r1=1600682&r2=1600683&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -27,6 +27,7 @@ import org.opengis.referencing.operation
 import org.apache.sis.referencing.operation.matrix.Matrix1;
 import org.apache.sis.referencing.operation.matrix.Matrix2;
 import org.apache.sis.referencing.operation.provider.Affine;
+import org.apache.sis.parameter.TensorParameters;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.ComparisonMode;
 
@@ -124,7 +125,7 @@ class LinearTransform1D extends Abstract
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return ProjectiveTransform.getParameterValues(getMatrix());
+        return TensorParameters.WKT1.createValueGroup(Affine.IDENTIFICATION, getMatrix());
     }
 
     /**
@@ -141,9 +142,15 @@ class LinearTransform1D extends Abstract
     @Override
     public MathTransform1D inverse() throws NoninvertibleTransformException {
         if (inverse == null) {
-            if (isIdentity()) {
-                inverse = this;
-            } else if (scale != 0) {
+            /*
+             * Note: we do not perform the following optimization, because MathTransforms.linear(…)
+             *       should never instantiate this class in the identity case.
+             *
+             *       if (isIdentity()) {
+             *           inverse = this;
+             *       } else { ... }
+             */
+            if (scale != 0) {
                 final LinearTransform1D inverse;
                 inverse = create(1/scale, -offset/scale);
                 inverse.inverse = this;
@@ -157,6 +164,11 @@ class LinearTransform1D extends Abstract
 
     /**
      * Tests whether this transform does not move any points.
+     *
+     * <span 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.</span>
      */
     @Override
     public boolean isIdentity() {

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=1600683&r1=1600682&r2=1600683&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] Thu Jun  5 15:48:56 2014
@@ -122,7 +122,7 @@ public final class MathTransforms extend
 //TODO              case 2: return linear(Matrices.toAffineTransform(matrix));
                 }
             } else if (sourceDimension == 2) {
-//TODO          return new ProjectiveTransform2D(matrix);
+                return new ProjectiveTransform2D(matrix);
             }
         }
         final LinearTransform candidate = CopyTransform.create(matrix);

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=1600683&r1=1600682&r2=1600683&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] Thu Jun  5 15:48:56 2014
@@ -84,10 +84,10 @@ class ProjectiveTransform extends Abstra
         numRow = matrix.getNumRow();
         numCol = matrix.getNumCol();
         elt = new double[numRow * numCol];
-        int index = 0;
+        int mix = 0;
         for (int j=0; j<numRow; j++) {
             for (int i=0; i<numCol; i++) {
-                elt[index++] = matrix.getElement(j,i);
+                elt[mix++] = matrix.getElement(j,i);
             }
         }
     }
@@ -110,16 +110,21 @@ class ProjectiveTransform extends Abstra
 
     /**
      * Tests whether this transform does not move any points.
+     *
+     * <span 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.</span>
      */
     @Override
     public boolean isIdentity() {
         if (numRow != numCol) {
             return false;
         }
-        int index = 0;
+        int mix = 0;
         for (int j=0; j<numRow; j++) {
             for (int i=0; i<numCol; i++) {
-                if (elt[index++] != (i == j ? 1 : 0)) {
+                if (elt[mix++] != (i == j ? 1 : 0)) {
                     return false;
                 }
             }
@@ -131,7 +136,7 @@ class ProjectiveTransform extends Abstra
      * Returns a copy of the matrix given to the constructor.
      */
     @Override
-    public Matrix getMatrix() {
+    public final Matrix getMatrix() {
         return Matrices.create(numRow, numCol, elt);
     }
 
@@ -149,26 +154,11 @@ class ProjectiveTransform extends Abstra
      * Returns the matrix elements as a group of parameters values. The number of parameters
depends on the
      * matrix size. Only matrix elements different from their default value will be included
in this group.
      *
-     * @param  matrix The matrix to returns as a group of parameters.
-     * @return A copy of the parameter values for this math transform.
-     */
-    static ParameterValueGroup getParameterValues(final Matrix matrix) {
-//      final MatrixParameters values;
-//      values = (MatrixParameters) Affine.PARAMETERS.createValue();
-//      values.setMatrix(matrix);
-//      return values;
-        return null; // TODO
-    }
-
-    /**
-     * Returns the matrix elements as a group of parameters values. The number of parameters
depends on the
-     * matrix size. Only matrix elements different from their default value will be included
in this group.
-     *
      * @return A copy of the parameter values for this math transform.
      */
     @Override
     public ParameterValueGroup getParameterValues() {
-        return getParameterValues(getMatrix());
+        return TensorParameters.WKT1.createValueGroup(Affine.IDENTIFICATION, getMatrix());
     }
 
     /**
@@ -213,8 +203,8 @@ class ProjectiveTransform extends Abstra
                     break;
                 }
                 case DESCENDING: {
-                    srcOff += (numPts-1) * srcDim;
-                    dstOff += (numPts-1) * dstDim;
+                    srcOff += (numPts - 1) * srcDim;
+                    dstOff += (numPts - 1) * dstDim;
                     srcInc = -srcInc;
                     dstInc = -dstInc;
                     break;
@@ -284,8 +274,8 @@ class ProjectiveTransform extends Abstra
                     break;
                 }
                 case DESCENDING: {
-                    srcOff += (numPts-1) * srcDim;
-                    dstOff += (numPts-1) * dstDim;
+                    srcOff += (numPts - 1) * srcDim;
+                    dstOff += (numPts - 1) * dstDim;
                     srcInc = -srcInc;
                     dstInc = -dstInc;
                     break;
@@ -366,8 +356,8 @@ class ProjectiveTransform extends Abstra
      */
     @Override
     public void transform(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts)
{
-        final int srcDim = numCol-1;
-        final int dstDim = numRow-1;
+        final int srcDim = numCol - 1;
+        final int dstDim = numRow - 1;
         final double[] buffer = new double[numRow];
         while (--numPts >= 0) {
             int mix = 0;
@@ -398,8 +388,16 @@ class ProjectiveTransform extends Abstra
      */
     @Override
     public Matrix derivative(final DirectPosition point) {
-        final MatrixSIS matrix = Matrices.create(numRow, numCol, elt);
-// TODO matrix.setSize(numRow-1, numCol-1);
+        final int srcDim = numCol - 1;
+        final int dstDim = numRow - 1;
+        final MatrixSIS matrix = Matrices.createZero(dstDim, srcDim);
+        int mix = 0;
+        for (int j=0; j<dstDim; j++) {
+            for (int i=0; i<srcDim; i++) {
+                matrix.setElement(j, i, elt[mix++]);
+            }
+            mix++; // Skip translation column.
+        }
         return matrix;
     }
 
@@ -409,15 +407,19 @@ class ProjectiveTransform extends Abstra
     @Override
     public synchronized MathTransform inverse() throws NoninvertibleTransformException {
         if (inverse == null) {
-            if (isIdentity()) {
-                inverse = this;
-            } else {
-                MatrixSIS matrix = Matrices.create(numRow, numCol, elt);
-                matrix = matrix.inverse();
-                ProjectiveTransform inv = createInverse(matrix);
-                inv.inverse = this;
-                inverse = inv;
-            }
+            /*
+             * Note: we do not perform the following optimization, because MathTransforms.linear(…)
+             *       should never instantiate this class in the identity case.
+             *
+             *       if (isIdentity()) {
+             *           inverse = this;
+             *       } else { ... }
+             */
+            MatrixSIS matrix = Matrices.create(numRow, numCol, elt);
+            matrix = matrix.inverse();
+            ProjectiveTransform inv = createInverse(matrix);
+            inv.inverse = this;
+            inverse = inv;
         }
         return inverse;
     }

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java?rev=1600683&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
[UTF-8] Thu Jun  5 15:48:56 2014
@@ -0,0 +1,99 @@
+/*
+ * 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 java.awt.Shape;
+import java.awt.geom.Point2D;
+import org.opengis.referencing.operation.Matrix;
+import org.opengis.referencing.operation.MathTransform2D;
+import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.opengis.referencing.operation.TransformException;
+
+
+/**
+ * Projective transform in 2D case.
+ *
+ * @author  Jan Jezek (UWB)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5 (derived from geotk-2.5)
+ * @version 0.5
+ * @module
+ */
+final class ProjectiveTransform2D extends ProjectiveTransform implements MathTransform2D
{
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -3101392684596817045L;
+
+    /**
+     * Creates projective transform from a matrix.
+     */
+    public ProjectiveTransform2D(final Matrix matrix) {
+        super(matrix);
+    }
+
+    /**
+     * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}.
+     * This method is a copy of {@link AbstractMathTransform2D#transform(Point2D, Point2D)}
+     */
+    @Override
+    public Point2D transform(final Point2D ptSrc, final Point2D ptDst) {
+        final double[] ord = new double[] {ptSrc.getX(), ptSrc.getY()};
+        transform(ord, 0, ord, 0, false);
+        if (ptDst != null) {
+            ptDst.setLocation(ord[0], ord[1]);
+            return ptDst;
+        } else {
+            return new Point2D.Double(ord[0], ord[1]);
+        }
+    }
+
+    /**
+     * Transform the specified shape.
+     */
+    @Override
+    public Shape createTransformedShape(final Shape shape) throws TransformException {
+        return AbstractMathTransform2D.createTransformedShape(this, shape, null, null, false);
+    }
+
+    /**
+     * Gets the derivative of this transform at a point.
+     *
+     * @param  point Ignored, since derivative of a linear transform is the same everywhere.
+     * @return The derivative at the specified point as a 2×2 matrix.
+     */
+    @Override
+    public Matrix derivative(final Point2D point) {
+        return super.derivative(null);
+    }
+
+    /**
+     * Creates the inverse transform of this object.
+     */
+    @Override
+    public MathTransform2D inverse() throws NoninvertibleTransformException {
+        return (MathTransform2D) super.inverse();
+    }
+
+    /**
+     * Creates an inverse transform using the specified matrix.
+     */
+    @Override
+    ProjectiveTransform2D createInverse(final Matrix matrix) {
+        return new ProjectiveTransform2D(matrix);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message