This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 29a8efdd863b56f33ec9e54a0035627dfd9771b9 Author: Martin Desruisseaux <[email protected]> AuthorDate: Sat Nov 7 13:02:34 2026 +0100 Add test for parallel execution of `GridGeometry.latticePointStream(…)`. --- .../sis/coverage/grid/GridPointIterator.java | 19 +++++++++++++++++-- .../apache/sis/coverage/grid/GridGeometryTest.java | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridPointIterator.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridPointIterator.java index 66799900af..146872f91c 100644 --- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridPointIterator.java +++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridPointIterator.java @@ -70,9 +70,18 @@ abstract class GridPointIterator<T> extends LatticeIterator<T> { super(extent); this.gridToCRS = gridToCRS; crsDimension = gridToCRS.getTargetDimensions(); + buffer = createBuffer(); + } + + /** + * Creates the {@link #buffer} array with a size sufficient for containing both source and target coordinates. + * Array size is {@value org.apache.sis.referencing.internal.shared.CoordinateOperations#MAXIMUM_BUFFER_SIZE} + * or less. + */ + private double[] createBuffer() { final int dimension = Math.max(crsDimension, gridToCRS.getSourceDimensions()); final int capacity = (int) Math.min(estimateSize(), Math.max(MAXIMUM_BUFFER_SIZE / dimension, 1)); - buffer = new double[capacity * dimension]; + return new double[Math.max(capacity * dimension, limit)]; } /** @@ -82,7 +91,13 @@ abstract class GridPointIterator<T> extends LatticeIterator<T> { * @param prefix extent of the prefix of the given iterator. */ GridPointIterator(final GridPointIterator<T> suffix, final long[] prefix) { - this(prefix, suffix.gridToCRS); + super(prefix); + gridToCRS = suffix.gridToCRS; + crsDimension = suffix.crsDimension; + limit = suffix.limit - suffix.currentPosition; + buffer = createBuffer(); + System.arraycopy(suffix.buffer, suffix.currentPosition, buffer, 0, limit); + suffix.limit = 0; } /** diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java index 28a8a2038b..53a37abe7d 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/coverage/grid/GridGeometryTest.java @@ -18,6 +18,7 @@ package org.apache.sis.coverage.grid; import java.util.Set; import java.util.List; +import java.util.stream.IntStream; import org.opengis.util.FactoryException; import org.opengis.geometry.Envelope; import org.opengis.metadata.Identifier; @@ -1087,6 +1088,27 @@ public final class GridGeometryTest extends TestCase { }, grid.instantStream(PixelInCell.CELL_CENTER).map(Object::toString).toArray()); } + /** + * Tests parallel execution of {@link GridGeometry#latticePointStream(PixelInCell, CoordinateReferenceSystem)}. + * + * @throws FactoryException if an error occurred while creating the transform. + */ + @Test + public void testParallelLatticePointStream() throws FactoryException { + final var grid = new GridGeometry( + new GridExtent(null, null, new long[] {3, 5, 3000}, true), + PixelInCell.CELL_CENTER, + MathTransforms.linear(new Matrix4( + 0.25, 0, 0, 2, + 0, 0.5, 0, 3, + 0, 0, 2, 7, + 0, 0, 0, 1)), + HardCodedCRS.WGS84_WITH_TIME); + + assertArrayEquals(IntStream.range(0, 3001).mapToDouble((i) -> 7 + 2*i).toArray(), + grid.latticePointStream1D(PixelInCell.CELL_CENTER, HardCodedCRS.TIME).parallel().toArray()); + } + /** * Tests {@link GridGeometry#contains(GridGeometry)} and {@link GridGeometry#intersects(GridGeometry)}. */
