This is an automated email from the ASF dual-hosted git repository.

jsorel pushed a commit to branch feat/image2polygon
in repository https://gitbox.apache.org/repos/asf/sis.git

commit e9c53951a4e0a71c0aae1997afac26f5639da2fe
Author: jsorel <johann.so...@geomatys.com>
AuthorDate: Wed Mar 26 11:05:15 2025 +0100

    Change Predicate<Double> to DoublePredicate, add test for 
ImageProcessor.areas
---
 .../main/org/apache/sis/image/ImageProcessor.java  |  6 +--
 .../org/apache/sis/image/ImageProcessorTest.java   | 49 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
index cb3c52f313..89335d066d 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/ImageProcessor.java
@@ -35,8 +35,8 @@ import java.awt.image.ImagingOpException;
 import java.awt.image.IndexColorModel;
 import java.awt.image.WritableRenderedImage;
 import java.util.ArrayList;
+import java.util.function.DoublePredicate;
 import java.util.function.DoubleToIntFunction;
-import java.util.function.Predicate;
 import javax.measure.Quantity;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.MathTransform1D;
@@ -1558,10 +1558,10 @@ public class ImageProcessor implements Cloneable {
      *         List values are the polygons as a Java2D {@link Shape}.
      * @throws ImagingOpException if an error occurred during calculation.
      */
-    public List<List<Shape>> areas(final RenderedImage data, 
Predicate<Double>[] predicates, final MathTransform gridToCRS) throws 
TransformException {
+    public List<List<Shape>> areas(final RenderedImage data, DoublePredicate[] 
predicates, final MathTransform gridToCRS) throws TransformException {
         final DoubleToIntFunction[] array = new 
DoubleToIntFunction[predicates.length];
         for (int i = 0; i < predicates.length; i++) {
-            final Predicate<Double> predicate = predicates[i];
+            final DoublePredicate predicate = predicates[i];
             array[i] = (double value) -> predicate.test(value) ? 1 : 0;
         }
         final List<Map<Integer, List<Shape>>> result = areas(data, array, 
gridToCRS);
diff --git 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageProcessorTest.java
 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageProcessorTest.java
index 7803a1f37c..e27a8dd08d 100644
--- 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageProcessorTest.java
+++ 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageProcessorTest.java
@@ -20,9 +20,12 @@ import java.util.Map;
 import java.util.stream.IntStream;
 import java.awt.Shape;
 import java.awt.Rectangle;
+import java.awt.geom.PathIterator;
 import java.awt.image.Raster;
 import java.awt.image.BufferedImage;
 import java.awt.image.RenderedImage;
+import java.util.List;
+import java.util.function.DoublePredicate;
 import org.opengis.referencing.operation.MathTransform;
 
 // Test dependencies
@@ -31,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.*;
 import org.apache.sis.image.processing.isoline.IsolinesTest;
 import org.apache.sis.test.TestCase;
 import static org.apache.sis.test.TestUtilities.getSingleton;
+import org.opengis.referencing.operation.TransformException;
 
 
 /**
@@ -109,4 +113,49 @@ public final class ImageProcessorTest extends TestCase {
             IsolinesTest.verifyIsolineFromMultiCells(getSingleton(r.values()));
         } while ((parallel = !parallel) == true);
     }
+    
+    /**
+     * Tests {@link ImageProcessor#areas(RenderedImage, DoublePredicate[], 
MathTransform) }.
+     */
+    @Test
+    public void testAreas() throws TransformException {
+        final BufferedImage image = new BufferedImage(3, 3, 
BufferedImage.TYPE_BYTE_BINARY);
+        image.getRaster().setSample(1, 1, 0, 1);
+        boolean parallel = false;
+        do {
+            processor.setExecutionMode(parallel ? 
ImageProcessor.Mode.SEQUENTIAL : ImageProcessor.Mode.PARALLEL);
+            final DoublePredicate predicate = (double v) -> v == 1.0;
+            final List<Shape> list = getSingleton(processor.areas(image, new 
DoublePredicate[]{predicate}, null));
+            assertEquals(1, list.size());
+            final Shape shape = list.get(0);
+            
+            /*
+                     1      4
+               (1,2) +------+ (2,2)
+                     |      |
+                     |      |
+               (1,1) +------+ (2,1)
+                     2      3            
+            */
+            
+            final PathIterator pathIterator = shape.getPathIterator(null);
+            final double[] coords = new double[2];
+            assertEquals(PathIterator.SEG_MOVETO, 
pathIterator.currentSegment(coords));
+            assertArrayEquals(new double[]{1,2}, coords);
+            pathIterator.next();
+            assertEquals(PathIterator.SEG_LINETO, 
pathIterator.currentSegment(coords));
+            assertArrayEquals(new double[]{1,1}, coords);
+            pathIterator.next();
+            assertEquals(PathIterator.SEG_LINETO, 
pathIterator.currentSegment(coords));
+            assertArrayEquals(new double[]{2,1}, coords);
+            pathIterator.next();
+            assertEquals(PathIterator.SEG_LINETO, 
pathIterator.currentSegment(coords));
+            assertArrayEquals(new double[]{2,2}, coords);
+            pathIterator.next();
+            assertEquals(PathIterator.SEG_CLOSE, 
pathIterator.currentSegment(coords));
+            pathIterator.next();
+            assertTrue(pathIterator.isDone());
+            
+        } while ((parallel = !parallel) == true);
+    }
 }

Reply via email to