sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Bug fix in the determination of matrix coefficients that we can move around `WraparoundTransform`.
Date Thu, 17 Sep 2020 11:11:34 GMT
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 bbf046c0173d395c4682424084c8b3444ccf1a67
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Sep 17 13:08:26 2020 +0200

    Bug fix in the determination of matrix coefficients that we can move around `WraparoundTransform`.
---
 .../org/apache/sis/coverage/grid/GridDerivation.java     |  4 +++-
 .../sis/internal/referencing/WraparoundTransform.java    | 16 ++++++++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index b8eb2be..9287864 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -556,7 +556,9 @@ public class GridDerivation {
                 indices = new GeneralEnvelope(dimension);
             }
             for (int i=0; i<dimension; i++) {
-                indices.setRange(i, baseExtent.getLow(i), baseExtent.getHigh(i) + 1.0);
+                long high = baseExtent.getHigh(i);
+                if (high != Long.MAX_VALUE) high++;                 // Increment before conversion
to `double`.
+                indices.setRange(i, baseExtent.getLow(i), high);
             }
             /*
              * Convert the target resolutions to grid cell subsamplings and adjust the extent
consequently.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
index cfbeb11..bb22229 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
@@ -487,22 +487,26 @@ public final class WraparoundTransform extends AbstractMathTransform
implements
             throws FactoryException
     {
         final long moveAll = Numerics.bitmask(dimension) - 1;
-        long canMoveAfter = moveAll;
+        long canMove = moveAll;
         /*
          * If any matrix row (output coordinate) uses the wraparound dimension as input,
          * then we can not move that row because the coordinate value may not be the same
          * after execution of `WraparoundTransform`.
          */
-        if (matrix.getNumCol() - 1 > wraparoundDimension) {
+        final int lastColumn = matrix.getNumCol() - 1;
+        if (wraparoundDimension < lastColumn) {
             for (int j = matrix.getNumRow(); --j >= 0;) {
                 final double v = matrix.getElement(j, wraparoundDimension);
                 if (v != (j == wraparoundDimension ? 1 : 0)) {
-                    canMoveAfter &= ~Numerics.bitmask(j);
+                    canMove &= ~Numerics.bitmask(j);
                 }
             }
         }
-        if (canMoveAfter != 0) {
-            if (canMoveAfter != moveAll) {
+        if (matrix.getElement(wraparoundDimension, lastColumn) != 0) {
+            canMove &= ~Numerics.bitmask(wraparoundDimension);
+        }
+        if (canMove != 0) {
+            if (canMove != moveAll) {
                 /*
                  * Create a matrix which will convert coordinates in all dimensions that
we can process
                  * before or after this `WraparoundTransform`. We start with a copy and set
to identity
@@ -512,7 +516,7 @@ public final class WraparoundTransform extends AbstractMathTransform implements
                  */
                 matrix = Matrices.copy(matrix);
                 for (int j = matrix.getNumRow() - 1; --j >=0;) {
-                    if ((canMoveAfter & Numerics.bitmask(j)) == 0) {    // True also
for dimensions ≥ 64.
+                    if ((canMove & Numerics.bitmask(j)) == 0) {       // True also for
dimensions ≥ 64.
                         for (int i=matrix.getNumCol(); --i >= 0;) {
                             matrix.setElement(j, i, (i == j) ? 1 : 0);
                         }


Mime
View raw message