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: Share code between GridCoverage and GridCoverage2D for implementation of their `evaluate(DirectPosition, double[])` method. Also split GridCoverage2DTest in two test methods.
Date Mon, 23 Dec 2019 13:52:22 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 e79c07b  Share code between GridCoverage and GridCoverage2D for implementation of
their `evaluate(DirectPosition, double[])` method. Also split GridCoverage2DTest in two test
methods.
e79c07b is described below

commit e79c07bd8e1bc010dbd9f2b3e9aeb3813a99af31
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Dec 23 14:42:39 2019 +0100

    Share code between GridCoverage and GridCoverage2D for implementation of their `evaluate(DirectPosition,
double[])` method.
    Also split GridCoverage2DTest in two test methods.
---
 .../coverage/grid/FractionalGridCoordinates.java   |  39 +++++++
 .../org/apache/sis/coverage/grid/GridCoverage.java |  48 ++++++---
 .../apache/sis/coverage/grid/GridCoverage2D.java   |  85 ++++++++--------
 .../org/apache/sis/coverage/grid/GridExtent.java   |   3 +-
 .../sis/coverage/grid/GridCoverage2DTest.java      | 113 +++++++++++++--------
 5 files changed, 188 insertions(+), 100 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/FractionalGridCoordinates.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/FractionalGridCoordinates.java
index 89cedbb..bab43ac 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/FractionalGridCoordinates.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/FractionalGridCoordinates.java
@@ -441,6 +441,45 @@ public class FractionalGridCoordinates implements GridCoordinates, Serializable
     }
 
     /**
+     * Creates an error message for a grid coordinates out of bounds.
+     * This method tries to detect the dimension of the out-of-bounds
+     * coordinate by searching for the dimension with largest error.
+     *
+     * @param  bounds  the expected bounds, or {@code null} if unknown.
+     * @return message to provide to {@link PointOutsideCoverageException},
+     *         or {@code null} if the given bounds were null.
+     */
+    final String pointOutsideCoverage(final GridExtent bounds) {
+        if (bounds == null) {
+            return null;
+        }
+        int    axis     = 0;
+        long   validMin = 0;
+        long   validMax = 0;
+        double distance = 0;
+        for (int i=bounds.getDimension(); --i >= 0;) {
+            final long low  = bounds.getLow(i);
+            final long high = bounds.getHigh(i);
+            final double c  = coordinates[i];
+            double d = low - c;
+            if (!(d > distance)) {              // Use '!' for entering in this block
if `d` is NaN.
+                d = c - high;
+                if (!(d > distance)) {          // Use '!' for skipping this coordinate
if `d` is NaN.
+                    continue;
+                }
+            }
+            axis     = i;
+            validMin = low;
+            validMax = high;
+            distance = d;
+        }
+        final StringBuilder b = new StringBuilder();
+        writeCoordinates(b);
+        return Resources.format(Resources.Keys.GridCoordinateOutsideCoverage_4,
+                bounds.getAxisIdentification(axis, axis), validMin, validMax, b.toString());
+    }
+
+    /**
      * Returns a string representation of this grid coordinates for debugging purpose.
      */
     @Override
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
index 1f182d3..08513af 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
@@ -21,7 +21,6 @@ import java.util.Collection;
 import java.util.Locale;
 import java.util.Objects;
 import java.awt.image.RenderedImage;
-import org.opengis.coverage.PointOutsideCoverageException;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.datum.PixelInCell;
@@ -30,7 +29,6 @@ import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.coverage.SubspaceNotSpecifiedException;
-import org.apache.sis.image.PixelIterator;
 import org.apache.sis.util.collection.DefaultTreeTable;
 import org.apache.sis.util.collection.TableColumn;
 import org.apache.sis.util.collection.TreeTable;
@@ -41,6 +39,7 @@ import org.apache.sis.util.Debug;
 
 // Branch-specific imports
 import org.opengis.coverage.CannotEvaluateException;
+import org.opengis.coverage.PointOutsideCoverageException;
 
 
 /**
@@ -61,7 +60,7 @@ public abstract class GridCoverage {
      *
      * @see #getGridGeometry()
      */
