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 2013/09/11 22:53:46 UTC
svn commit: r1522032 - in /sis/branches/JDK7/core:
sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/
sis-utility/src/main/java/org/apache/sis/util/resources/
Author: desruisseaux
Date: Wed Sep 11 20:53:45 2013
New Revision: 1522032
URL: http://svn.apache.org/r1522032
Log:
Ported some more utility methods.
Modified:
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/matrix/MatrixSIS.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
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=1522032&r1=1522031&r2=1522032&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] Wed Sep 11 20:53:45 2013
@@ -26,10 +26,11 @@ import org.apache.sis.internal.util.Nume
// Related to JDK7
import java.util.Objects;
+import java.awt.geom.AffineTransform;
/**
- * Static utility methods for creating and manipulating {@link Matrix} instances.
+ * {@link Matrix} factory methods and utilities.
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4 (derived from geotk-2.2)
@@ -165,6 +166,38 @@ public final class Matrices extends Stat
}
/**
+ * Returns {@code true} if the given matrix is affine.
+ *
+ * @param matrix The matrix to test.
+ * @return {@code true} if the matrix is affine.
+ *
+ * @see MatrixSIS#isAffine()
+ * @see #toAffineTransform(Matrix)
+ */
+ public static boolean isAffine(final Matrix matrix) {
+ if (matrix instanceof MatrixSIS) {
+ return ((MatrixSIS) matrix).isAffine();
+ }
+ if (matrix instanceof AffineTransform) {
+ return true;
+ }
+ // Following is executed only if the given matrix is not a SIS implementation.
+ int j = matrix.getNumRow();
+ int i = matrix.getNumCol();
+ if (i != j--) {
+ return false; // Matrix is not square.
+ }
+ double e = 1;
+ while (--i >= 0) {
+ if (matrix.getElement(j, i) != e) {
+ return false;
+ }
+ e = 0;
+ }
+ return true;
+ }
+
+ /**
* Returns {@code true} if the given matrix is close to an identity matrix, given a tolerance threshold.
* This method is equivalent to computing the difference between the given matrix and an identity matrix
* of identical size, and returning {@code true} if and only if all differences are smaller than or equal
@@ -291,6 +324,29 @@ public final class Matrices extends Stat
}
/**
+ * Returns the given matrix as a Java2D affine transform.
+ *
+ * @param matrix The matrix to returns as an affine transform.
+ * @return The matrix argument if it can be safely casted (including {@code null} argument),
+ * or a copy of the given matrix otherwise.
+ * @throws IllegalArgumentException if the given matrix size is not 3×3 or if the matrix is not affine.
+ *
+ * @see #isAffine(Matrix)
+ */
+ public static AffineTransform toAffineTransform(final Matrix matrix) throws IllegalArgumentException {
+ if (matrix == null || matrix instanceof AffineTransform) {
+ return (AffineTransform) matrix;
+ }
+ MatrixSIS.ensureSizeMatch(3, matrix);
+ if (isAffine(matrix)) {
+ return new AffineTransform(matrix.getElement(0,0), matrix.getElement(1,0),
+ matrix.getElement(0,1), matrix.getElement(1,1),
+ matrix.getElement(0,2), matrix.getElement(1,2));
+ }
+ throw new IllegalStateException(Errors.format(Errors.Keys.NotAnAffineTransform));
+ }
+
+ /**
* Returns a unlocalized string representation of the given matrix.
* For each column, the numbers are aligned on the decimal separator.
*
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1522032&r1=1522031&r2=1522032&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java Wed Sep 11 20:53:45 2013
@@ -114,6 +114,8 @@ public abstract class MatrixSIS implemen
* only zeros, except in the last column which contains 1.
*
* @return {@code true} if this matrix is affine.
+ *
+ * @see Matrices#isAffine(Matrix)
*/
public abstract boolean isAffine();
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1522032&r1=1522031&r2=1522032&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Wed Sep 11 20:53:45 2013
@@ -481,6 +481,11 @@ public final class Errors extends Indexe
public static final int NotAUnicodeIdentifier_1 = 113;
/**
+ * Transform is not affine.
+ */
+ public static final int NotAnAffineTransform = 121;
+
+ /**
* Class ‘{0}’ is not a comparable.
*/
public static final int NotComparableClass_1 = 66;
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1522032&r1=1522031&r2=1522032&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Wed Sep 11 20:53:45 2013
@@ -101,6 +101,7 @@ NonAngularUnit_1 = \u201c
NonLinearUnit_1 = \u201c{0}\u201d is not a linear unit.
NonScaleUnit_1 = \u201c{0}\u201d is not a scale unit.
NonTemporalUnit_1 = \u201c{0}\u201d is not a time unit.
+NotAnAffineTransform = Transform is not affine.
NotANumber_1 = Argument \u2018{0}\u2019 shall not be NaN (Not-a-Number).
NotAPrimitiveWrapper_1 = Class \u2018{0}\u2019 is not a primitive type wrapper.
NotAUnicodeIdentifier_1 = Text \u201c{0}\u201d is not a Unicode identifier.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1522032&r1=1522031&r2=1522032&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Wed Sep 11 20:53:45 2013
@@ -91,6 +91,7 @@ NonAngularUnit_1 = \u201c
NonLinearUnit_1 = \u201c{0}\u201d n\u2019est pas une unit\u00e9 de longueurs.
NonScaleUnit_1 = \u201c{0}\u201d n\u2019est pas une unit\u00e9 d\u2019\u00e9chelles.
NonTemporalUnit_1 = \u201c{0}\u201d n\u2019est pas une unit\u00e9 de temps.
+NotAnAffineTransform = La transformation n\u2019est pas affine.
NotANumber_1 = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre NaN (Not-a-Number).
NotAPrimitiveWrapper_1 = La classe \u2018{0}\u2019 n\u2019est pas un adaptateur d\u2019un type primitif.
NotAUnicodeIdentifier_1 = Le texte \u201c{0}\u201d n\u2019est pas un identifiant Unicode.