Author: desruisseaux
Date: Sat Jun 28 00:11:29 2014
New Revision: 1606273
URL: http://svn.apache.org/r1606273
Log:
Fix a never-ending loop. Opportunist replacement of hard-coded values by
constants.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineMatrix.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineMatrix.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineMatrix.java?rev=1606273&r1=1606272&r2=1606273&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineMatrix.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineMatrix.java
[UTF-8] Sat Jun 28 00:11:29 2014
@@ -42,6 +42,27 @@ final class AffineMatrix implements Exte
private static final long serialVersionUID = 1605578645060388327L;
/**
+ * The number of rows and columns of this matrix.
+ */
+ private static final int SIZE = 3;
+
+ /**
+ * The length of an array containing all matrix elements.
+ */
+ private static final int LENGTH = SIZE * SIZE;
+
+ /**
+ * The length of an array containing only the matrix elements to be stored.
+ * The last row is omitted because it is assumed to contain (0 0 1).
+ */
+ private static final int LENGTH_STORED = (SIZE - 1) * SIZE;
+
+ /**
+ * The length of an array containing all matrix elements together with
error terms.
+ */
+ private static final int LENGTH_EXTENDED = 2 * LENGTH;
+
+ /**
* The transform from which to get the matrix terms.
*/
private final AffineTransform transform;
@@ -60,12 +81,22 @@ final class AffineMatrix implements Exte
*/
AffineMatrix(final AffineTransform transform, final double[] elements) {
this.transform = transform;
- if (elements != null && elements.length >= 15) {
- errors = Arrays.copyOfRange(elements, 9, 15);
- } else {
- errors = null;
+ if (elements != null) {
+ assert elements.length == LENGTH || elements.length ==
LENGTH_EXTENDED;
+ if (elements.length == LENGTH_EXTENDED) {
+ errors = Arrays.copyOfRange(elements, LENGTH, LENGTH +
LENGTH_STORED);
+ /*
+ * At this point we could check:
+ *
+ * assert Arrays.equals(elements, getExtendedElements());
+ *
+ * but we do not, because the terms in the last row may not be
exactly 0 or 1
+ * because of rounding errors.
+ */
+ return;
+ }
}
- assert (elements == null) || Arrays.equals(elements,
getExtendedElements());
+ errors = null;
}
/**
@@ -73,7 +104,7 @@ final class AffineMatrix implements Exte
*/
@Override
public int getNumRow() {
- return 3;
+ return SIZE;
}
/**
@@ -81,7 +112,7 @@ final class AffineMatrix implements Exte
*/
@Override
public int getNumCol() {
- return 3;
+ return SIZE;
}
/**
@@ -97,9 +128,9 @@ final class AffineMatrix implements Exte
*/
@Override
public double[] getExtendedElements() {
- final double[] elements = new double[errors != null ? 18 : 9];
+ final double[] elements = new double[errors != null ? LENGTH_EXTENDED
: LENGTH];
if (errors != null) {
- System.arraycopy(errors, 0, elements, 9, 6);
+ System.arraycopy(errors, 0, elements, LENGTH, LENGTH_STORED);
}
elements[0] = transform.getScaleX();
elements[1] = transform.getShearX();
@@ -116,9 +147,9 @@ final class AffineMatrix implements Exte
*/
@Override
public final double getElement(final int row, final int column) {
- ArgumentChecks.ensureBetween("row", 0, 3, row);
- ArgumentChecks.ensureBetween("column", 0, 3, column);
- switch (row * 3 + column) {
+ ArgumentChecks.ensureBetween("row", 0, SIZE, row);
+ ArgumentChecks.ensureBetween("column", 0, SIZE, column);
+ switch (row * SIZE + column) {
case 0: return transform.getScaleX();
case 1: return transform.getShearX();
case 2: return transform.getTranslateX();
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java?rev=1606273&r1=1606272&r2=1606273&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] Sat Jun 28 00:11:29 2014
@@ -123,8 +123,6 @@ public class AffineTransform2D extends I
pz(elements[1]), pz(elements[4]),
pz(elements[2]), pz(elements[5]));
matrix = new AffineMatrix(this, elements);
- assert elements.length == 9 || elements.length == 18;
- assert elements[6] == 0 && elements[7] == 0 && elements[8] == 1;
}
/**
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1606273&r1=1606272&r2=1606273&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Sat Jun 28 00:11:29 2014
@@ -906,14 +906,11 @@ public abstract class AbstractMathTransf
*/
static boolean equals(final LinearTransform t1, final Object t2, final
ComparisonMode mode) {
if (t2 instanceof LinearTransform) {
- final Matrix m1 = t1.getMatrix();
- if (m1 != null) {
- final Matrix m2 = ((LinearTransform) t2).getMatrix();
- if (m1 instanceof LenientComparable) {
- return ((LenientComparable) m1).equals(m2, mode);
- }
- return Matrices.equals(m1, m2, mode);
- }
+ /*
+ * 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;
}