This commit is a copy-and-paste of the isIdentity()
method that existed prior this commit,
modified for working as a static method instead than a member method and with the following code added:
tolerance = Math.abs(tolerance); ... Math.abs(... - ...) > tolerance
SIS has the same method in Matrices
, with the tolerance = abs(tolerance)
removed
for consistency with equals(..., tolerance)
methods and the abs(...) > tolerance
inverted to !(abs(...) <= tolerance)
for working with NaN. Since this is not original work,
having this method in SIS is okay.
Command line:
svn diff --extensions "--unified --ignore-space-change --ignore-all-space --ignore-eol-style" -r24484:24485 https://svn.osgeo.org/geotools/trunk/modules/library/referencing/src/main/java/org/geotools/referencing/operation/matrix/GeneralMatrix.java
Revision 24484 | Revision 24485 |
---|---|
private static final long serialVersionUID = 8447482612423035360L; /** * Constructs a square identity matrix of size {@code size} × {@code size}. */ public GeneralMatrix(final int size) { |
private static final long serialVersionUID = 8447482612423035360L; /** * Defaul tolerance value for floating point comparisons. */ public static final double EPS = 1E-6; /** * Constructs a square identity matrix of size {@code size} × {@code size}. */ public GeneralMatrix(final int size) { |
assert isAffine() : this; return true; } /** * {@inheritDoc} */ public final void multiply(final Matrix matrix) { |
assert isAffine() : this; return true; } /** * Returns {@code true} if this matrix is an identity matrix using the provided tolerance. * @since 2.3.1 */ public final boolean isIdentity(double tolerance) { return isIdentity(this, tolerance); } /** * Returns {@code true} if this matrix is an identity matrix using the provided tolerance. * @since 2.3.1 */ public final static boolean isIdentity(final XMatrix matrix,double tolerance) { tolerance=Math.abs(tolerance); final int numRow = matrix.getNumRow(); final int numCol = matrix.getNumCol(); if (numRow != numCol) { return false; } for (int j=0; j<numRow; j++) { for (int i=0; i<numCol; i++) { if (Math.abs(matrix.getElement(j,i)- (i==j ? 1 : 0))>tolerance) { return false; } } } assert matrix.isAffine() : matrix; return true; } /** * {@inheritDoc} */ public final void multiply(final Matrix matrix) { |