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: Minor cleanups.
Date Tue, 24 Mar 2020 22:43:16 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 ace1eed  Minor cleanups.
ace1eed is described below

commit ace1eed512dfcb0f3efcb2aeef7f9e548e9d03b1
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Mar 24 23:29:19 2020 +0100

    Minor cleanups.
---
 .../sis/coverage/grid/GridCoverageBuilder.java     |  5 ++++-
 .../java/org/apache/sis/image/DefaultIterator.java | 15 +------------
 .../java/org/apache/sis/image/PixelIterator.java   | 26 ++--------------------
 .../java/org/apache/sis/image/PlanarImage.java     | 15 +++++++------
 .../sis/internal/coverage/j2d/ImageLayout.java     | 13 ++++++-----
 .../java/org/apache/sis/geometry/Shapes2D.java     |  4 ++--
 6 files changed, 24 insertions(+), 54 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
index 813c4bc..42dfc46 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
@@ -180,7 +180,10 @@ public class GridCoverageBuilder {
     }
 
     /**
-     * Sets the domain envelope (including its CRS).
+     * Sets the domain as an enclosing envelope (including its CRS).
+     * The given envelope should contain all pixel area. For example the
+     * {@linkplain Envelope#getLowerCorner() envelope lower corner} should locate the lower-left
+     * (or upper-left, depending on <var>y</var> axis orientation) pixel corner,
not pixel center.
      * If the given envelope contains a CRS, then that CRS will be the coverage CRS.
      * A transform from grid indices to domain coordinates will be created automatically.
      * That transform will map grid dimensions to envelope dimensions in the same order
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
index 42dea65..7b9c93b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/DefaultIterator.java
@@ -180,19 +180,6 @@ class DefaultIterator extends WritablePixelIterator {
     }
 
     /**
-     * Stores the column (x) and row (y) indices of the current pixel.
-     */
-    @Override
-    public void getPosition(final double[] dest, final int offset) {
-        if (x >= lowerX && tileY < tileUpperY) {
-            dest[offset    ] = x;
-            dest[offset + 1] = y;
-        } else {
-            super.getPosition(dest, offset);        // Will cause exception to be thrown.
-        }
-    }
-
-    /**
      * Moves the pixel iterator to the given column (x) and row (y) indices.
      *
      * @param  px  the column index of the pixel to make current.
@@ -201,7 +188,7 @@ class DefaultIterator extends WritablePixelIterator {
      */
     @Override
     public void moveTo(final int px, final int py) {
-        if (px < lowerX || px >= upperX ||  py < lowerY || py >= upperY) {
+        if (px < lowerX || px >= upperX  ||  py < lowerY || py >= upperY) {
             throw new IndexOutOfBoundsException(Resources.format(Resources.Keys.OutOfIteratorDomain_2,
px, py));
         }
         if (image != null) {
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
index 5ea9d33..02d6ede 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PixelIterator.java
@@ -91,7 +91,7 @@ public abstract class PixelIterator {
     /**
      * The domain, in pixel coordinates, of the region traversed by this pixel iterator.
      * This may be smaller than the image or raster bounds, but not greater.
-     * The lower values are inclusive and the upper values exclusive.
+     * The lower values are inclusive and the upper values are exclusive.
      *
      * @see #getDomain()
      */
@@ -180,7 +180,7 @@ public abstract class PixelIterator {
     }
 
     /**
-     * Computes the intersection between the given bounds and and {@code subArea} if {@code
subArea} is non-null.
+     * Computes the intersection between the given bounds and {@code subArea} if {@code subArea} is
non-null.
      * If the result is empty, then the width and/or height are set to zero (not negative).
      */
     private static Rectangle intersection(int x, int y, int width, int height, Rectangle
subArea, Dimension window) {
@@ -542,28 +542,6 @@ public abstract class PixelIterator {
     public abstract Point getPosition();
 
     /**
-     * Stores in the specified array the column (x) and row (y) indices of the current pixel.
-     * This method is equivalent to invoking {@link #getPosition()} and copying the (<var>x</var>,
<var>y</var>)
-     * coordinates in {@code dest[offset]} and {@code dest[offset + 1]} respectively.
-     *
-     * <div class="note"><b>API note:</b>
-     * an array of type {@code double[]} is used for allowing the coordinates to be converted
with
-     * {@link org.opengis.referencing.operation.MathTransform#transform(double[], int, double[],
int, int)}.
-     * A typical use case is to apply a {@linkplain org.apache.sis.coverage.grid.GridGeometry#getGridToCRS
-     * grid to CRS} transform.</div>
-     *
-     * @param  dest    the array where to store the (<var>x</var>, <var>y</var>)
pixel coordinates.
-     * @param  offset  the offset where to store the coordinates in the specified array.
-     *
-     * @since 1.1
-     */
-    public void getPosition(final double[] dest, final int offset) {
-        final Point pos = getPosition();
-        dest[offset    ] = pos.x;
-        dest[offset + 1] = pos.y;
-    }
-
-    /**
      * Moves the pixel iterator to the given column (x) and row (y) indices. After this method
invocation,
      * the iterator state is as if the {@link #next()} method has been invoked just before
to reach the
      * specified position.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
index 7dd5393..254db3b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/PlanarImage.java
@@ -33,6 +33,7 @@ import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.internal.coverage.j2d.ImageUtilities;
 import org.apache.sis.internal.coverage.j2d.TileOpExecutor;
 import org.apache.sis.internal.coverage.j2d.ColorModelFactory;
+import org.apache.sis.internal.jdk9.JDK9;
 
 
 /**
@@ -283,7 +284,7 @@ public abstract class PlanarImage implements RenderedImage {
     @Override
     public int getTileGridXOffset() {
         // We may have temporary `int` overflow after multiplication but exact result after
addition.
-        return Math.toIntExact(getMinX() - getMinTileX() * ((long) getTileWidth()));
+        return Math.toIntExact(getMinX() - JDK9.multiplyFull(getMinTileX(), getTileWidth()));
     }
 
     /**
@@ -297,7 +298,7 @@ public abstract class PlanarImage implements RenderedImage {
      */
     @Override
     public int getTileGridYOffset() {
-        return Math.toIntExact(getMinY() - getMinTileY() * ((long) getTileHeight()));
+        return Math.toIntExact(getMinY() - JDK9.multiplyFull(getMinTileY(), getTileHeight()));
     }
 
     /**
@@ -372,7 +373,7 @@ public abstract class PlanarImage implements RenderedImage {
      * It is caller responsibility to ensure that all arguments are non-null and that the
rectangle is contained
      * inside both this image and the given raster.
      *
-     * @param  aoi  the region of this image to copy.
+     * @param  aoi     the region of this image to copy.
      * @param  raster  the raster to hold a copy of this image, or {@code null}.
      */
     private void copyData(final Rectangle aoi, final WritableRaster raster) {
@@ -447,10 +448,10 @@ public abstract class PlanarImage implements RenderedImage {
             if (sm.getWidth()  < tileWidth)  return "tileWidth";
             if (sm.getHeight() < tileHeight) return "tileHeight";
         }
-        if (((long) getNumXTiles()) * tileWidth  != getWidth())  return "numXTiles";
-        if (((long) getNumYTiles()) * tileHeight != getHeight()) return "numYTiles";
-        if (((long) getMinTileX())  * tileWidth  + getTileGridXOffset() != getMinX()) return
"tileX";
-        if (((long) getMinTileY())  * tileHeight + getTileGridYOffset() != getMinY()) return
"tileY";
+        if (JDK9.multiplyFull(getNumXTiles(), tileWidth)  != getWidth())  return "numXTiles";
+        if (JDK9.multiplyFull(getNumYTiles(), tileHeight) != getHeight()) return "numYTiles";
+        if (JDK9.multiplyFull(getMinTileX(),  tileWidth)  + getTileGridXOffset() != getMinX())
return "tileX";
+        if (JDK9.multiplyFull(getMinTileY(),  tileHeight) + getTileGridYOffset() != getMinY())
return "tileY";
         return null;
     }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
index b50aa9a..2cf3ce4 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/ImageLayout.java
@@ -50,9 +50,10 @@ public class ImageLayout {
 
     /**
      * The default instance which will target {@value ImageUtilities#DEFAULT_TILE_SIZE} pixels
as tile
-     * width and height.
+     * width and height. This default instance conservatively disallows tile sizes that are
not divisors
+     * of image size.
      */
-    public static final ImageLayout DEFAULT = new ImageLayout(null, true);
+    public static final ImageLayout DEFAULT = new ImageLayout(null, false);
 
     /**
      * Preferred size for tiles.
@@ -62,7 +63,7 @@ public class ImageLayout {
     private final int preferredTileWidth, preferredTileHeight;
 
     /**
-     * Whether this instance allow tiles that are only partially filled. A value of {@code
true} implies that
+     * Whether this instance allows tiles that are only partially filled. A value of {@code
true} implies that
      * tiles in the last row or in the last column may contain empty pixels. A value of {@code
false} implies
      * that this class will be unable to subdivide large images in smaller tiles if the image
size is a prime
      * number.
@@ -73,7 +74,7 @@ public class ImageLayout {
      * Creates a new image layout.
      *
      * @param  preferredTileSize  the preferred tile size, or {@code null} for the default
size.
-     * @param  allowPartialTiles  whether this instance allow tiles that are only partially
filled.
+     * @param  allowPartialTiles  whether this instance allows tiles that are only partially
filled.
      */
     protected ImageLayout(final Dimension preferredTileSize, final boolean allowPartialTiles)
{
         if (preferredTileSize != null) {
@@ -195,8 +196,8 @@ public class ImageLayout {
             }
         }
         /*
-         * If the image is already tiled, we may select smaller tiles if the original tiles
are too large
-         * but those smaller tiles must be divisors of the original size. This is necessary
because image
+         * If the image is already tiled, we may select smaller tiles if the original tiles
are too large.
+         * But those smaller tiles must be divisors of the original size. This is necessary
because image
          * operations may assume that a call to `source.getTile(…)` will return a tile
covering fully the
          * tile to compute.
          */
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
index 8b07e95..81d52ec 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/Shapes2D.java
@@ -163,7 +163,7 @@ public final class Shapes2D extends Static {
      * @param  envelope     the rectangle to transform (may be {@code null}).
      * @param  destination  the destination rectangle (may be {@code envelope}).
      *         If {@code null}, a new rectangle will be created and returned.
-     * @return {@code destination}, or a new rectangle if {@code destination} was non-null
and {@code envelope} was null.
+     * @return {@code destination}, or a new rectangle if {@code destination} was null and
{@code envelope} was non-null.
      * @throws TransformException if a transform failed.
      *
      * @see #transform(CoordinateOperation, Rectangle2D, Rectangle2D)
@@ -384,7 +384,7 @@ public final class Shapes2D extends Static {
      * @param  envelope     the rectangle to transform (may be {@code null}).
      * @param  destination  the destination rectangle (may be {@code envelope}).
      *         If {@code null}, a new rectangle will be created and returned.
-     * @return {@code destination}, or a new rectangle if {@code destination} was non-null
and {@code envelope} was null.
+     * @return {@code destination}, or a new rectangle if {@code destination} was null and
{@code envelope} was non-null.
      * @throws TransformException if a transform failed.
      *
      * @see #transform(MathTransform2D, Rectangle2D, Rectangle2D)


Mime
View raw message