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 e7f297691fa61824d94e73d1ce95aca2124b8b8d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Sep 27 16:57:20 2022 +0200 Preserve the sign of scale factor in automatic "grid to CRS" transform. --- .../java/org/apache/sis/coverage/grid/ResampledGridCoverage.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java index e3114ab04a..40ed350813 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java +++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/ResampledGridCoverage.java @@ -377,15 +377,18 @@ final class ResampledGridCoverage extends DerivedGridCoverage { */ for (;;) { double max = -1; + int sign = 1; int tgDim = -1; // Grid dimension of maximal value. int tcDim = -1; // CRS dimension of maximal value. for (int i=0; i<mappedDim; i++) { // `ci` differs from `i` only if the source grid has "too much" dimensions. final int ci = (dimSelect != null) ? dimSelect[i] : i; for (int j=0; j<crsDim; j++) { - final double m = Math.abs(vectors.getElement(j, ci)); + final double v = vectors.getElement(j, ci); + final double m = Math.abs(v); if (m > max) { max = m; + sign = (v < 0) ? -1 : 1; // Like `Math.signum(…)` but without 0. tcDim = j; tgDim = ci; } @@ -399,7 +402,7 @@ final class ResampledGridCoverage extends DerivedGridCoverage { vectors.setElement(tcDim, i, Double.NaN); // For preventing this row to be selected again. } final DoubleDouble m = DoubleDouble.castOrCopy(magnitudes.getNumber(0, tgDim)); - m.inverseDivide(1); + m.inverseDivide(sign); crsToGrid.setNumber(tgDim, tcDim, m); // Scale factor from CRS coordinates to grid coordinates. /* * Move the point of interest in a place where conversion to source grid coordinates