You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2019/01/11 15:19:29 UTC

[sis] branch geoapi-4.0 updated (bedebb4 -> d4ca8e1)

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a change to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git.


    from bedebb4  GridGeometry : add rounding parameter
     new c14923e  Fix @link javadoc tags for method signature change.
     new d4ca8e1  When adding a margin to a grid extent, need to check for overflow.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/org/apache/sis/coverage/grid/GridExtent.java   | 10 +++++++---
 .../main/java/org/apache/sis/coverage/grid/GridGeometry.java | 12 ++++++------
 .../java/org/apache/sis/coverage/grid/GridGeometryTest.java  |  6 +++---
 3 files changed, 16 insertions(+), 12 deletions(-)


[sis] 01/02: Fix @link javadoc tags for method signature change.

Posted by de...@apache.org.
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 c14923e23081545b010c0a2aaa38daf619f07250
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Jan 11 16:03:52 2019 +0100

    Fix @link javadoc tags for method signature change.
---
 .../main/java/org/apache/sis/coverage/grid/GridExtent.java   |  2 +-
 .../main/java/org/apache/sis/coverage/grid/GridGeometry.java | 12 ++++++------
 .../java/org/apache/sis/coverage/grid/GridGeometryTest.java  |  6 +++---
 3 files changed, 10 insertions(+), 10 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 046662a..d1f396b 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
@@ -927,7 +927,7 @@ public class GridExtent implements Serializable {
      * @return the subsampled extent, or {@code this} is subsampling results in the same extent.
      * @throws IllegalArgumentException if a period is not greater than zero.
      *
-     * @see GridGeometry#subgrid(Envelope, double...)
+     * @see GridGeometry#subgrid(Envelope, GridRoundingMode, double...)
      */
     public GridExtent subsample(final int... periods) {
         ArgumentChecks.ensureNonNull("periods", periods);
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 9212df5..6e13e5f 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -239,7 +239,7 @@ public class GridGeometry implements Serializable {
     /**
      * Creates a new grid geometry derived from the given grid geometry with a new extent and a modified transform.
      * This constructor is used for creating a grid geometry over a subregion (for example with the grid extent
-     * computed by {@link #subExtent(Envelope)}) or grid geometry for a subsampled raster.
+     * computed by {@link #subExtent(Envelope, GridRoundingMode)}) or grid geometry for a subsampled raster.
      *
      * <p>If {@code toOther} is non-null, it should be a transform from the given {@code extent} coordinates to the
      * {@code other} grid coordinates. That transform should be merely a {@linkplain MathTransforms#scale(double...)
@@ -258,8 +258,8 @@ public class GridGeometry implements Serializable {
      * @throws NullPointerException if {@code extent} is {@code null} and the other grid geometry contains no other information.
      * @throws TransformException if the math transform can not compute the geospatial envelope from the grid extent.
      *
-     * @see #subExtent(Envelope)
-     * @see #subgrid(Envelope, double...)
+     * @see #subExtent(Envelope, GridRoundingMode)
+     * @see #subgrid(Envelope, GridRoundingMode, double...)
      */
     GridGeometry(final GridGeometry other, final GridExtent extent, final MathTransform toOther) throws TransformException {
         final int dimension = other.getDimension();
@@ -628,7 +628,7 @@ public class GridGeometry implements Serializable {
      * {@linkplain #getGridToCRS(PixelInCell) transformed} to the "real world" coordinate system.
      * The initial envelope encompasses all cell surfaces, from the left border of leftmost cell
      * to the right border of the rightmost cell and similarly along other axes.
-     * If this grid geometry is a {@linkplain #subgrid(Envelope, double...) subgrid}, then the envelope is also
+     * If this grid geometry is a {@linkplain #subgrid(Envelope, GridRoundingMode, double...) subgrid}, then the envelope is also
      * {@linkplain GeneralEnvelope#intersect(Envelope) clipped} to the envelope of the original (non subsampled) grid geometry.
      *
      * @return the bounding box in "real world" coordinates (never {@code null}).
@@ -684,7 +684,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no extent or no "grid to CRS" transform.
      * @throws IllegalGridGeometryException if an error occurred while converting the envelope coordinates to grid coordinates.
      *
-     * @see #subgrid(Envelope, double...)
+     * @see #subgrid(Envelope, GridRoundingMode, double...)
      */
     public GridExtent subExtent(final Envelope areaOfInterest, final GridRoundingMode roundingMode) {
         ArgumentChecks.ensureNonNull("areaOfInterest", areaOfInterest);
@@ -1060,7 +1060,7 @@ public class GridGeometry implements Serializable {
      * @throws IncompleteGridGeometryException if this grid geometry has no extent or no "grid to CRS" transform.
      * @throws IllegalGridGeometryException if an error occurred while converting the envelope coordinates to grid coordinates.
      *
-     * @see #subExtent(Envelope)
+     * @see #subExtent(Envelope, GridRoundingMode)
      * @see GridExtent#subsample(int[])
      */
     public GridGeometry subgrid(final Envelope areaOfInterest, final GridRoundingMode roundingMode,
diff --git a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
index 6209f8d..9fb9e86 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
@@ -239,7 +239,7 @@ public final strictfp class GridGeometryTest extends TestCase {
     }
 
     /**
-     * Tests {@link GridGeometry#subExtent(Envelope)}.
+     * Tests {@link GridGeometry#subExtent(Envelope, GridRoundingMode)}.
      */
     @Test
     @DependsOnMethod("testFromGeospatialEnvelope")
@@ -269,7 +269,7 @@ public final strictfp class GridGeometryTest extends TestCase {
     }
 
     /**
-     * Tests {@link GridGeometry#subExtent(Envelope)} with a non-linear "grid to CRS" transform.
+     * Tests {@link GridGeometry#subExtent(Envelope, GridRoundingMode)} with a non-linear "grid to CRS" transform.
      */
     @Test
     @DependsOnMethod({"testNonLinear", "testSubExtent"})
@@ -306,7 +306,7 @@ public final strictfp class GridGeometryTest extends TestCase {
     }
 
     /**
-     * Tests {@link GridGeometry#subgrid(Envelope, double...)}.
+     * Tests {@link GridGeometry#subgrid(Envelope, GridRoundingMode, double...)}.
      *
      * @throws TransformException if an error occurred during computation.
      */


[sis] 02/02: When adding a margin to a grid extent, need to check for overflow.

Posted by de...@apache.org.
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 d4ca8e15494e59bfc22f8d6a4f52ee225281d865
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Jan 11 16:15:55 2019 +0100

    When adding a margin to a grid extent, need to check for overflow.
---
 .../src/main/java/org/apache/sis/coverage/grid/GridExtent.java    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 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 d1f396b..7c0230f 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
@@ -379,11 +379,15 @@ public class GridExtent implements Serializable {
              * If the user specified a margin, add it now. The margin dimension indices follow the envelope
              * dimension indices.  Note that the resulting extent will be intersected with enclosing extent
              * 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];
-                lower = Math.subtractExact(lower, m);
-                upper = Math.addExact(upper, m);
+                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 (lower > upper) {
                 upper += (lower - upper) >>> 1;         // (upper - lower) as unsigned integer: overflow-safe.