You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2015/10/26 11:15:16 UTC
svn commit: r1710547 -
/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/
Author: desruisseaux
Date: Mon Oct 26 10:15:16 2015
New Revision: 1710547
URL: http://svn.apache.org/viewvc?rev=1710547&view=rev
Log:
Slightly more robust check for inverse transforms of linear operations.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractLinearTransform.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/GeocentricAffineTransform.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/ProjectiveTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractLinearTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractLinearTransform.java?rev=1710547&r1=1710546&r2=1710547&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractLinearTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractLinearTransform.java [UTF-8] Mon Oct 26 10:15:16 2015
@@ -16,8 +16,10 @@
*/
package org.apache.sis.referencing.operation.transform;
+import java.io.Serializable;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.Matrix;
import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.internal.referencing.provider.Affine;
@@ -37,13 +39,23 @@ import org.apache.sis.util.resources.Err
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.6
- * @version 0.6
+ * @version 0.7
* @module
*/
-@SuppressWarnings("CloneInNonCloneableClass")
-abstract class AbstractLinearTransform extends AbstractMathTransform
- implements LinearTransform, Matrix // Not Cloneable, despite the clone() method.
-{
+@SuppressWarnings("CloneInNonCloneableClass") // Intentionally not Cloneable despite the clone() method.
+abstract class AbstractLinearTransform extends AbstractMathTransform implements LinearTransform, Matrix, Serializable {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -4649708313541868599L;
+
+ /**
+ * The inverse transform, or {@code null} if not yet created.
+ * This field is part of the serialization form in order to avoid rounding errors if a user
+ * asks for the inverse of the inverse (i.e. the original transform) after deserialization.
+ */
+ MathTransform inverse;
+
/**
* Constructs a transform.
*/
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=1710547&r1=1710546&r2=1710547&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] Mon Oct 26 10:15:16 2015
@@ -17,7 +17,6 @@
package org.apache.sis.referencing.operation.transform;
import java.util.Arrays;
-import java.io.Serializable;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
@@ -39,10 +38,10 @@ import org.apache.sis.referencing.operat
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.5
- * @version 0.6
+ * @version 0.7
* @module
*/
-final class CopyTransform extends AbstractLinearTransform implements Serializable {
+final class CopyTransform extends AbstractLinearTransform {
/**
* Serial number for inter-operability with different versions.
*/
@@ -61,11 +60,6 @@ final class CopyTransform extends Abstra
private final int[] indices;
/**
- * The inverse transform. Will be created only when first needed.
- */
- private transient MathTransform inverse;
-
- /**
* Creates a new transform.
*
* @param srcDim The dimension of source coordinates.
@@ -339,8 +333,9 @@ final class CopyTransform extends Abstra
public synchronized MathTransform inverse() throws NoninvertibleTransformException {
if (inverse == null) {
/*
- * Note: we do not perform the following optimization, because MathTransforms.linear(…)
- * should never instantiate this class in the identity case.
+ * Note: no need to perform the following check as this point because MathTransforms.linear(…)
+ * should never instantiate this class in the identity case and because we perform an
+ * equivalent check later anyway.
*
* if (isIdentity()) {
* inverse = this;
@@ -361,7 +356,7 @@ final class CopyTransform extends Abstra
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.
+ for (j=0; j<srcDim; j++) { // Okay to reuse 'j' since the outer loop will not continue.
final int i = reverse[j];
if (i >= 0) {
matrix.setElement(j, i, 1);
@@ -371,14 +366,16 @@ final class CopyTransform extends Abstra
}
matrix.setElement(srcDim, dstDim, 1);
inverse = MathTransforms.linear(matrix);
- if (inverse instanceof ProjectiveTransform) {
- ((ProjectiveTransform) inverse).inverse = this;
+ if (inverse instanceof AbstractLinearTransform) {
+ ((AbstractLinearTransform) inverse).inverse = this;
}
return inverse;
}
}
/*
- * At this point, we known that we can create the inverse transform.
+ * At this point, we know that we can create the inverse transform.
+ * If this transform is the identity transform (we should never happen,
+ * but we are paranoiac), then the old and new arrays would be equal.
*/
CopyTransform copyInverse = this;
if (!Arrays.equals(reverse, indices)) {
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/GeocentricAffineTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/GeocentricAffineTransform.java?rev=1710547&r1=1710546&r2=1710547&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/GeocentricAffineTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/GeocentricAffineTransform.java [UTF-8] Mon Oct 26 10:15:16 2015
@@ -110,14 +110,6 @@ final class GeocentricAffineTransform ex
}
/**
- * Creates an inverse transform using the specified matrix.
- */
- @Override
- final GeocentricAffineTransform createInverse(final Matrix matrix) {
- return new GeocentricAffineTransform(matrix, type);
- }
-
- /**
* {@inheritDoc}
*/
@Override
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=1710547&r1=1710546&r2=1710547&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] Mon Oct 26 10:15:16 2015
@@ -16,7 +16,6 @@
*/
package org.apache.sis.referencing.operation.transform;
-import java.io.Serializable;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
@@ -37,7 +36,7 @@ import org.apache.sis.internal.referenci
* @version 0.6
* @module
*/
-final class IdentityTransform extends AbstractLinearTransform implements Serializable {
+final class IdentityTransform extends AbstractLinearTransform {
/**
* Serial number for inter-operability with different versions.
*/
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=1710547&r1=1710546&r2=1710547&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] Mon Oct 26 10:15:16 2015
@@ -17,7 +17,6 @@
package org.apache.sis.referencing.operation.transform;
import java.util.Arrays;
-import java.io.Serializable;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
@@ -38,14 +37,12 @@ import org.apache.sis.util.ArgumentCheck
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.5
- * @version 0.5
+ * @version 0.7
* @module
*
* @see java.awt.geom.AffineTransform
*/
-class ProjectiveTransform extends AbstractLinearTransform implements LinearTransform, ExtendedPrecisionMatrix,
- Serializable // Not Cloneable, despite the clone() method.
-{
+class ProjectiveTransform extends AbstractLinearTransform implements ExtendedPrecisionMatrix {
/**
* Serial number for inter-operability with different versions.
*/
@@ -70,13 +67,6 @@ class ProjectiveTransform extends Abstra
private final double[] elt;
/**
- * The inverse transform. Will be created only when first needed. This field is part of the serialization form
- * in order to avoid rounding errors if a user asks for the inverse of the inverse (i.e. the original transform)
- * after deserialization.
- */
- AbstractMathTransform inverse;
-
- /**
* Constructs a transform from the specified matrix.
* The matrix is usually square and affine, but this is not enforced.
*
@@ -420,29 +410,23 @@ class ProjectiveTransform extends Abstra
public synchronized MathTransform inverse() throws NoninvertibleTransformException {
if (inverse == null) {
/*
- * 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 { ... }
+ * Should never be the identity transform at this point (except during tests) because
+ * MathTransforms.linear(…) should never instantiate this class in the identity case.
+ * But we check anyway as a paranoiac safety.
*/
- ProjectiveTransform inv = createInverse(Matrices.inverse(this));
- inv.inverse = this;
- inverse = inv;
+ if (isIdentity()) {
+ inverse = this;
+ } else {
+ inverse = MathTransforms.linear(Matrices.inverse(this));
+ if (inverse instanceof AbstractLinearTransform) {
+ ((AbstractLinearTransform) inverse).inverse = this;
+ }
+ }
}
return inverse;
}
/**
- * Creates an inverse transform using the specified matrix.
- * To be overridden by {@link GeocentricAffineTransform}.
- */
- ProjectiveTransform createInverse(final Matrix matrix) {
- return new ProjectiveTransform(matrix);
- }
-
- /**
* {@inheritDoc}
*
* @return {@inheritDoc}
Modified: 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=1710547&r1=1710546&r2=1710547&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform2D.java [UTF-8] Mon Oct 26 10:15:16 2015
@@ -89,12 +89,4 @@ final class ProjectiveTransform2D extend
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);
- }
}