-    private final GridGeometry gridGeometry;
+    final GridGeometry gridGeometry;
 
     /**
      * List of sample dimension (band) information for the grid coverage. Information include
such things
@@ -186,13 +185,13 @@ public abstract class GridCoverage {
      * @throws PointOutsideCoverageException if the evaluation failed because the input point
      *         has invalid coordinates.
      * @throws CannotEvaluateException if the values can not be computed at the specified
coordinate
-     *         for an other reason. It may be thrown if the coverage data type can not be
converted
+     *         for another reason. It may be thrown if the coverage data type can not be
converted
      *         to {@code double} by an identity or widening conversion. Subclasses may relax
this
      *         constraint if appropriate.
      *
      * @since 1.1
      */
-    public double[] evaluate(final DirectPosition point, double[] buffer) throws CannotEvaluateException
{
+    public double[] evaluate(final DirectPosition point, final double[] buffer) throws CannotEvaluateException
{
         /*
          * TODO: instead of restricting to a single point, keep the automatic size (1 or
2),
          * invoke render for each plan, then interpolate. We would keep a value of 1 in the
@@ -201,19 +200,42 @@ public abstract class GridCoverage {
         final long[] size = new long[gridGeometry.getDimension()];
         java.util.Arrays.fill(size, 1);
         try {
-            final GridExtent subExtent = toGridCoordinates(point).toExtent(gridGeometry.extent,
size);
-            final RenderedImage image = render(subExtent);
-            final PixelIterator ite = PixelIterator.create(image);  // TODO: avoid costly
creation of PixelIterator here.
-            ite.moveTo(0, 0);
-            return ite.getPixel(buffer);
-        } catch (ArithmeticException | DisjointExtentException ex) {
-            throw (PointOutsideCoverageException) new PointOutsideCoverageException(ex.getMessage(),
point).initCause(ex);
-        } catch (IllegalArgumentException | TransformException ex) {
+            final FractionalGridCoordinates gc = toGridCoordinates(point);
+            try {
+                final GridExtent subExtent = gc.toExtent(gridGeometry.extent, size);
+                return evaluate(render(subExtent), 0, 0, buffer);
+            } catch (ArithmeticException | IndexOutOfBoundsException | DisjointExtentException
ex) {
+                throw (PointOutsideCoverageException) new PointOutsideCoverageException(
+                        gc.pointOutsideCoverage(gridGeometry.extent), point).initCause(ex);
+            }
+        } catch (PointOutsideCoverageException ex) {
+            ex.setOffendingLocation(point);
+            throw ex;
+        } catch (RuntimeException | TransformException ex) {
             throw new CannotEvaluateException(ex.getMessage(), ex);
         }
     }
 
     /**
+     * Gets sample values from the given image at the given index. This method does not verify
+     * explicitly if the coordinates are out of bounds; we rely on the checks performed by
the
+     * image and sample model implementations.
+     *
+     * @param  data    the data from which to get the sample values.
+     * @param  x       column index of the value to get.
+     * @param  y       row index of the value to get.
+     * @param  buffer  an array in which to store values, or {@code null} to create a new
array.
+     * @return the {@code buffer} array, or a newly created array if {@code buffer} was null.
+     * @throws ArithmeticException if an integer overflow occurred while computing indices.
+     * @throws IndexOutOfBoundsException if a coordinate is out of bounds.
+     */
+    static double[] evaluate(final RenderedImage data, final int x, final int y, final double[]
buffer) {
+        final int tx = Math.floorDiv(Math.subtractExact(x, data.getTileGridXOffset()), data.getTileWidth());
+        final int ty = Math.floorDiv(Math.subtractExact(y, data.getTileGridYOffset()), data.getTileHeight());
+        return data.getTile(tx, ty).getPixel(x, y, buffer);
+    }
+
+    /**
      * Converts the specified geospatial position to grid coordinates. If the given position
      * is associated to a non-null coordinate reference system (CRS) different than the CRS
      * of this coverage, then this method automatically transforms that position to the
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
index d360e57..2e2d9d0 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -31,8 +31,6 @@ import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.datum.PixelInCell;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
-import org.opengis.coverage.CannotEvaluateException;
-import org.opengis.coverage.PointOutsideCoverageException;
 import org.apache.sis.coverage.SampleDimension;
 import org.apache.sis.internal.coverage.ImageUtilities;
 import org.apache.sis.internal.coverage.ConvertedGridCoverage;
@@ -44,6 +42,10 @@ import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.Workaround;
 
+// Branch-specific imports
+import org.opengis.coverage.CannotEvaluateException;
+import org.opengis.coverage.PointOutsideCoverageException;
+
 
 /**
  * Basic access to grid data values backed by a two-dimensional {@link RenderedImage}.
@@ -107,8 +109,8 @@ public class GridCoverage2D extends GridCoverage {
 
     /**
      * The two-dimensional components of the coordinate reference system and "grid to CRS"
transform.
-     * This is derived from {@link #getGridGeometry()} when first needed, retaining only
the components
-     * at dimension indices {@link #xDimension} and {@link #yDimension}.
+     * This is derived from {@link #gridGeometry} when first needed, retaining only the components
at
+     * dimension indices {@link #xDimension} and {@link #yDimension}.
      *
      * @see #getGridGeometry2D()
      */
@@ -362,7 +364,7 @@ public class GridCoverage2D extends GridCoverage {
      */
     public synchronized GridGeometry getGridGeometry2D() {
         if (gridGeometry2D == null) {
-            gridGeometry2D = getGridGeometry().reduce(xDimension, yDimension);
+            gridGeometry2D = gridGeometry.reduce(xDimension, yDimension);
         }
         return gridGeometry2D;
     }
@@ -416,6 +418,40 @@ public class GridCoverage2D extends GridCoverage {
     }
 
     /**
+     * Returns a sequence of double values for a given point in the coverage.
+     * The CRS of the given point may be any coordinate reference system,
+     * or {@code null} for the same CRS than this coverage.
+     * The returned sequence contains a value for each {@linkplain SampleDimension sample
dimension}.
+     *
+     * @param  point   the coordinate point where to evaluate.
+     * @param  buffer  an array in which to store values, or {@code null} to create a new
array.
+     * @return the {@code buffer} array, or a newly created array if {@code buffer} was null.
+     * @throws PointOutsideCoverageException if the evaluation failed because the input point
+     *         has invalid coordinates.
+     * @throws CannotEvaluateException if the values can not be computed at the specified
coordinate
+     *         for another reason.
+     */
+    @Override
+    public double[] evaluate(final DirectPosition point, final double[] buffer) throws CannotEvaluateException
{
+        try {
+            final FractionalGridCoordinates gc = toGridCoordinates(point);
+            try {
+                final int x = Math.toIntExact(Math.addExact(gc.getCoordinateValue(xDimension),
gridToImageX));
+                final int y = Math.toIntExact(Math.addExact(gc.getCoordinateValue(yDimension),
gridToImageY));
+                return evaluate(data, x, y, buffer);
+            } catch (ArithmeticException | IndexOutOfBoundsException | DisjointExtentException
ex) {
+                throw (PointOutsideCoverageException) new PointOutsideCoverageException(
+                        gc.pointOutsideCoverage(gridGeometry.extent), point).initCause(ex);
+            }
+        } catch (PointOutsideCoverageException ex) {
+            ex.setOffendingLocation(point);
+            throw ex;
+        } catch (RuntimeException | TransformException ex) {
+            throw new CannotEvaluateException(ex.getMessage(), ex);
+        }
+    }
+
+    /**
      * Returns a grid data region as a rendered image. The {@code sliceExtent} argument
      * specifies the area of interest and may be {@code null} for requesting the whole image.
      * The coordinates given by {@link RenderedImage#getMinX()} and {@link RenderedImage#getMinY()
getMinY()}
@@ -438,7 +474,7 @@ public class GridCoverage2D extends GridCoverage {
         if (sliceExtent == null) {
             return data;
         }
-        final GridExtent extent = getGridGeometry().extent;
+        final GridExtent extent = gridGeometry.extent;
         if (extent != null) {
             for (int i = Math.min(sliceExtent.getDimension(), extent.getDimension()); --i
>= 0;) {
                 if (i != xDimension && i != yDimension) {
@@ -477,41 +513,4 @@ public class GridCoverage2D extends GridCoverage {
             throw new CannotEvaluateException(e.getMessage(), e);
         }
     }
-
-    /**
-     * Returns a sequence of double values for a given point in the coverage.
-     * The CRS of the given point may be any coordinate reference system,
-     * or {@code null} for the same CRS than this coverage.
-     * The returned sequence contains a value for each {@linkplain SampleDimension sample
dimension}.
-     *
-     * @param  point   the coordinate point where to evaluate.
-     * @param  buffer  an array in which to store values, or {@code null} to create a new
array.
-     * @return the {@code buffer} array, or a newly created array if {@code buffer} was null.
-     * @throws PointOutsideCoverageException if the evaluation failed because the input point
-     *         has invalid coordinates.
-     * @throws CannotEvaluateException if the values can not be computed at the specified
coordinate
-     *         for an other reason.
-     */
-    @Override
-    public double[] evaluate(final DirectPosition point, double[] buffer) throws CannotEvaluateException
{
-        try {
-            final FractionalGridCoordinates gc = toGridCoordinates(point);
-            final int x = Math.toIntExact(gc.getCoordinateValue(xDimension));
-            final int y = Math.toIntExact(gc.getCoordinateValue(yDimension));
-            final int xmin = data.getMinX();
-            final int ymin = data.getMinY();
-            if (x >= xmin && x < xmin + (long) data.getWidth() &&
-                y >= ymin && y < ymin + (long) data.getHeight())
-            {
-                final int tx = Math.floorDiv(x - data.getTileGridXOffset(), data.getTileWidth());
-                final int ty = Math.floorDiv(y - data.getTileGridYOffset(), data.getTileHeight());
-                return data.getTile(tx, ty).getPixel(x, y, buffer);
-            }
-        } catch (ArithmeticException | DisjointExtentException ex) {
-            throw (PointOutsideCoverageException) new PointOutsideCoverageException(ex.getMessage(),
point).initCause(ex);
-        } catch (IllegalArgumentException | TransformException ex) {
-            throw new CannotEvaluateException(ex.getMessage(), ex);
-        }
-        throw new PointOutsideCoverageException(null, point);
-    }
 }
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
index 12688c5..0c3c748 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridExtent.java
@@ -1182,7 +1182,8 @@ public class GridExtent implements GridEnvelope, Serializable {
                         if (Double.isNaN(p)) b.append("NaN");
                         else b.append(Math.round(p));
                     }
-                    throw new PointOutsideCoverageException(Resources.format(Resources.Keys.GridCoordinateOutsideCoverage_4,
+                    throw new PointOutsideCoverageException(Resources.format(
+                            Resources.Keys.GridCoordinateOutsideCoverage_4,
                             getAxisIdentification(i,k), low, high, b.toString()));
                 }
             }
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
index cefd2cf..cd8bb81 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
@@ -16,7 +16,7 @@
  */
 package org.apache.sis.coverage.grid;
 
-import java.awt.Point;
+import java.util.Collections;
 import java.awt.Transparency;
 import java.awt.color.ColorSpace;
 import java.awt.image.BufferedImage;
@@ -25,9 +25,7 @@ import java.awt.image.ComponentColorModel;
 import java.awt.image.DataBuffer;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
-import java.util.Arrays;
-import java.util.Hashtable;
-import org.opengis.util.FactoryException;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.coverage.PointOutsideCoverageException;
 import org.opengis.referencing.operation.MathTransform1D;
 import org.opengis.referencing.datum.PixelInCell;
@@ -39,9 +37,10 @@ import org.apache.sis.measure.Units;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
 import org.apache.sis.test.TestCase;
-import org.junit.Assert;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 
 /**
  * Tests the {@link GridCoverage2D} implementation.
@@ -51,40 +50,52 @@ import org.junit.Test;
  * @since   1.1
  * @module
  */
-public class GridCoverage2DTest extends TestCase {
+public final strictfp class GridCoverage2DTest extends TestCase {
     /**
-     * Tests with a two-dimensional coverage.
+     * Creates a {@link GridCoverage2D} instance with arbitrary sample values.
+     * The image size is 2×2 pixels, the "grid to CRS" transform is identity,
+     * the range of sample values is [-97.5 … 105] metres and the packed values are:
+     *
+     * {@preformat text
+     *    2    5
+     *   -5  -10
+     * }
      */
-    @Test
-    public void testCoverage2D() throws FactoryException {
-        /*
-         * Create coverage of 2×2 pixels with an identity "grid to CRS" transform.
-         * The range of sample values will be [-10 … +10]°C.
-         */
-        final GridGeometry grid = new GridGeometry(new GridExtent(2, 2),
+    private static GridCoverage2D createTestCoverage() {
+        final int size = 2;
+        final GridGeometry grid = new GridGeometry(new GridExtent(size, size),
                 PixelInCell.CELL_CENTER, MathTransforms.identity(2), HardCodedCRS.WGS84);
 
         final MathTransform1D toUnits = (MathTransform1D) MathTransforms.linear(0.5, 100);
-        final SampleDimension sd = new SampleDimension.Builder().setName("t")
-                .addQuantitative("data", NumberRange.create(-10, true, 10, true), toUnits,
Units.CELSIUS)
+        final SampleDimension sd = new SampleDimension.Builder().setName("Some kind of height")
+                .addQuantitative("data", NumberRange.create(-10, true, 10, true), toUnits,
Units.METRE)
                 .build();
         /*
-         * Create the grid coverage, make an image and set values directly as integers.
+         * Create an image and set values directly as integers. We do not use one of the
+         * BufferedImage.TYPE_* constant because this test uses some negative values.
          */
-        WritableRaster raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT, 2,
2, 1, new Point(0,0));
-        final ColorSpace colors = ColorModelFactory.createColorSpace(1, 0, -10, 10);
-        final ColorModel cm = new ComponentColorModel(colors, false, false, Transparency.OPAQUE,
DataBuffer.TYPE_INT);
-        BufferedImage image = new BufferedImage(cm, raster, false, new Hashtable<>());
-        GridCoverage coverage = new GridCoverage2D(grid, Arrays.asList(sd), image);
-        raster.setSample(0, 0, 0,   0);
+        final WritableRaster raster = WritableRaster.createBandedRaster(DataBuffer.TYPE_INT,
size, size, 1, null);
+        raster.setSample(0, 0, 0,   2);
         raster.setSample(1, 0, 0,   5);
         raster.setSample(0, 1, 0,  -5);
         raster.setSample(1, 1, 0, -10);
+        final ColorSpace    colors = ColorModelFactory.createColorSpace(1, 0, -10, 10);
+        final ColorModel    cm     = new ComponentColorModel(colors, false, false, Transparency.OPAQUE,
DataBuffer.TYPE_INT);
+        final BufferedImage image  = new BufferedImage(cm, raster, false, null);
+        return new GridCoverage2D(grid, Collections.singleton(sd), image);
+    }
+
+    /**
+     * Tests {@link GridCoverage2D#forConvertedValues(boolean)}.
+     */
+    @Test
+    public void testForConvertedValues() {
+        GridCoverage coverage = createTestCoverage();
         /*
          * Verify packed values.
          */
         assertSamplesEqual(coverage, new double[][] {
-            { 0,   5},
+            { 2,   5},
             {-5, -10}
         });
         /*
@@ -92,16 +103,16 @@ public class GridCoverage2DTest extends TestCase {
          */
         coverage = coverage.forConvertedValues(true);
         assertSamplesEqual(coverage, new double[][] {
-            {100.0, 102.5},
+            {101.0, 102.5},
             { 97.5,  95.0}
         });
         /*
          * Test writing converted values and verify the result in the packed coverage.
-         * For example for the sample value at (0,0), we have (x is the packed value):
+         * For example for the sample value at (0,0), we have (p is the packed value):
          *
-         *   70 = x * 0.5 + 100   →   (70-100)/0.5 = x   →   x = -60
+         *   70 = p * 0.5 + 100   →   (70-100)/0.5 = p   →   p = -60
          */
-        raster = ((BufferedImage) coverage.render(null)).getRaster();
+        final WritableRaster raster = ((BufferedImage) coverage.render(null)).getRaster();
         raster.setSample(0, 0, 0,  70);
         raster.setSample(1, 0, 0,   2.5);
         raster.setSample(0, 1, 0,  -8);
@@ -110,40 +121,56 @@ public class GridCoverage2DTest extends TestCase {
             { -60, -195},
             {-216, -380}
         });
+    }
+
+    /**
+     * Tests {@link GridCoverage2D#evaluate(DirectPosition, double[])}.
+     */
+    @Test
+    public void testEvaluate() {
+        final GridCoverage coverage = createTestCoverage();
+        /*
+         * Test evaluation at indeger indices. No interpolation should be applied.
+         */
+        assertArrayEquals(new double[] {  2}, coverage.evaluate(new DirectPosition2D(0, 0),
null), STRICT);
+        assertArrayEquals(new double[] {  5}, coverage.evaluate(new DirectPosition2D(1, 0),
null), STRICT);
+        assertArrayEquals(new double[] { -5}, coverage.evaluate(new DirectPosition2D(0, 1),
null), STRICT);
+        assertArrayEquals(new double[] {-10}, coverage.evaluate(new DirectPosition2D(1, 1),
null), STRICT);
+        /*
+         * Test evaluation at fractional indices. Current interpolation is nearest neighor
rounding,
+         * but future version may do a bilinear interpolation.
+         */
+        assertArrayEquals(new double[] {2}, coverage.evaluate(new DirectPosition2D(-0.499,
-0.499), null), STRICT);
+        assertArrayEquals(new double[] {2}, coverage.evaluate(new DirectPosition2D( 0.499,
 0.499), null), STRICT);
         /*
-         * Test evaluation
+         * Test some points that are outside the coverage extent.
          */
-        Assert.assertArrayEquals(new double[]{ 70.0}, coverage.evaluate(new DirectPosition2D(0,
0), null), STRICT);
-        Assert.assertArrayEquals(new double[]{  2.5}, coverage.evaluate(new DirectPosition2D(1,
0), null), STRICT);
-        Assert.assertArrayEquals(new double[]{- 8.0}, coverage.evaluate(new DirectPosition2D(0,
1), null), STRICT);
-        Assert.assertArrayEquals(new double[]{-90.0}, coverage.evaluate(new DirectPosition2D(1,
1), null), STRICT);
-        //test nearest neighor rounding
-        Assert.assertArrayEquals(new double[]{70.0}, coverage.evaluate(new DirectPosition2D(-0.499,
-0.499), null), STRICT);
-        Assert.assertArrayEquals(new double[]{70.0}, coverage.evaluate(new DirectPosition2D(
0.499,  0.499), null), STRICT);
-        //test out of coverage
         try {
             coverage.evaluate(new DirectPosition2D(-0.51, 0), null);
-            Assert.fail("Point ouside coverage evalue must fail");
+            fail("Expected PointOutsideCoverageException.");
         } catch (PointOutsideCoverageException ex) {
-            //ok
+            assertNotNull(ex.getMessage());
         }
         try {
             coverage.evaluate(new DirectPosition2D(1.51, 0), null);
-            Assert.fail("Point ouside coverage evalue must fail");
+            fail("Expected PointOutsideCoverageException.");
         } catch (PointOutsideCoverageException ex) {
-            //ok
+            assertNotNull(ex.getMessage());
         }
     }
 
     /**
-     * assert that the sample values in the given coverage are equal to the expected values.
+     * Asserts that the sample values in the given coverage are equal to the expected values.
+     *
+     * @param  coverage  the coverage containing the sample values to check.
+     * @param  expected  the expected sample values.
      */
     private static void assertSamplesEqual(final GridCoverage coverage, final double[][]
expected) {
         final Raster raster = coverage.render(null).getData();
         for (int y=0; y<expected.length; y++) {
             for (int x=0; x<expected[y].length; x++) {
                 double value = raster.getSampleDouble(x, y, 0);
-                Assert.assertEquals(expected[y][x], value, STRICT);
+                assertEquals(expected[y][x], value, STRICT);
             }
         }
     }


Mime
View raw message