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 d773f3f985 Improve TupleArray bound computation and ignores NaN values
d773f3f985 is described below
commit d773f3f98503cccf4627d57838cf0c58d23b0ebf
Author: jsorel <[email protected]>
AuthorDate: Wed Sep 17 11:27:29 2025 +0200
Improve TupleArray bound computation and ignores NaN values
---
.../apache/sis/geometries/math/TupleArrays.java | 39 +++++++++++++++-------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/TupleArrays.java
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/TupleArrays.java
index 2860da8934..1e9f7aa06c 100644
---
a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/TupleArrays.java
+++
b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/math/TupleArrays.java
@@ -18,6 +18,7 @@ package org.apache.sis.geometries.math;
import java.util.AbstractList;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
@@ -27,7 +28,6 @@ import org.opengis.util.FactoryException;
import org.apache.sis.coverage.SampleDimension;
import org.apache.sis.geometries.BBox;
import org.apache.sis.geometries.Geometries;
-import org.apache.sis.geometry.GeneralDirectPosition;
import org.apache.sis.measure.NumberRange;
import org.apache.sis.referencing.CRS;
import org.apache.sis.util.ArgumentChecks;
@@ -197,21 +197,36 @@ public final class TupleArrays extends Static {
* @return vectors with the same crs as the array, lower and upper bounds.
*/
public static BBox computeRange(TupleArray array) {
- final CoordinateReferenceSystem crs =
array.getCoordinateReferenceSystem();
- final BBox bbox = crs == null ? new BBox(array.getDimension()) : new
BBox(crs);
- bbox.setToNaN();
- boolean first = true;
+
+ final int dim = array.getDimension();
+ final double[] min = new double[dim];
+ final double[] max = new double[dim];
+ final double[] buffer = new double[dim];
+ Arrays.fill(min, Double.NaN);
+ Arrays.fill(max, Double.NaN);
+
final TupleArrayCursor cursor = array.cursor();
+ if (cursor.next()) {
+ cursor.samples().toArrayDouble(buffer, 0);
+ System.arraycopy(buffer, 0, min, 0, dim);
+ System.arraycopy(buffer, 0, max, 0, dim);
+ }
+
+ int i;
while (cursor.next()) {
- final Tuple samples = cursor.samples();
- if (first) {
- bbox.getLower().set(samples);
- bbox.getUpper().set(samples);
- first = false;
- } else {
- bbox.add(samples);
+ cursor.samples().toArrayDouble(buffer, 0);
+ for (i = 0; i < dim; i++) {
+ if (Double.isNaN(buffer[i])) continue;
+ if (Double.isNaN(min[i]) || (buffer[i] < min[i])) min[i] =
buffer[i];
+ if (Double.isNaN(max[i]) || (buffer[i] > max[i])) max[i] =
buffer[i];
}
}
+
+ final CoordinateReferenceSystem crs =
array.getCoordinateReferenceSystem();
+ final BBox bbox = crs == null ? new BBox(array.getDimension()) : new
BBox(crs);
+ for (i = 0; i < dim; i++) {
+ bbox.setRange(i, min[i], max[i]);
+ }
return bbox;
}