Author: desruisseaux
Date: Sun Jun 29 20:09:40 2014
New Revision: 1606594
URL: http://svn.apache.org/r1606594
Log:
Added a (hopefully temporary) tolerance threshold when checking if the result
of MathTransform concatenation is the identity transform.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.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/ProjectiveTransform.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1606594&r1=1606593&r2=1606594&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Sun Jun 29 20:09:40 2014
@@ -30,6 +30,7 @@ import org.apache.sis.util.ArgumentCheck
import org.apache.sis.util.resources.Errors;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.internal.referencing.AxisDirections;
+import org.apache.sis.internal.referencing.ExtendedPrecisionMatrix;
// Branch-dependent imports
import java.util.Objects;
@@ -63,7 +64,7 @@ import java.util.Objects;
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4 (derived from geotk-2.2)
- * @version 0.4
+ * @version 0.5
* @module
*/
public final class Matrices extends Static {
@@ -677,11 +678,13 @@ public final class Matrices extends Stat
if (size != matrix.getNumCol()) {
return new NonSquareMatrix(matrix);
}
- switch (size) {
- case 1: return new Matrix1(matrix);
- case 2: return new Matrix2(matrix);
- case 3: return new Matrix3(matrix);
- case 4: return new Matrix4(matrix);
+ if (!(matrix instanceof ExtendedPrecisionMatrix)) {
+ switch (size) {
+ case 1: return new Matrix1(matrix);
+ case 2: return new Matrix2(matrix);
+ case 3: return new Matrix3(matrix);
+ case 4: return new Matrix4(matrix);
+ }
}
return new GeneralMatrix(matrix);
}
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=1606594&r1=1606593&r2=1606594&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] Sun Jun 29 20:09:40 2014
@@ -30,6 +30,7 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.TransformException;
import org.opengis.referencing.operation.NoninvertibleTransformException;
import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.referencing.operation.matrix.MatrixSIS;
import org.apache.sis.internal.referencing.Semaphores;
import org.apache.sis.util.Classes;
@@ -64,6 +65,16 @@ class ConcatenatedTransform extends Abst
private static final long serialVersionUID = 5772066656987558634L;
/**
+ * Tolerance threshold for considering a matrix as identity. Since the
value used here is smaller
+ * than 1 ULP (about 2.22E-16), it applies only the the zero terms in the
matrix. The terms on the
+ * diagonal are still expected to be exactly 1.
+ *
+ * @todo Try to remove completely this tolerance threshold after we
applied double-double arithmetic
+ * to all matrices.
+ */
+ private static final double IDENTITY_TOLERANCE = 1E-16;
+
+ /**
* The first math transform.
*/
protected final MathTransform transform1;
@@ -230,6 +241,9 @@ class ConcatenatedTransform extends Abst
final Matrix matrix2 = MathTransforms.getMatrix(tr2);
if (matrix2 != null) {
final Matrix matrix =
MatrixSIS.castOrCopy(matrix2).multiply(matrix1);
+ if (Matrices.isIdentity(matrix, IDENTITY_TOLERANCE)) {
+ return MathTransforms.identity(matrix.getNumRow());
+ }
/*
* NOTE: It is quite tempting to "fix rounding errors" in the
matrix before to create the transform.
* But this is often wrong for datum shift transformations
(Molodensky and the like) since the datum
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=1606594&r1=1606593&r2=1606594&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] Sun Jun 29 20:09:40 2014
@@ -189,7 +189,9 @@ class ProjectiveTransform extends Abstra
*/
@Override
public final void setElement(final int row, final int column, final double
value) {
- throw new
UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableAffineTransform));
+ throw new UnsupportedOperationException(Matrices.isAffine(this)
+ ? Errors.format(Errors.Keys.UnmodifiableAffineTransform)
+ : Errors.format(Errors.Keys.UnmodifiableObject_1,
ProjectiveTransform.class));
}
/**