Author: desruisseaux
Date: Sun Jun 29 20:13:03 2014
New Revision: 1606595
URL: http://svn.apache.org/r1606595
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/matrix/Matrices.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.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/CopyTransform.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
Merged /sis/branches/JDK8:r1606274-1606594
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Sun Jun 29 20:13:03 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Sun Jun 29 20:13:03 2014
@@ -33,7 +33,6 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.SingleOperation;
import org.apache.sis.geometry.GeneralDirectPosition;
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.io.wkt.Formatter;
import org.apache.sis.io.wkt.FormattableObject;
@@ -874,48 +873,6 @@ public abstract class AbstractMathTransf
}
/**
- * Helper method for implementation of {@link #equals(Object,
ComparisonMode)} methods in
- * {@link LinearTransform} implementations. Those implementations shall
replace completely the
- * {@link #equals(Object, ComparisonMode)} default implementation,
<strong>except</strong> for
- * {@link ComparisonMode#STRICT} which should continue to rely on the
default implementation.
- * The pattern is:
- *
- * {@preformat java
- * public boolean equals(Object object, ComparisonMode mode) {
- * if (object == this) { // Slight optimization
- * return true;
- * }
- * if (mode != ComparisonMode.STRICT) {
- * return equals(this, object, mode);
- * }
- * if (super.equals(object, mode)) {
- * // Compare the internal fields here.
- * }
- * return false;
- * }
- * }
- *
- * Note that this pattern considers {@link ComparisonMode#BY_CONTRACT} as
synonymous to
- * {@code IGNORE_METADATA} rather than {@code STRICT}. This is valid if we
consider that
- * the behavior of the math transform is completely specified by its
matrix.
- *
- * @param t1 The first transform to compare.
- * @param t2 The second transform to compare, or {@code null} if none.
- * @param mode The strictness level of the comparison.
- * @return {@code true} if both transforms are equal.
- */
- static boolean equals(final LinearTransform t1, final Object t2, final
ComparisonMode mode) {
- if (t2 instanceof LinearTransform) {
- /*
- * Note: do not delegate to ((LenientComparable) m1).equals(m2,
mode)
- * since it may cause a never-ending loop with ProjectiveTransform.
- */
- return Matrices.equals(t1.getMatrix(), ((LinearTransform)
t2).getMatrix(), mode);
- }
- return false;
- }
-
- /**
* Formats the inner part of a <cite>Well Known Text</cite> version 1 (WKT
1) element.
* The default implementation formats all parameter values returned by
{@link #getParameterValues()}.
* The parameter group name is used as the math transform name.
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=1606595&r1=1606594&r2=1606595&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] Sun Jun 29 20:13:03 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/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/CopyTransform.java
[UTF-8] Sun Jun 29 20:13:03 2014
@@ -426,9 +426,10 @@ final class CopyTransform extends Abstra
return true;
}
if (mode != ComparisonMode.STRICT) {
- return equals(this, object, mode);
- }
- if (super.equals(object, mode)) {
+ if (object instanceof LinearTransform) {
+ return Matrices.equals(getMatrix(), ((LinearTransform)
object).getMatrix(), mode);
+ }
+ } else if (super.equals(object, mode)) {
final CopyTransform that = (CopyTransform) object;
return srcDim == that.srcDim && Arrays.equals(indices,
that.indices);
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/IdentityTransform.java
[UTF-8] Sun Jun 29 20:13:03 2014
@@ -259,11 +259,11 @@ final class IdentityTransform extends Ab
return true;
}
if (mode != ComparisonMode.STRICT) {
- return equals(this, object, mode);
- }
- if (super.equals(object, mode)) {
- final IdentityTransform that = (IdentityTransform) object;
- return this.dimension == that.dimension;
+ if (object instanceof LinearTransform) {
+ return Matrices.equals(getMatrix(), ((LinearTransform)
object).getMatrix(), mode);
+ }
+ } else if (super.equals(object, mode)) {
+ return ((IdentityTransform) object).dimension == dimension;
}
return false;
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearTransform1D.java
[UTF-8] Sun Jun 29 20:13:03 2014
@@ -24,6 +24,7 @@ import org.opengis.referencing.operation
import org.opengis.referencing.operation.MathTransform1D;
import org.opengis.referencing.operation.TransformException;
import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.referencing.operation.matrix.Matrix1;
import org.apache.sis.referencing.operation.matrix.Matrix2;
import org.apache.sis.referencing.operation.provider.Affine;
@@ -310,9 +311,10 @@ class LinearTransform1D extends Abstract
return true;
}
if (mode != ComparisonMode.STRICT) {
- return equals(this, object, mode);
- }
- if (super.equals(object, mode)) {
+ if (object instanceof LinearTransform) {
+ return Matrices.equals(getMatrix(), ((LinearTransform)
object).getMatrix(), mode);
+ }
+ } else if (super.equals(object, mode)) {
final LinearTransform1D that = (LinearTransform1D) object;
return doubleToRawLongBits(this.scale) ==
doubleToRawLongBits(that.scale) &&
doubleToRawLongBits(this.offset) ==
doubleToRawLongBits(that.offset);
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java?rev=1606595&r1=1606594&r2=1606595&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ProjectiveTransform.java
[UTF-8] Sun Jun 29 20:13:03 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));
}
/**
@@ -516,9 +518,10 @@ class ProjectiveTransform extends Abstra
return true;
}
if (mode != ComparisonMode.STRICT) {
- return equals(this, object, mode);
- }
- if (super.equals(object, mode)) {
+ if (object instanceof LinearTransform) {
+ return Matrices.equals(this, ((LinearTransform)
object).getMatrix(), mode);
+ }
+ } else if (super.equals(object, mode)) {
final ProjectiveTransform that = (ProjectiveTransform) object;
return this.numRow == that.numRow &&
this.numCol == that.numCol &&