sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Partial revert of previous commit: be overflow-tolerant only if we are going to clip the grid.
Date Fri, 11 Jan 2019 19:08:39 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 110cb92  Partial revert of previous commit: be overflow-tolerant only if we are going
to clip the grid.
110cb92 is described below

commit 110cb923a7c08f8e6bfde0d802da7b507c773715
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Jan 11 18:58:35 2019 +0100

    Partial revert of previous commit: be overflow-tolerant only if we are going to clip the
grid.
---
 .../main/java/org/apache/sis/coverage/grid/GridExtent.java  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 7c0230f..e325a5b 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -321,7 +321,7 @@ public class GridExtent implements Serializable {
             double max = envelope.getUpper(i);
             final boolean isMinValid = (min >= Long.MIN_VALUE);
             final boolean isMaxValid = (max <= Long.MAX_VALUE);
-            if (min > max || (!(isMinValid & isMaxValid) & enclosing == null))
{
+            if (min > max || (enclosing == null && !(isMinValid & isMaxValid)))
{
                 /*
                  * We do not throw an exception if 'enclosing' is non-null and envelope bounds
are NaN
                  * because this case occurs when the gridToCRS transform has a NaN scale
factor.  Such
@@ -381,13 +381,16 @@ public class GridExtent implements Serializable {
              * at the next step, which may cancel the margin effect.
              *
              * Note about overflow checks: if m>0, then x < x+m unless the result overflows
the 'long' capacity.
-             * We detect overflows for the m>0 case with compare(x, x+m) > 0. If m<0
the logic is inverted; this
-             * is the purpose of ^m.
              */
             if (margin != null && i < margin.length) {
                 final int m = margin[i];
-                if ((Long.compare(lower, lower -= m) ^ m) < 0) lower = Long.MIN_VALUE;
     // Clamp to MIN/MAX if overflow.
-                if ((Long.compare(upper, upper += m) ^ m) > 0) upper = Long.MAX_VALUE;
+                if (enclosing != null && m > 0) {
+                    if (lower < (lower -= m)) lower = Long.MIN_VALUE;       // Clamp to
MIN/MAX if overflow.
+                    if (upper > (upper += m)) upper = Long.MAX_VALUE;
+                } else {
+                    lower = Math.subtractExact(lower, m);
+                    upper = Math.addExact(upper, m);
+                }
             }
             if (lower > upper) {
                 upper += (lower - upper) >>> 1;         // (upper - lower) as unsigned
integer: overflow-safe.


Mime
View raw message