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 362fdac88cbd691b3c55d413f60ed07cf2bce22f Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Apr 19 11:43:25 2022 +0200 `AffineTransform2D(double[])` constructor should have the same semantic than `AffineTransform(double[])`. --- .../referencing/j2d/AffineTransform2D.java | 32 ++++++++++++++++++---- .../referencing/j2d/ImmutableAffineTransform.java | 14 ++++++++-- .../operation/transform/MathTransforms.java | 2 +- .../apache/sis/internal/storage/image/Store.java | 7 ++--- 4 files changed, 42 insertions(+), 13 deletions(-) diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java index b1efc79793..ed3283ad80 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java @@ -48,7 +48,7 @@ import static org.apache.sis.util.ArgumentChecks.ensureDimensionMatches; * the {@link #equals(Object) equals} method, hopefully to occur only in exceptional corner cases. * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 0.7 + * @version 1.2 * @since 0.5 * @module */ @@ -84,16 +84,37 @@ public class AffineTransform2D extends ImmutableAffineTransform */ public AffineTransform2D(final AffineTransform transform) { super(transform); - forcePositiveZeros(); // Must be invoked before to set the 'matrix' value. + forcePositiveZeros(); // Must be invoked before to set the `matrix` value. matrix = new AffineMatrix(this, null); } /** - * Constructs a new {@code AffineTransform2D} from the given 9 or 18 values. + * Constructs a new transform from an array of values representing either the 4 non-translation + * entries or the 6 specifiable entries of the 3×3 matrix. * - * @param elements the matrix elements, optionally with error terms. + * @param elements the matrix elements in an array of length 4 or 6. */ public AffineTransform2D(final double[] elements) { + super(elements); + forcePositiveZeros(); + matrix = new AffineMatrix(this, null); + } + + /** + * Constructs a new {@code AffineTransform2D} from the 9 or 18 values of the given matrix. + * + * @param matrix the matrix from which to get the (potentially extended) elements. + */ + public AffineTransform2D(final ExtendedPrecisionMatrix matrix) { + this(matrix, matrix.getExtendedElements()); + } + + /** + * Work around for RFE #4093999 in Sun's bug database + * ("Relax constraint on placement of this()/super() call in constructors"). + */ + @Workaround(library="JDK", version="1.7") + private AffineTransform2D(final ExtendedPrecisionMatrix m, final double[] elements) { super(pz(elements[0]), pz(elements[3]), pz(elements[1]), pz(elements[4]), pz(elements[2]), pz(elements[5])); @@ -307,8 +328,7 @@ public class AffineTransform2D extends ImmutableAffineTransform * this matrix inversion is multiplied with other matrices: the double-double accuracy allows * us to better detect the terms that are 0 or 1 after matrix concatenation. */ - final AffineTransform2D work = new AffineTransform2D( - ((ExtendedPrecisionMatrix) Matrices.inverse(matrix)).getExtendedElements()); + AffineTransform2D work = new AffineTransform2D(((ExtendedPrecisionMatrix) Matrices.inverse(matrix))); work.inverse = this; inverse = work; // Set only on success. } diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java index 8d51544534..e45334e74b 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/ImmutableAffineTransform.java @@ -27,7 +27,7 @@ import org.apache.sis.internal.referencing.Resources; * throw an exception (which is the default), then {@code AffineTransform} is immutable. * * @author Martin Desruisseaux (IRD, Geomatys) - * @version 0.5 + * @version 1.2 * @since 0.5 * @module */ @@ -49,12 +49,22 @@ public class ImmutableAffineTransform extends AffineTransform { /** * Constructs a new transform that is a copy of the specified {@code AffineTransform} object. * - * @param tr The affine transform to copy. + * @param tr the affine transform to copy. */ public ImmutableAffineTransform(final AffineTransform tr) { super(tr); } + /** + * Constructs a new transform from an array of values representing either the 4 non-translation + * entries or the 6 specifiable entries of the 3×3 matrix. + * + * @param elements the matrix elements in an array of length 4 or 6. + */ + public ImmutableAffineTransform(final double[] elements) { + super(elements); + } + /** * Constructs a new transform from 6 values representing the 6 specifiable * entries of the 3×3 transformation matrix. Those values are given unchanged to the diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java index 2760359f73..7446511218 100644 --- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java +++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java @@ -202,7 +202,7 @@ public final class MathTransforms extends Static { } case 2: { if (matrix instanceof ExtendedPrecisionMatrix) { - return new AffineTransform2D(((ExtendedPrecisionMatrix) matrix).getExtendedElements()); + return new AffineTransform2D(((ExtendedPrecisionMatrix) matrix)); } else { return new AffineTransform2D( matrix.getElement(0,0), matrix.getElement(1,0), diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java index a3ff6092b8..c3ac161e47 100644 --- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java +++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/image/Store.java @@ -285,7 +285,7 @@ loop: for (int convention=0;; convention++) { final CharSequence[] lines = CharSequences.splitOnEOL(readAuxiliaryFile(wld, encoding)); int count = 0; final int expected = 6; // Expected number of elements. - final double[] m = new double[expected]; + final double[] elements = new double[expected]; for (int i=0; i<expected; i++) { final String line = lines[i].toString().trim(); if (!line.isEmpty() && line.charAt(0) != '#') { @@ -293,7 +293,7 @@ loop: for (int convention=0;; convention++) { throw new DataStoreContentException(errors().getString(Errors.Keys.TooManyOccurrences_2, expected, "coefficient")); } try { - m[count++] = Double.parseDouble(line); + elements[count++] = Double.parseDouble(line); } catch (NumberFormatException e) { throw new DataStoreContentException(errors().getString(Errors.Keys.ErrorInFileAtLine_2, content.getFilename(), i), e); } @@ -302,8 +302,7 @@ loop: for (int convention=0;; convention++) { if (count != expected) { throw new EOFException(errors().getString(Errors.Keys.UnexpectedEndOfFile_1, content.getFilename())); } - // TODO: provide a more direct way. - return new AffineTransform2D(new java.awt.geom.AffineTransform(m)); + return new AffineTransform2D(elements); } /**