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 55c2c40 Add `GridExtent.contains(long...)` method.
55c2c40 is described below
commit 55c2c4082059d7d4e3356231f9a1dd468084a170
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Tue Mar 29 16:15:38 2022 +0200
Add `GridExtent.contains(long...)` method.
---
.../org/apache/sis/coverage/grid/GridExtent.java | 28 ++++++++++++++++++++++
.../apache/sis/coverage/grid/GridExtentTest.java | 10 ++++++++
2 files changed, 38 insertions(+)
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 a754ff6..1d1e988 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
@@ -1482,6 +1482,34 @@ public class GridExtent implements GridEnvelope,
LenientComparable, Serializable
}
/**
+ * Returns {@code true} if this extent contains the given cell indices.
+ * An index is considered inside the grid extent if its value is between
+ * {@link #getLow(int) low} and {@link #getHigh(int) high} bounds,
inclusive.
+ *
+ * <h4>Number of arguments</h4>
+ * The {@code indices} array length should be equal to the {@linkplain
#getDimension() number of dimensions}.
+ * If the array is shorter, missing index values are considered inside the
extent.
+ * If the array is longer, extraneous values are ignored.
+ *
+ * @param indices indices of the grid cell to check.
+ * @return whether the given indices are inside this extent.
+ *
+ * @since 1.2
+ */
+ public boolean contains(final long... indices) {
+ ArgumentChecks.ensureNonNull("indices", indices);
+ final int m = getDimension();
+ final int length = Math.min(m, indices.length);
+ for (int i=0; i<length; i++) {
+ final long c = indices[i];
+ if (c < coordinates[i] || c > coordinates[i + m]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Returns the intersection of this grid extent with to the given grid
extent.
* The given extent shall have the same number of dimensions.
*
diff --git
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
index 4de05b0..b5fd1c0 100644
---
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
+++
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridExtentTest.java
@@ -203,6 +203,16 @@ public final strictfp class GridExtentTest extends
TestCase {
}
/**
+ * Tests {@link GridExtent#contains(long...)}.
+ */
+ @Test
+ public void testContains() {
+ final GridExtent extent = create3D();
+ assertTrue (extent.contains(100, 200, 40));
+ assertFalse(extent.contains(100, 200, 39));
+ }
+
+ /**
* Tests {@link GridExtent#intersect(GridExtent)}.
*/
@Test