sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Move a helper method.
Date Wed, 30 Jan 2019 12:15:59 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 244183a42ffe3598848ad5f18f1399d0305953b8
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jan 30 11:23:19 2019 +0100

    Move a helper method.
---
 .../apache/sis/coverage/grid/GridDerivation.java   | 25 +++-------------------
 .../org/apache/sis/coverage/grid/GridExtent.java   | 18 ++++++++++++++++
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
index e4ffb09..0e5adff 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/grid/GridDerivation.java
@@ -685,7 +685,7 @@ public class GridDerivation {
      * grid coordinates, 1 maps to {@linkplain GridExtent#getHigh(int) high grid coordinates}
and 0.5 maps the median point.
      * The slicing is applied on all dimensions except the specified dimensions to keep.
      *
-     * @param  sliceRatio        the ration to apply on all grid dimensions except the ones
to keep.
+     * @param  sliceRatio        the ratio to apply on all grid dimensions except the ones
to keep.
      * @param  dimensionsToKeep  the grid dimension to keep unchanged.
      * @return {@code this} for method call chaining.
      * @throws IncompleteGridGeometryException if the base grid geometry has no extent.
@@ -697,32 +697,13 @@ public class GridDerivation {
         subGridSetter = "sliceByRatio";
         final GridExtent extent = (baseExtent != null) ? baseExtent : base.getExtent();
         final GeneralDirectPosition slicePoint = new GeneralDirectPosition(extent.getDimension());
-        baseExtent = sliceByRatio(extent, slicePoint, sliceRatio, dimensionsToKeep);
+        baseExtent = extent.sliceByRatio(slicePoint, sliceRatio, dimensionsToKeep);
         if (subsampledExtent != null) {
-            subsampledExtent = sliceByRatio(subsampledExtent, slicePoint, sliceRatio, dimensionsToKeep);
+            subsampledExtent = subsampledExtent.sliceByRatio(slicePoint, sliceRatio, dimensionsToKeep);
         }
         return this;
     }
 
-    /**
-     * Returns a slice of the given grid extent computed by a ratio between 0 and 1 inclusive.
-     * This is for {@link #sliceByRatio(double, int...)} implementation only.
-     *
-     * @param  extent      the extent to slice.
-     * @param  slicePoint  a pre-allocated direct position to be overwritten by this method.
-     */
-    private static GridExtent sliceByRatio(final GridExtent extent, final GeneralDirectPosition
slicePoint,
-            final double sliceRatio, final int[] dimensionsToKeep)
-    {
-        for (int i=0; i<slicePoint.ordinates.length; i++) {
-            slicePoint.ordinates[i] = sliceRatio * (extent.getSize(i) - 1) + extent.getLow(i);
-        }
-        for (int i=0; i<dimensionsToKeep.length; i++) {
-            slicePoint.ordinates[dimensionsToKeep[i]] = Double.NaN;
-        }
-        return extent.slice(slicePoint, null);
-    }
-
     /*
      * RATIONAL FOR NOT PROVIDING reduce(int... dimensions) METHOD HERE: that method would
need to be the last method invoked,
      * otherwise it makes more complicated to implement other methods in this class.  Forcing
users to invoke 'build()' before
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 73f976d..b3cc40b 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
@@ -969,6 +969,24 @@ public class GridExtent implements Serializable {
     }
 
     /**
+     * Returns a slice of this given grid extent computed by a ratio between 0 and 1 inclusive.
+     * This is a helper method for {@link GridDerivation#sliceByRatio(double, int...)} implementation.
+     *
+     * @param  slicePoint        a pre-allocated direct position to be overwritten by this
method.
+     * @param  sliceRatio        the ratio to apply on all grid dimensions except the ones
to keep.
+     * @param  dimensionsToKeep  the grid dimension to keep unchanged.
+     */
+    final GridExtent sliceByRatio(final DirectPosition slicePoint, final double sliceRatio,
final int[] dimensionsToKeep) {
+        for (int i=slicePoint.getDimension(); --i >= 0;) {
+            slicePoint.setOrdinate(i, sliceRatio * (getSize(i) - 1) + getLow(i));
+        }
+        for (int i=0; i<dimensionsToKeep.length; i++) {
+            slicePoint.setOrdinate(dimensionsToKeep[i], Double.NaN);
+        }
+        return slice(slicePoint, null);
+    }
+
+    /**
      * Creates a new grid extent which represent a slice of this grid at the given point.
      * The given point may have less dimensions than this grid extent, in which case the
      * dimensions must be specified in the {@code modifiedDimensions} array. Coordinates


Mime
View raw message