sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Convenience method for creating a Vector backed by a double[] array.
Date Tue, 05 Feb 2019 18:24:49 GMT
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

commit ab7c6e11ffb03040f5e0e5dc40894c43abdc4dd2
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Feb 5 14:06:01 2019 +0100

    Convenience method for creating a Vector backed by a double[] array.
---
 .../sis/internal/feature/GeometriesTestCase.java   |  2 +-
 .../operation/builder/LinearTransformBuilder.java  |  6 +++---
 .../src/main/java/org/apache/sis/math/Vector.java  | 25 +++++++++++++++++++++-
 .../test/java/org/apache/sis/math/PlaneTest.java   |  2 +-
 .../sis/internal/netcdf/impl/FeaturesInfo.java     |  2 +-
 5 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
index 4105b5a..eaf0608 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/internal/feature/GeometriesTestCase.java
@@ -78,7 +78,7 @@ public abstract strictfp class GeometriesTestCase extends TestCase {
                 NaN, NaN,
                  -3,  -2,
                  -2,  -5,
-                 -1,  -6}, false));
+                 -1,  -6}));
 
         final GeneralEnvelope env = factory.tryGetEnvelope(geometry);
         assertEquals("xmin", -3, env.getLower(0), STRICT);
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
index 858282e..c5e5c90 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LinearTransformBuilder.java
@@ -965,7 +965,7 @@ search:         for (int j=domain(); --j >= 0;) {
                             c = line.fit(vector(sources[0]), vector(targets[j]));
                         } else {
                             c = line.fit(Vector.createSequence(0, 1, gridSize[0]),
-                                         Vector.create(targets[j], false));
+                                         Vector.create(targets[j]));
                         }
                         break;
                     }
@@ -982,7 +982,7 @@ search:         for (int j=domain(); --j >= 0;) {
                         if (sources != null) {
                             c = plan.fit(vector(sources[0]), vector(sources[1]), vector(targets[j]));
                         } else try {
-                            c = plan.fit(gridSize[0], gridSize[1], Vector.create(targets[j],
false));
+                            c = plan.fit(gridSize[0], gridSize[1], Vector.create(targets[j]));
                         } catch (IllegalArgumentException e) {
                             // This may happen if the z vector still contain some "NaN" values.
                             throw new InvalidGeodeticParameterException(noData(), e);
@@ -1007,7 +1007,7 @@ search:         for (int j=domain(); --j >= 0;) {
      */
     private Vector vector(final double[] data) {
         assert gridSize == null;
-        return Vector.create(data, false).subList(0, numPoints);
+        return Vector.create(data).subList(0, numPoints);
     }
 
     /**
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
index d7b76b2..9a31652 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
@@ -148,6 +148,29 @@ public abstract class Vector extends AbstractList<Number> implements
RandomAcces
     }
 
     /**
+     * Wraps the given array of floating point values. This method does not clone the array:
+     * changes in the given array will be reflected in the returned vector and vice-versa.
+     * This method is equivalent to
+     * <code>{@link #create(Object, boolean) create}(array, false)</code> but
potentially faster.
+     *
+     * @param  array  the array of floating point values to wrap in a vector, or {@code null}.
+     * @return the given array wrapped in a vector, or {@code null} if the argument was {@code
null}.
+     *
+     * @since 1.0
+     */
+    public static Vector create(final double[] array) {
+        /*
+         * NOTE: we do not use variable-length argument (double...) because doing so may
force us to
+         * declare 'create' methods for all other primitive types,  otherwise some developers
may be
+         * surprised that 'create(0, 1, 2, 3)' converts the integer values to doubles. We
do not yet
+         * provide explicit 'create(...)' methods for other primitive types because it is
not needed
+         * by Apache SIS and it would lost a feature of current API, which is to force developers
to
+         * think whether their integers are signed or unsigned.
+         */
+        return (array != null) ? new ArrayVector.Doubles(array) : null;
+    }
+
+    /**
      * Wraps the given {@code float[]} array in a vector that preserve the string representations
in base 10.
      * For example the 0.1 {@code float} value casted to {@code double} normally produces
0.10000000149011612
      * because of the way IEEE 754 arithmetic represents numbers (in base 2 instead than
base 10). But the
@@ -160,7 +183,7 @@ public abstract class Vector extends AbstractList<Number> implements
RandomAcces
      * from decimal representations, for example an ASCII file. There is usually no reason
to use this method
      * if the values are the result of some numerical computations.
      *
-     * @param  array  the object to wrap in a vector, or {@code null}.
+     * @param  array  the array of floating point values to wrap in a vector, or {@code null}.
      * @return the given array wrapped in a vector, or {@code null} if the argument was {@code
null}.
      *
      * @see DecimalFunctions#floatToDouble(float)
diff --git a/core/sis-utility/src/test/java/org/apache/sis/math/PlaneTest.java b/core/sis-utility/src/test/java/org/apache/sis/math/PlaneTest.java
index d0b34c7..196f782 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/math/PlaneTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/math/PlaneTest.java
@@ -156,7 +156,7 @@ public final strictfp class PlaneTest extends TestCase {
          * generic code path.
          */
         final Plane gf = new Plane();
-        gf.fit(nx, ny, Vector.create(z, false));
+        gf.fit(nx, ny, Vector.create(z));
         assertEquals("sx", fitted.slopeX(), gf.slopeX(), STRICT);
         assertEquals("sy", fitted.slopeY(), gf.slopeY(), STRICT);
         assertEquals("z₀", fitted.z0(),     gf.z0(),     STRICT);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
index 75402e8..e419064 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
@@ -386,7 +386,7 @@ search: for (final VariableInfo counts : decoder.variables) {
             for (int i=0; i<tmp.length; i++) {
                 tmp[i] = coords[i % dimension].doubleValue(i / dimension);
             }
-            feature.setPropertyValue("trajectory", factory.createPolyline(dimension, Vector.create(tmp,
false)));
+            feature.setPropertyValue("trajectory", factory.createPolyline(dimension, Vector.create(tmp)));
             action.accept(feature);
             position = Math.addExact(position, length);
             return ++index < counts.size();


Mime
View raw message