sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1803718 - in /sis/branches/JDK8/core/sis-raster/src: main/java/org/apache/sis/image/DefaultIterator.java main/java/org/apache/sis/image/PixelIterator.java test/java/org/apache/sis/image/PixelIteratorTest.java
Date Tue, 01 Aug 2017 23:35:55 GMT
Author: desruisseaux
Date: Tue Aug  1 23:35:54 2017
New Revision: 1803718

URL: http://svn.apache.org/viewvc?rev=1803718&view=rev
Log:
Enable more tests.

Modified:
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/DefaultIterator.java
    sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
    sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/image/PixelIteratorTest.java

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/DefaultIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/DefaultIterator.java?rev=1803718&r1=1803717&r2=1803718&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/DefaultIterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/DefaultIterator.java
[UTF-8] Tue Aug  1 23:35:54 2017
@@ -189,19 +189,21 @@ final class DefaultIterator extends Pixe
     @Override
     public boolean next() {
         if (++x >= currentUpperX) {
-            if (++y >= currentUpperY) {
-                if (++tileX >= tileUpperX) {
-                    tileY = Math.incrementExact(tileY);
+            if (++y >= currentUpperY) {                     // Strict equality (==) would
work, but use >= as a safety.
+                if (++tileX >= tileUpperX) {                // Strict equality (==) would
work, but use >= as a safety.
+                    tileY = Math.incrementExact(tileY);     // 'incrementExact' because 'tileY
> tileUpperY' is allowed.
                     if (tileY >= tileUpperY) {
                         /*
                          * Paranoiac safety: keep the x, y and tileX values before their
maximal values
                          * in order to avoid overflow. The 'tileY' value is used for checking
if next()
-                         * is invoked again, in order to avoid a common misuse pattern.
+                         * is invoked again, in order to avoid a common misuse pattern. In
principle
+                         * 'tileY' needs to be compared only to 'tileUpperY', but we also
compare to
+                         * 'tileLowerY + 1' for handling the empty iterator case.
                          */
                         x =  currentUpperX - 1;
                         y =  currentUpperY - 1;
                         tileX = tileUpperX - 1;
-                        if (tileY > tileUpperY) {
+                        if (tileY > Math.max(tileUpperY, tileLowerY + 1)) {
                             throw new IllegalStateException(Resources.format(Resources.Keys.IterationIsFinished));
                         }
                         return false;

Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java?rev=1803718&r1=1803717&r2=1803718&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/image/PixelIterator.java
[UTF-8] Tue Aug  1 23:35:54 2017
@@ -106,6 +106,7 @@ public abstract class PixelIterator {
      */
     PixelIterator(final Raster data, final Rectangle subArea) {
         ArgumentChecks.ensureNonNull("data", data);
+        final Rectangle bounds;
         image           = null;
         currentRaster   = data;
         numBands        = data.getNumBands();
@@ -117,16 +118,11 @@ public abstract class PixelIterator {
         tileLowerY      = 0;
         tileUpperX      = 1;
         tileUpperY      = 1;
-        Rectangle bounds = new Rectangle(tileGridXOffset, tileGridYOffset, tileWidth, tileHeight);
-        if (subArea != null) {
-            bounds = bounds.intersection(subArea);
-            if (bounds.width  < 0) bounds.width  = 0;
-            if (bounds.height < 0) bounds.height = 0;
-        }
-        lowerX = bounds.x;
-        lowerY = bounds.y;
-        upperX = Math.addExact(lowerX, bounds.width);
-        upperY = Math.addExact(lowerY, bounds.height);
+        bounds          = intersection(tileGridXOffset, tileGridYOffset, tileWidth, tileHeight,
subArea);
+        lowerX          = bounds.x;
+        lowerY          = bounds.y;
+        upperX          = Math.addExact(lowerX, bounds.width);
+        upperY          = Math.addExact(lowerY, bounds.height);
     }
 
     /**
@@ -138,24 +134,22 @@ public abstract class PixelIterator {
      */
     PixelIterator(final RenderedImage data, final Rectangle subArea) {
         ArgumentChecks.ensureNonNull("data", data);
-        image            = data;
-        numBands         = data.getSampleModel().getNumBands();
-        tileWidth        = data.getTileWidth();
-        tileHeight       = data.getTileHeight();
-        tileGridXOffset  = data.getTileGridXOffset();
-        tileGridYOffset  = data.getTileGridYOffset();
-        Rectangle bounds = new Rectangle(data.getMinX(), data.getMinY(), data.getWidth(),
data.getHeight());
-        if (subArea != null) {
-            bounds = bounds.intersection(subArea);
-        }
-        lowerX     = bounds.x;
-        lowerY     = bounds.y;
-        upperX     = Math.addExact(lowerX, bounds.width);
-        upperY     = Math.addExact(lowerY, bounds.height);
-        tileLowerX = floorDiv(Math.subtractExact(lowerX, tileGridXOffset), tileWidth);
-        tileLowerY = floorDiv(Math.subtractExact(lowerY, tileGridYOffset), tileHeight);
-        tileUpperX =  ceilDiv(Math.subtractExact(upperX, tileGridXOffset), tileWidth);
-        tileUpperY =  ceilDiv(Math.subtractExact(upperY, tileGridYOffset), tileHeight);
+        final Rectangle bounds;
+        image           = data;
+        numBands        = data.getSampleModel().getNumBands();
+        tileWidth       = data.getTileWidth();
+        tileHeight      = data.getTileHeight();
+        tileGridXOffset = data.getTileGridXOffset();
+        tileGridYOffset = data.getTileGridYOffset();
+        bounds          = intersection(data.getMinX(), data.getMinY(), data.getWidth(), data.getHeight(),
subArea);
+        lowerX          = bounds.x;
+        lowerY          = bounds.y;
+        upperX          = Math.addExact(lowerX, bounds.width);
+        upperY          = Math.addExact(lowerY, bounds.height);
+        tileLowerX      = floorDiv(Math.subtractExact(lowerX, tileGridXOffset), tileWidth);
+        tileLowerY      = floorDiv(Math.subtractExact(lowerY, tileGridYOffset), tileHeight);
+        tileUpperX      =  ceilDiv(Math.subtractExact(upperX, tileGridXOffset), tileWidth);
+        tileUpperY      =  ceilDiv(Math.subtractExact(upperY, tileGridYOffset), tileHeight);
     }
 
     /**
@@ -166,6 +160,20 @@ public abstract class PixelIterator {
     }
 
     /**
+     * Computes the intersection between the given bounds and 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) {
+        Rectangle bounds = new Rectangle(x, y, width, height);
+        if (subArea != null) {
+            bounds = bounds.intersection(subArea);
+            if (bounds.width  < 0) bounds.width  = 0;
+            if (bounds.height < 0) bounds.height = 0;
+        }
+        return bounds;
+    }
+
+    /**
      * Returns the pixel coordinates of the region where this iterator is doing the iteration.
      * If no region was specified at construction time, then this method returns the image
or
      * raster bounds.

Modified: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/image/PixelIteratorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/image/PixelIteratorTest.java?rev=1803718&r1=1803717&r2=1803718&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/image/PixelIteratorTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/image/PixelIteratorTest.java
[UTF-8] Tue Aug  1 23:35:54 2017
@@ -161,6 +161,7 @@ public strictfp class PixelIteratorTest
                     value++;
                 }
             }
+            value += 10;                // Arbitrary offset.
         }
         assertEquals("Number of expected values", expected.length, n);
         return raster;
@@ -178,6 +179,8 @@ public strictfp class PixelIteratorTest
      * @return an image filled with arbitrary sample values.
      */
     private WritableRenderedImage createImage(final Rectangle subArea) {
+        assertEquals(0, width  % tileWidth);
+        assertEquals(0, height % tileHeight);
         final int numXTiles = (width  + tileWidth -1) / tileWidth;
         final int numYTiles = (height + tileHeight-1) / tileHeight;
         final int xmax = xmin + width;                                  // Maximum value
is exclusive.
@@ -194,7 +197,7 @@ public strictfp class PixelIteratorTest
             subMaxX = StrictMath.min(xmax, subArea.x + subArea.width);
             subMaxY = StrictMath.min(ymax, subArea.y + subArea.height);
         }
-        expected = new float[(subMaxX - subMinX) * (subMaxY - subMinY) * numBands];
+        expected = new float[StrictMath.max(subMaxX - subMinX, 0) * StrictMath.max(subMaxY
- subMinY, 0) * numBands];
         final TiledImage image = new TiledImage(dataType, numBands, xmin, ymin, width, height,
tileWidth, tileHeight, 0, 0);
         /*
          * At this point, all data structures have been created an initialized to zero sample
values.
@@ -218,8 +221,11 @@ public strictfp class PixelIteratorTest
                             value++;
                         }
                     }
+                    value += 4;         // Arbitrary offset.
                 }
+                value += 7;             // Arbitrary offset.
             }
+            value += 10;                // Arbitrary offset.
         }
         assertEquals("Number of expected values", expected.length, n);
         return image;
@@ -675,17 +681,16 @@ public strictfp class PixelIteratorTest
      * The sub-area is large enough for covering more than one tile.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnTileUpperLeft")
     public void testOnImageUpperLeft() {
         xmin       = -5;
         ymin       =  5;
-        width      = 90;
-        height     = 50;
-        tileWidth  = 10;
+        width      = 27;
+        height     = 20;
+        tileWidth  =  9;
         tileHeight =  5;
         numBands   =  3;
-        final Rectangle subArea = new Rectangle(-10, -20, 40, 30);
+        final Rectangle subArea = new Rectangle(-10, -5, 25, 22);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         assertNull("getIterationOrder()", iterator.getIterationOrder());
@@ -698,17 +703,16 @@ public strictfp class PixelIteratorTest
      * The sub-area is large enough for covering more than one tile.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnTileUpperRight")
     public void testOnImageUpperRight() {
         xmin       = 20;
         ymin       =  0;
-        width      = 80;
-        height     = 50;
-        tileWidth  = 10;
-        tileHeight =  5;
-        numBands   =  3;
-        final Rectangle subArea = new Rectangle(80, -20, 30, 50);
+        width      = 25;
+        height     = 24;
+        tileWidth  =  5;
+        tileHeight =  6;
+        numBands   =  2;
+        final Rectangle subArea = new Rectangle(27, -20, 30, 37);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         assertNull("getIterationOrder()", iterator.getIterationOrder());
@@ -721,17 +725,16 @@ public strictfp class PixelIteratorTest
      * The sub-area is large enough for covering more than one tile.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnTileLowerRight")
     public void testOnImageLowerRight() {
         xmin       = 30;
-        ymin       =  0;
-        width      = 70;
-        height     = 50;
-        tileWidth  = 10;
-        tileHeight =  5;
-        numBands   =  3;
-        final Rectangle subArea = new Rectangle(80, 30, 50, 50);
+        ymin       =  1;
+        width      = 15;
+        height     = 12;
+        tileWidth  =  3;
+        tileHeight =  4;
+        numBands   =  4;
+        final Rectangle subArea = new Rectangle(36, 8, 12, 20);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         assertNull("getIterationOrder()", iterator.getIterationOrder());
@@ -744,17 +747,16 @@ public strictfp class PixelIteratorTest
      * The sub-area is large enough for covering more than one tile.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnTileLowerLeft")
     public void testOnImageLowerLeft() {
-        xmin       =  0;
-        ymin       =  0;
-        width      = 70;
-        height     = 50;
-        tileWidth  = 10;
-        tileHeight =  5;
-        numBands   =  3;
-        final Rectangle subArea = new Rectangle(-20, 30, 50, 50);
+        xmin       = -2;
+        ymin       = -7;
+        width      = 15;
+        height     = 16;
+        tileWidth  =  5;
+        tileHeight =  4;
+        numBands   =  1;
+        final Rectangle subArea = new Rectangle(-20, -1, 30, 20);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         assertNull("getIterationOrder()", iterator.getIterationOrder());
@@ -766,17 +768,16 @@ public strictfp class PixelIteratorTest
      * The sub-area is large enough for covering more than one tile.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnTileSubArea")
     public void testOnImageSubArea() {
         xmin       =  -5;
         ymin       =   7;
-        width      = 100;
-        height     =  50;
-        tileWidth  =  10;
-        tileHeight =   5;
-        numBands   =   3;
-        final Rectangle subArea = new Rectangle(20, 10, 10, 10);
+        width      =  70;
+        height     =  48;
+        tileWidth  =   7;
+        tileHeight =   4;
+        numBands   =   2;
+        final Rectangle subArea = new Rectangle(20, 10, 30, 25);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         assertNull("getIterationOrder()", iterator.getIterationOrder());
@@ -784,20 +785,18 @@ public strictfp class PixelIteratorTest
     }
 
     /**
-     * Tests iteration over a sub-area in a tiled image.
-     * The sub-area is large enough for covering more than one tile.
+     * Tests iteration over a all the region of a tiled image.
      */
     @Test
-    @Ignore
     @DependsOnMethod({"testOnImage", "testOnRasterFullArea"})
     public void testOnImageFullArea() {
-        xmin       =   0;
-        ymin       =   0;
-        width      = 100;
+        xmin       =  -5;
+        ymin       =  -3;
+        width      =  60;
         height     =  50;
-        tileWidth  =  10;
+        tileWidth  =   6;
         tileHeight =   5;
-        numBands   =   3;
+        numBands   =   1;
         final Rectangle subArea = new Rectangle(-10, -10, 150, 80);
         createPixelIterator(createImage(subArea), subArea);
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
@@ -809,16 +808,15 @@ public strictfp class PixelIteratorTest
      * Tests iteration over a sub-area that do not intersect the image area.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnRasterEmptyArea")
     public void testOnImageEmptyArea() {
-        xmin       = 0;
-        ymin       = 0;
-        width      = 20;
-        height     = 10;
-        tileWidth  = 15;
-        tileHeight =  5;
-        numBands   =  3;
+        xmin       = 5;
+        ymin       = 6;
+        width      = 8;
+        height     = 9;
+        tileWidth  = 2;
+        tileHeight = 3;
+        numBands   = 2;
         final Rectangle subArea = new Rectangle(-100, -50, 5, 17);
         createPixelIterator(createImage(subArea), subArea);
         assertEquals("Expected an empty set of values.", 0, expected.length);
@@ -830,23 +828,22 @@ public strictfp class PixelIteratorTest
      * an exception to be thrown.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testIllegalMoveOnRaster")
     public void testIllegalMoveOnImage() {
         xmin       =  0;
         ymin       =  0;
-        width      = 20;
-        height     = 10;
-        tileWidth  = 15;
-        tileHeight =  5;
-        numBands   =  3;
+        width      =  8;
+        height     =  6;
+        tileWidth  =  4;
+        tileHeight =  3;
+        numBands   =  1;
         createPixelIterator(createImage(null));
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         try {
             iterator.moveTo(102, 53);
-            fail("Expected IllegalArgumentException.");
-        } catch (IllegalArgumentException e) {
-            // ok
+            fail("Expected IndexOutOfBoundsException.");
+        } catch (IndexOutOfBoundsException e) {
+            assertNotNull(e.getMessage());
         }
     }
 
@@ -854,25 +851,23 @@ public strictfp class PixelIteratorTest
      * Verifies that invoking {@link PixelIterator#next()} after iteration end causes an
exception to be thrown.
      */
     @Test
-    @Ignore
     @DependsOnMethod("testOnImage")
     public void testIllegalNext() {
-        xmin       =  0;
-        ymin       =  0;
-        width      = 20;
-        height     = 15;
-        tileWidth  = 10;
-        tileHeight =  5;
-        numBands   =  3;
-        final Rectangle subArea = new Rectangle(-10, -10, 150, 80);
-        createPixelIterator(createImage(subArea), subArea);
+        xmin       = -1;
+        ymin       =  3;
+        width      =  8;
+        height     =  6;
+        tileWidth  =  4;
+        tileHeight =  3;
+        numBands   =  1;
+        createPixelIterator(createImage(null));
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         verifyIteration(false);
         try {
             iterator.next();
             fail("Expected IllegalStateException.");
         } catch (IllegalStateException e) {
-            // ok
+            assertNotNull(e.getMessage());
         }
     }
 
@@ -880,15 +875,14 @@ public strictfp class PixelIteratorTest
      * Tests {@link PixelIterator#getPosition()}.
      */
     @Test
-    @Ignore
     public void testGetPosition() {
         xmin       =  56;
         ymin       =   1;
-        width      =  40;
-        height     =  32;
-        tileWidth  =  10;
+        width      =  20;
+        height     =  24;
+        tileWidth  =   5;
         tileHeight =   8;
-        numBands   =   3;
+        numBands   =   2;
         createPixelIterator(createImage(null));
         assertTrue("Expected a non-empty set of values.", expected.length != 0);
         int i = 0;
@@ -901,7 +895,7 @@ public strictfp class PixelIteratorTest
                         assertEquals("x", tx*tileWidth  + x + xmin, position.x);
                         assertEquals("y", ty*tileHeight + y + ymin, position.y);
                         for (int b=0; b<numBands; b++) {
-                            assertEquals(expected[i], iterator.getSampleFloat(b), 0f);
+                            assertEquals(expected[i++], iterator.getSampleFloat(b), 0f);
                         }
                     }
                 }



Mime
View raw message