sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1832809 - in /sis/branches/JDK8/core/sis-raster/src: main/java/org/apache/sis/coverage/grid/ test/java/org/apache/sis/coverage/grid/
Date Mon, 04 Jun 2018 10:30:04 GMT
Author: desruisseaux
Date: Mon Jun  4 10:30:04 2018
New Revision: 1832809

URL: http://svn.apache.org/viewvc?rev=1832809&view=rev
Log:
Use the 'long' primitive type instead of 'int' in GridExtent.
This force us to not implement GeoAPI interfaces for now (until https://github.com/opengeospatial/geoapi/issues/36)
is resolved.
But since those interfaces were not part of formal standard yet (they are in the "pending"
part of GeoAPI), we would not have implemented them in SIS release anyway.

Modified:
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
    sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java?rev=1832809&r1=1832808&r2=1832809&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridCoordinatesView.java
[UTF-8] Mon Jun  4 10:30:04 2018
@@ -18,26 +18,26 @@ package org.apache.sis.coverage.grid;
 
 import java.util.Arrays;
 import org.apache.sis.util.ArgumentChecks;
-import org.apache.sis.util.resources.Errors;
-
-// Branch-dependent imports
-import org.opengis.coverage.grid.GridCoordinates;
 
 
 /**
  * A view over the low or high grid envelope coordinates.
  * This is not a general-purpose grid coordinates since it assumes a {@link GridExtent} coordinates
layout.
  *
+ * <div class="note"><b>Upcoming API generalization:</b>
+ * this class may implement the {@code GridCoordinates} interface in a future Apache SIS
version.
+ * This is pending <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>.</div>
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-final class GridCoordinatesView implements GridCoordinates {
+final class GridCoordinatesView /* implements GridCoordinates */ {
     /**
      * A reference to the coordinate array of the enclosing grid envelope.
      */
-    private final int[] ordinates;
+    private final long[] ordinates;
 
     /**
      * Index of the first value in the {@link #ordinates} array.
@@ -48,7 +48,7 @@ final class GridCoordinatesView implemen
     /**
      * Creates a new view over the low or high coordinates.
      */
-    GridCoordinatesView(final int[] ordinates, final int offset) {
+    GridCoordinatesView(final long[] ordinates, final int offset) {
         this.ordinates = ordinates;
         this.offset = offset;
     }
@@ -56,7 +56,6 @@ final class GridCoordinatesView implemen
     /**
      * Returns the number of dimension.
      */
-    @Override
     public final int getDimension() {
         return ordinates.length >>> 1;
     }
@@ -64,16 +63,14 @@ final class GridCoordinatesView implemen
     /**
      * Returns all coordinate values.
      */
-    @Override
-    public final int[] getCoordinateValues() {
+    public final long[] getCoordinateValues() {
         return Arrays.copyOfRange(ordinates, offset, offset + getDimension());
     }
 
     /**
      * Returns the coordinate value for the specified dimension.
      */
-    @Override
-    public final int getCoordinateValue(final int index) {
+    public final long getCoordinateValue(final int index) {
         ArgumentChecks.ensureValidIndex(getDimension(), index);
         return ordinates[offset + index];
     }
@@ -81,10 +78,9 @@ final class GridCoordinatesView implemen
     /**
      * Do not allow modification of grid coordinates since they are backed by {@link GridExtent}.
      */
-    @Override
-    public void setCoordinateValue(final int index, int value) {
-        throw new UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableObject_1,
"GridCoordinates"));
-    }
+//  public void setCoordinateValue(final int index, long value) {
+//      throw new UnsupportedOperationException(Errors.format(Errors.Keys.UnmodifiableObject_1,
"GridCoordinates"));
+//  }
 
     /**
      * Returns a string representation of this grid coordinates for debugging purpose.
@@ -99,12 +95,12 @@ final class GridCoordinatesView implemen
      */
     @Override
     public final int hashCode() {
-        int code = -3;                              // Arbitrary seed for differentiating
from Arrays.hashCode(int[]).
+        long code = -3;                             // Arbitrary seed for differentiating
from Arrays.hashCode(long[]).
         final int end = offset + getDimension();
         for (int i=offset; i<end; i++) {
             code = 31 * code + ordinates[i];
         }
-        return code;
+        return Long.hashCode(code);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java?rev=1832809&r1=1832808&r2=1832809&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
[UTF-8] Mon Jun  4 10:30:04 2018
@@ -30,7 +30,6 @@ import org.apache.sis.geometry.GeneralDi
 
 // Branch-dependent imports
 import org.opengis.coverage.grid.GridEnvelope;
-import org.opengis.coverage.grid.GridCoordinates;
 
 
 /**
@@ -46,12 +45,16 @@ import org.opengis.coverage.grid.GridCoo
  *
  * {@code GridExtent} instances are unmodifiable, so they can be shared between different
{@link GridGeometry} instances.
  *
+ * <div class="note"><b>Upcoming API generalization:</b>
+ * this class may implement the {@code GridEnvelope} interface in a future Apache SIS version.
+ * This is pending <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>.</div>
+ *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @version 1.0
  * @since   1.0
  * @module
  */
-public class GridExtent implements GridEnvelope, Serializable {
+public class GridExtent implements Serializable {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -62,18 +65,18 @@ public class GridExtent implements GridE
      * while the last half contains maximum ordinates (<strong>inclusive</strong>).
Note that the
      * later is the opposite of Java2D usage but conform to ISO specification.
      */
-    private final int[] ordinates;
+    private final long[] ordinates;
 
     /**
      * Creates a new array of coordinates with the given number of dimensions.
      *
      * @throws IllegalArgumentException if the given number of dimensions is excessive.
      */
-    private static int[] allocate(final int dimension) throws IllegalArgumentException {
+    private static long[] allocate(final int dimension) throws IllegalArgumentException {
         if (dimension > Integer.MAX_VALUE / 2) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.ExcessiveNumberOfDimensions_1,
dimension));
         }
-        return new int[dimension << 1];
+        return new long[dimension << 1];
     }
 
     /**
@@ -83,11 +86,11 @@ public class GridExtent implements GridE
      * @throws IllegalArgumentException if a coordinate value in the low part is
      *         greater than the corresponding coordinate value in the high part.
      */
-    private static void checkCoherence(final int[] ordinates) throws IllegalArgumentException
{
+    private static void checkCoherence(final long[] ordinates) throws IllegalArgumentException
{
         final int dimension = ordinates.length >>> 1;
         for (int i=0; i<dimension; i++) {
-            final int lower = ordinates[i];
-            final int upper = ordinates[i + dimension];
+            final long lower = ordinates[i];
+            final long upper = ordinates[i + dimension];
             if (lower > upper) {
                 throw new IllegalArgumentException(Resources.format(
                         Resources.Keys.IllegalGridEnvelope_3, i, lower, upper));
@@ -123,7 +126,7 @@ public class GridExtent implements GridE
      * @see #getLow()
      * @see #getHigh()
      */
-    public GridExtent(final int[] low, final int[] high, final boolean isHighIncluded) {
+    public GridExtent(final long[] low, final long[] high, final boolean isHighIncluded)
{
         ArgumentChecks.ensureNonNull("high", high);
         final int dimension = high.length;
         if (low != null && low.length != dimension) {
@@ -181,7 +184,6 @@ public class GridExtent implements GridE
      *
      * @return the number of dimensions.
      */
-    @Override
     public final int getDimension() {
         return ordinates.length >>> 1;
     }
@@ -191,9 +193,11 @@ public class GridExtent implements GridE
      * The sequence contains a minimum value for each dimension of the grid coverage.
      *
      * @return the valid minimum grid coordinates, inclusive.
+     *
+     * @todo Pending resolution of <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>
+     *       before to become public API, in order to use the interface in return type.
      */
-    @Override
-    public GridCoordinates getLow() {
+    GridCoordinatesView getLow() {
         return new GridCoordinatesView(ordinates, 0);
     }
 
@@ -202,9 +206,11 @@ public class GridExtent implements GridE
      * The sequence contains a maximum value for each dimension of the grid coverage.
      *
      * @return the valid maximum grid coordinates, <strong>inclusive</strong>.
+     *
+     * @todo Pending resolution of <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>
+     *       before to become public API, in order to use the interface in return type.
      */
-    @Override
-    public GridCoordinates getHigh() {
+    GridCoordinatesView getHigh() {
         return new GridCoordinatesView(ordinates, getDimension());
     }
 
@@ -219,8 +225,7 @@ public class GridExtent implements GridE
      * @see #getLow()
      * @see #getHigh(int)
      */
-    @Override
-    public int getLow(final int index) {
+    public long getLow(final int index) {
         ArgumentChecks.ensureValidIndex(getDimension(), index);
         return ordinates[index];
     }
@@ -236,8 +241,7 @@ public class GridExtent implements GridE
      * @see #getHigh()
      * @see #getLow(int)
      */
-    @Override
-    public int getHigh(final int index) {
+    public long getHigh(final int index) {
         final int dimension = getDimension();
         ArgumentChecks.ensureValidIndex(dimension, index);
         return ordinates[index + dimension];
@@ -251,16 +255,15 @@ public class GridExtent implements GridE
      * @return the span at the given dimension.
      * @throws IndexOutOfBoundsException if the given index is negative or is equals or greater
      *         than the {@linkplain #getDimension() grid dimension}.
-     * @throws ArithmeticException if the span is too large for the {@code int} primitive
type.
+     * @throws ArithmeticException if the span is too large for the {@code long} primitive
type.
      *
      * @see #getLow(int)
      * @see #getHigh(int)
      */
-    @Override
-    public int getSpan(final int index) {
+    public long getSpan(final int index) {
         final int dimension = getDimension();
         ArgumentChecks.ensureValidIndex(dimension, index);
-        return Math.toIntExact(ordinates[dimension + index] - (ordinates[index] - 1L));
+        return Math.incrementExact(Math.subtractExact(ordinates[dimension + index], ordinates[index]));
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java?rev=1832809&r1=1832808&r2=1832809&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
[UTF-8] Mon Jun  4 10:30:04 2018
@@ -35,9 +35,6 @@ import org.apache.sis.internal.raster.Re
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 
-// Branch-dependent imports
-import org.opengis.coverage.grid.GridEnvelope;
-
 
 /**
  * Valid extent of grid coordinates together with the transform from those grid coordinates
@@ -217,6 +214,10 @@ public class GridGeometry implements Ser
      * (with pixels that may be tens of kilometres large) is a recurrent problem. We want
to encourage developers
      * to always think about wether their <cite>grid to CRS</cite> transform
is mapping pixel corner or center.</div>
      *
+     * <div class="note"><b>Upcoming API generalization:</b>
+     * the {@code extent} type of this method may be changed to {@code GridEnvelope} interface
in a future Apache SIS version.
+     * This is pending <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>.</div>
+     *
      * @param  extent     the valid extent of grid coordinates, or {@code null} if unknown.
      * @param  anchor     {@linkplain PixelInCell#CELL_CENTER Cell center} for OGC conventions
or
      *                    {@linkplain PixelInCell#CELL_CORNER cell corner} for Java2D/JAI
conventions.
@@ -227,7 +228,7 @@ public class GridGeometry implements Ser
      * @throws TransformException if the math transform can not compute the geospatial envelope
or the resolution
      *         from the grid envelope.
      */
-    public GridGeometry(final GridEnvelope extent, final PixelInCell anchor, final MathTransform
gridToCRS,
+    public GridGeometry(final GridExtent extent, final PixelInCell anchor, final MathTransform
gridToCRS,
             final CoordinateReferenceSystem crs) throws TransformException
     {
         if (gridToCRS != null) {
@@ -240,12 +241,12 @@ public class GridGeometry implements Ser
         } else if (crs == null) {
             ArgumentChecks.ensureNonNull("extent", extent);
         }
-        this.extent      = GridExtent.castOrCopy(extent);
+        this.extent      = extent;
         this.gridToCRS   = PixelTranslation.translate(gridToCRS, anchor, PixelInCell.CELL_CENTER);
         this.cornerToCRS = PixelTranslation.translate(gridToCRS, anchor, PixelInCell.CELL_CORNER);
         GeneralEnvelope env = null;
         if (extent != null && gridToCRS != null) {
-            env = this.extent.toCRS(cornerToCRS);
+            env = extent.toCRS(cornerToCRS);
             env.setCoordinateReferenceSystem(crs);
         } else if (crs != null) {
             env = new GeneralEnvelope(crs);
@@ -262,7 +263,7 @@ public class GridGeometry implements Ser
         if (mat != null) {
             resolution = resolution(mat, 1);
         } else if (extent != null && gridToCRS != null) {
-            resolution = resolution(gridToCRS.derivative(this.extent.getCentroid()), 0);
+            resolution = resolution(gridToCRS.derivative(extent.getCentroid()), 0);
         } else {
             resolution = null;
         }
@@ -362,11 +363,15 @@ public class GridGeometry implements Ser
      * for {@link java.awt.image.BufferedImage}, but may be non-zero for arbitrary {@link
RenderedImage}.
      * A grid with 512 cells can have a minimum coordinate of 0 and maximum of 511.
      *
+     * <div class="warning"><b>Upcoming API generalization:</b>
+     * the return type of this method may be changed to {@code GridEnvelope} interface in
a future Apache SIS version.
+     * This is pending <a href="https://github.com/opengeospatial/geoapi/issues/36">GeoAPI
update</a>.</div>
+     *
      * @return the valid extent of grid coordinates (never {@code null}).
      * @throws IncompleteGridGeometryException if this grid geometry has no extent —
      *         i.e. <code>{@linkplain #isDefined(int) isDefined}({@linkplain #EXTENT})</code>
returned {@code false}.
      */
-    public GridEnvelope getExtent() throws IncompleteGridGeometryException {
+    public GridExtent getExtent() throws IncompleteGridGeometryException {
         if (extent != null) {
             return extent;
         }

Modified: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java?rev=1832809&r1=1832808&r2=1832809&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/coverage/grid/GridGeometryTest.java
[UTF-8] Mon Jun  4 10:30:04 2018
@@ -28,9 +28,6 @@ import org.junit.Test;
 
 import static org.apache.sis.test.ReferencingAssert.*;
 
-// Branch-dependent imports
-import org.opengis.coverage.grid.GridEnvelope;
-
 
 /**
  * Tests the {@link GridGeometry} implementation.
@@ -44,7 +41,7 @@ public final strictfp class GridGeometry
     /**
      * Verifies grid extent coordinates.
      */
-    private static void assertExtentEquals(final GridEnvelope extent, final int[] low, final
int[] high) {
+    private static void assertExtentEquals(final GridExtent extent, final long[] low, final
long[] high) {
         assertArrayEquals("extent.low",  low,  extent.getLow() .getCoordinateValues());
         assertArrayEquals("extent.high", high, extent.getHigh().getCoordinateValues());
     }
@@ -56,8 +53,8 @@ public final strictfp class GridGeometry
      */
     @Test
     public void testSimple() throws TransformException {
-        final int[]         low      = new int[] {100, 300, 3, 6};
-        final int[]         high     = new int[] {200, 400, 4, 7};
+        final long[]         low     = new long[] {100, 300, 3, 6};
+        final long[]         high    = new long[] {200, 400, 4, 7};
         final GridExtent    extent   = new GridExtent(low, high, true);
         final MathTransform identity = MathTransforms.identity(4);
         final GridGeometry  grid     = new GridGeometry(extent, PixelInCell.CELL_CORNER,
identity, null);
@@ -102,8 +99,8 @@ public final strictfp class GridGeometry
      */
     @Test
     public void testShifted() throws TransformException {
-        final int[]         low      = new int[] { 0,   0, 2};
-        final int[]         high     = new int[] {99, 199, 4};
+        final long[]        low      = new long[] { 0,   0, 2};
+        final long[]        high     = new long[] {99, 199, 4};
         final GridExtent    extent   = new GridExtent(low, high, true);
         final MathTransform identity = MathTransforms.identity(3);
         final GridGeometry  grid     = new GridGeometry(extent, PixelInCell.CELL_CENTER,
identity, null);
@@ -147,8 +144,8 @@ public final strictfp class GridGeometry
     @Test
     public void testNonLinear() throws TransformException {
         final GridExtent extent = new GridExtent(
-                new int[] {0,     0, 2, 6},
-                new int[] {100, 200, 3, 9}, false);
+                new long[] {0,     0, 2, 6},
+                new long[] {100, 200, 3, 9}, false);
         final MathTransform horizontal = MathTransforms.linear(Matrices.create(3, 3, new
double[] {
                 0.5, 0,    12,
                 0,   0.25, -2,



Mime
View raw message