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

jsorel 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 ecffefe1cc feat(GridExtent): add GridExtent.interiorCoordinateStream 
method
ecffefe1cc is described below

commit ecffefe1cc8aceab717c5040f88b3ec58ba2bff2
Author: jsorel <[email protected]>
AuthorDate: Wed Apr 15 14:36:37 2026 +0200

    feat(GridExtent): add GridExtent.interiorCoordinateStream method
---
 .../org/apache/sis/coverage/grid/GridExtent.java   | 34 ++++++++++++++++++++++
 .../apache/sis/coverage/grid/GridExtentTest.java   | 25 ++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
index 1fa56bce8e..45b296cdae 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
@@ -27,6 +27,8 @@ import java.io.Serializable;
 import java.io.IOException;
 import java.io.UncheckedIOException;
 import java.awt.Rectangle;
+import java.util.stream.LongStream;
+import java.util.stream.Stream;
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
 import org.opengis.geometry.Envelope;
@@ -2140,6 +2142,38 @@ public class GridExtent implements GridEnvelope, 
LenientComparable, Serializable
         return true;
     }
 
+    /**
+     * Create a stream of coordinates contained in the GridExtent.
+     * Iteration goes from {@linkplain GridExtent#getLow() } to {@linkplain 
GridExtent#getHigh() } coordinates inclusive.
+     * <p>
+     * No assumption of the iteration order should be made.
+     *
+     * @return stream of coordinates inside the GridExtent.
+     * @since 1.7
+     */
+    public Stream<long[]> interiorCoordinateStream() {
+        final int dimension = getDimension();
+        final long[] low = getLow().getCoordinateValues();
+        final long[] high = getHigh().getCoordinateValues();
+
+        Stream<long[]> stream = LongStream.range(low[0], high[0]+1)
+                .mapToObj((long value) -> {
+                    final long[] array = new long[dimension];
+                    array[0] = value;
+                    return array;
+        });
+        for (int i = 1; i <dimension; i++) {
+            final int idx = i;
+            stream = stream.flatMap((long[] t) -> LongStream.range(low[idx], 
high[idx]+1)
+                    .mapToObj((long value) -> {
+                        final long[] array = t.clone();
+                        array[idx] = value;
+                        return array;
+                    }));
+        }
+        return stream;
+    }
+
     /**
      * Compares the specified object with this grid extent for equality.
      * This method delegates to {@code equals(object, ComparisonMode.STRICT)}.
diff --git 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
index d80f1bab6a..a0656270dd 100644
--- 
a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
+++ 
b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -19,6 +19,8 @@ package org.apache.sis.coverage.grid;
 import java.util.Map;
 import java.util.Locale;
 import java.io.IOException;
+import java.util.List;
+import java.util.function.Function;
 import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.metadata.spatial.DimensionNameType;
@@ -417,6 +419,29 @@ public final class GridExtentTest extends TestCase {
         assertMessageContains(exception);
     }
 
+    /**
+     * Tests {@link GridExtent#interiorStream() }.
+     */
+    @Test
+    public void testInteriorCoordinateStream() {
+        final record Pt(long x, long y, long z){};
+        var extent = new GridExtent(null, new long[]{1,20,33}, new 
long[]{3,23,35}, false);
+        var lst = extent.interiorCoordinateStream().map((long[] t) -> new 
Pt(t[0], t[1], t[2])).toList();
+        assertEquals(2*3*2, lst.size());
+        assertTrue(lst.contains(new Pt(1,20,33)));
+        assertTrue(lst.contains(new Pt(1,20,34)));
+        assertTrue(lst.contains(new Pt(1,21,33)));
+        assertTrue(lst.contains(new Pt(1,21,34)));
+        assertTrue(lst.contains(new Pt(1,22,33)));
+        assertTrue(lst.contains(new Pt(1,22,34)));
+        assertTrue(lst.contains(new Pt(2,20,33)));
+        assertTrue(lst.contains(new Pt(2,20,34)));
+        assertTrue(lst.contains(new Pt(2,21,33)));
+        assertTrue(lst.contains(new Pt(2,21,34)));
+        assertTrue(lst.contains(new Pt(2,22,33)));
+        assertTrue(lst.contains(new Pt(2,22,34)));
+    }
+
     /**
      * Verifies the result of {@code getSubspaceDimensions(…)} and {@code 
getLargestDimensions(…)}.
      * In this test, the two methods should produce the same results.

Reply via email to