This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit ad6153efb4f6a28c7bc88ea10dd25b472fa2bb0c Author: Martin Desruisseaux <[email protected]> AuthorDate: Mon Jun 30 18:51:19 2025 +0200 Minor editions to new matrix methods: * Formatting (missing spaces before brackets). * Documentaton (the parameter name needs to be the same as in the parent class for allowing @inheritDoc to work fully). * Consolidation of argument checks. * Keep setter methods together. --- .../sis/referencing/operation/matrix/Matrix1.java | 14 +++--- .../sis/referencing/operation/matrix/Matrix2.java | 52 ++++++++++++---------- .../sis/referencing/operation/matrix/Matrix3.java | 17 ++++--- .../sis/referencing/operation/matrix/Matrix4.java | 19 ++++---- .../referencing/operation/matrix/MatrixSIS.java | 8 +--- 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java index a2fb7e1400..3b85ada5c0 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix1.java @@ -18,7 +18,6 @@ package org.apache.sis.referencing.operation.matrix; import org.opengis.referencing.operation.Matrix; import org.apache.sis.util.privy.Numerics; -import org.apache.sis.util.resources.Errors; /** @@ -240,16 +239,17 @@ public class Matrix1 extends MatrixSIS { /** * {@inheritDoc} + * + * @since 1.5 */ @Override - public double[] multiply(double[] v) { - if (v.length != 1) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, 1, v.length)); - } - return new double[]{ - m00 * v[0] + public double[] multiply(final double[] vector) { + ensureLengthMatch(1, vector); + return new double[] { + m00 * vector[0] }; } + /** * Normalizes all columns in-place. * For a 1×1 matrix with non-NaN value, this method sets the {@link #m00} value diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java index edd5d8dac9..6ee69302f4 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix2.java @@ -18,7 +18,6 @@ package org.apache.sis.referencing.operation.matrix; import org.opengis.referencing.operation.Matrix; import org.apache.sis.util.privy.Numerics; -import org.apache.sis.util.resources.Errors; /** @@ -232,6 +231,27 @@ public class Matrix2 extends MatrixSIS { m10 = elements[2]; m11 = elements[3]; } + /** + * Sets the elements to a rotation matrix of the given arithmetic angle. + * Angle 0 is oriented toward positive <var>x</bar> axis, + * rotation is counter-clockwise and the unit of measurement is radians. + * The resulting matrix is not affine in the sense of {@link #isAffine()}. + * The matrix is: + * + * <pre class="math"> + * ┌ ┐ + * │ cos(θ) −sin(θ) │ + * │ sin(θ) cos(θ) │ + * └ ┘</pre> + * + * @param θ arithmetic rotation angle in radians. + * @since 1.5 + */ + public void setToRotation(double θ) { + m00 = (m11 = Math.cos(θ)); + m01 = -(m10 = Math.sin(θ)); + } + /** * {@inheritDoc} * @@ -265,36 +285,20 @@ public class Matrix2 extends MatrixSIS { /** * {@inheritDoc} + * + * @since 1.5 */ @Override - public double[] multiply(double[] v) { - if (v.length != 2) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, 2, v.length)); - } - final double x = v[0]; - final double y = v[1]; - return new double[]{ + public double[] multiply(final double[] vector) { + ensureLengthMatch(2, vector); + final double x = vector[0]; + final double y = vector[1]; + return new double[] { m00 * x + m01 * y, m10 * x + m11 * y }; } - /** - * Set matrix to given rotation angle, - * Rotation is in counter-clockwise direction. - * Resulting matrix will not be affine. - * - * @param angleRad angle in radians - */ - public void setToRotation(double angleRad) { - final double sin = Math.sin(angleRad); - final double cos = Math.cos(angleRad); - m00 = cos; - m01 = -sin; - m10 = sin; - m11 = cos; - } - /** * {@inheritDoc} */ diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java index b62d749217..b3271aa890 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix3.java @@ -16,7 +16,6 @@ */ package org.apache.sis.referencing.operation.matrix; -import org.apache.sis.util.resources.Errors; import org.opengis.referencing.operation.Matrix; @@ -291,16 +290,16 @@ public class Matrix3 extends MatrixSIS { /** * {@inheritDoc} + * + * @since 1.5 */ @Override - public double[] multiply(double[] v) { - if (v.length != 3) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, 3, v.length)); - } - final double x = v[0]; - final double y = v[1]; - final double z = v[2]; - return new double[]{ + public double[] multiply(final double[] vector) { + ensureLengthMatch(3, vector); + final double x = vector[0]; + final double y = vector[1]; + final double z = vector[2]; + return new double[] { m00 * x + m01 * y + m02 * z, m10 * x + m11 * y + m12 * z, m20 * x + m21 * y + m22 * z diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java index 86b6e1cafb..7d53874a6b 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/Matrix4.java @@ -16,7 +16,6 @@ */ package org.apache.sis.referencing.operation.matrix; -import org.apache.sis.util.resources.Errors; import org.opengis.referencing.operation.Matrix; @@ -329,17 +328,17 @@ public class Matrix4 extends MatrixSIS { /** * {@inheritDoc} + * + * @since 1.5 */ @Override - public double[] multiply(double[] v) { - if (v.length != 4) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, 4, v.length)); - } - final double x = v[0]; - final double y = v[1]; - final double z = v[2]; - final double w = v[3]; - return new double[]{ + public double[] multiply(final double[] vector) { + ensureLengthMatch(4, vector); + final double x = vector[0]; + final double y = vector[1]; + final double z = vector[2]; + final double w = vector[3]; + return new double[] { m00 * x + m01 * y + m02 * z + m03 * w, m10 * x + m11 * y + m12 * z + m13 * w, m20 * x + m21 * y + m22 * z + m23 * w, diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/MatrixSIS.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/MatrixSIS.java index 951002c2bc..47a00b3333 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/MatrixSIS.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/matrix/MatrixSIS.java @@ -535,9 +535,7 @@ public abstract class MatrixSIS implements Matrix, LenientComparable, Cloneable, */ public double[] multiply(final double[] vector) { final int numCol = getNumCol(); - if (vector.length != numCol) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, numCol, vector.length)); - } + ensureLengthMatch(numCol, vector); final double[] target = new double[getNumRow()]; for (int j=0; j<target.length; j++) { Number sum = null; @@ -581,9 +579,7 @@ public abstract class MatrixSIS implements Matrix, LenientComparable, Cloneable, */ public void translate(final double[] vector) { final int numCol = getNumCol(); - if (vector.length != numCol) { - throw new MismatchedMatrixSizeException(Errors.format(Errors.Keys.UnexpectedArrayLength_2, numCol, vector.length)); - } + ensureLengthMatch(numCol, vector); final int numRow = getNumRow(); for (int j=0; j<numRow; j++) { Number sum = null;
