sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Consolidation of creation of SampleDimension with NaN values.
Date Wed, 26 Dec 2018 23:06:32 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new bafe80e  Consolidation of creation of SampleDimension with NaN values.
bafe80e is described below

commit bafe80e4372254e6106df6a397d0066c3d89489b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Dec 27 00:05:46 2018 +0100

    Consolidation of creation of SampleDimension with NaN values.
---
 .../org/apache/sis/coverage/SampleDimension.java   | 46 ++++++++++++++++++----
 .../org/apache/sis/coverage/SampleRangeFormat.java |  7 ++--
 .../apache/sis/coverage/SampleDimensionTest.java   | 37 ++++++++++++++++-
 pom.xml                                            |  2 +-
 4 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
index 834585d..6294919 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
@@ -711,7 +711,6 @@ public class SampleDimension implements Serializable {
 
         /**
          * Adds a qualitative category for samples of the given floating-point value.
-         * The given value can not be {@link Float#NaN NaN}.
          *
          * <div class="note"><b>Implementation note:</b>
          * this convenience method delegates to {@link #addQualitative(CharSequence, NumberRange)}.</div>
@@ -720,7 +719,6 @@ public class SampleDimension implements Serializable {
          *                 or {@code null} for a default "no data" name.
          * @param  sample  the sample value as a real number.
          * @return {@code this}, for method call chaining.
-         * @throws IllegalArgumentException if the given value is NaN.
          */
         public Builder addQualitative(final CharSequence name, final float sample) {
             return addQualitative(name, NumberRange.create(sample, true, sample, true));
@@ -728,7 +726,6 @@ public class SampleDimension implements Serializable {
 
         /**
          * Adds a qualitative category for samples of the given double precision floating-point
value.
-         * The given value can not be {@link Double#NaN NaN}.
          *
          * <div class="note"><b>Implementation note:</b>
          * this convenience method delegates to {@link #addQualitative(CharSequence, NumberRange)}.</div>
@@ -737,7 +734,6 @@ public class SampleDimension implements Serializable {
          *                 or {@code null} for a default "no data" name.
          * @param  sample  the sample value as a real number.
          * @return {@code this}, for method call chaining.
-         * @throws IllegalArgumentException if the given value is NaN.
          */
         public Builder addQualitative(final CharSequence name, final double sample) {
             return addQualitative(name, NumberRange.create(sample, true, sample, true));
@@ -751,10 +747,10 @@ public class SampleDimension implements Serializable {
          *
          * @param  name     the category name as a {@link String} or {@link InternationalString}
object,
          *                  or {@code null} for a default "no data" name.
-         * @param  minimum  the minimum sample value, inclusive. Can not be NaN.
-         * @param  maximum  the maximum sample value, inclusive. Can not be NaN.
+         * @param  minimum  the minimum sample value, inclusive.
+         * @param  maximum  the maximum sample value, inclusive.
          * @return {@code this}, for method call chaining.
-         * @throws IllegalArgumentException if a given value is NaN or if the range is empty.
+         * @throws IllegalArgumentException if the range is empty.
          */
         public Builder addQualitative(final CharSequence name, final Number minimum, final
Number maximum) {
             return addQualitative(name, range(Numbers.widestClass(minimum, maximum), minimum,
maximum));
@@ -834,6 +830,42 @@ public class SampleDimension implements Serializable {
         }
 
         /**
+         * Adds a quantitative category for values ranging from {@code minimum} to {@code
maximum} inclusive
+         * in the given units of measurement. The transfer function is set to identity.
+         *
+         * <div class="note"><b>Implementation note:</b>
+         * this convenience method delegates to {@link #addQuantitative(CharSequence, NumberRange,
MathTransform1D, Unit)}.</div>
+         *
+         * @param  name     the category name as a {@link String} or {@link InternationalString}
object.
+         * @param  minimum  the minimum value (inclusive) in the given units.
+         * @param  maximum  the maximum value (inclusive) in the given units.
+         * @param  units    the units of measurement.
+         * @return {@code this}, for method call chaining.
+         * @throws IllegalArgumentException if a value is NaN or if {@code minimum} is greater
than {@code maximum}.
+         */
+        public Builder addQuantitative(CharSequence name, float minimum, float maximum, Unit<?>
units) {
+            return addQuantitative(name, MeasurementRange.create(minimum, true, maximum,
true, units), Category.identity(), units);
+        }
+
+        /**
+         * Adds a quantitative category for values ranging from {@code minimum} to {@code
maximum} inclusive
+         * in the given units of measurement. The transfer function is set to identity.
+         *
+         * <div class="note"><b>Implementation note:</b>
+         * this convenience method delegates to {@link #addQuantitative(CharSequence, NumberRange,
MathTransform1D, Unit)}.</div>
+         *
+         * @param  name     the category name as a {@link String} or {@link InternationalString}
object.
+         * @param  minimum  the minimum value (inclusive) in the given units.
+         * @param  maximum  the maximum value (inclusive) in the given units.
+         * @param  units    the units of measurement.
+         * @return {@code this}, for method call chaining.
+         * @throws IllegalArgumentException if a value is NaN or if {@code minimum} is greater
than {@code maximum}.
+         */
+        public Builder addQuantitative(CharSequence name, double minimum, double maximum,
Unit<?> units) {
+            return addQuantitative(name, MeasurementRange.create(minimum, true, maximum,
true, units), Category.identity(), units);
+        }
+
+        /**
          * Adds a quantitative category for sample values ranging from {@code lower} inclusive
to {@code upper} exclusive.
          * Sample values are converted into real values using the following linear equation:
          *
diff --git a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
index f7c62d6..57c46c2 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleRangeFormat.java
@@ -54,7 +54,8 @@ final class SampleRangeFormat extends RangeFormat {
 
     /**
      * {@code true} if the range of sample values is different than the range of real values,
or
-     * if there is qualitative categories. If {@code false}, then we can omit the "Samples"
column.
+     * if there is qualitative categories with non NaN values. If {@code false}, then we
can omit
+     * the "Samples" column.
      */
     private boolean hasPackedValues;
 
@@ -98,8 +99,8 @@ final class SampleRangeFormat extends RangeFormat {
             int ndigits = 0;
             for (final Category category : dimensions[i].getCategories()) {
                 final Category converted = category.converted();
-                final boolean  isPacked  = (category.minimum != converted.minimum)
-                                         | (category.maximum != converted.maximum);
+                final boolean  isPacked  = (Double.doubleToRawLongBits(category.minimum)
!= Double.doubleToRawLongBits(converted.minimum))
+                                         | (Double.doubleToRawLongBits(category.maximum)
!= Double.doubleToRawLongBits(converted.maximum));
                 hasPackedValues |= isPacked;
                 /*
                  * If the sample values are already real values, pretend that they are packed
in bytes.
diff --git a/core/sis-raster/src/test/java/org/apache/sis/coverage/SampleDimensionTest.java
b/core/sis-raster/src/test/java/org/apache/sis/coverage/SampleDimensionTest.java
index 754e92a..913c7f5 100644
--- a/core/sis-raster/src/test/java/org/apache/sis/coverage/SampleDimensionTest.java
+++ b/core/sis-raster/src/test/java/org/apache/sis/coverage/SampleDimensionTest.java
@@ -17,13 +17,15 @@
 package org.apache.sis.coverage;
 
 import java.util.Set;
-import org.apache.sis.measure.NumberRange;
+import org.opengis.referencing.operation.MathTransform1D;
+import org.apache.sis.referencing.operation.transform.LinearTransform;
 import org.apache.sis.referencing.operation.transform.TransferFunction;
+import org.apache.sis.measure.NumberRange;
 import org.apache.sis.measure.Units;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
 
 
 /**
@@ -80,4 +82,35 @@ public final strictfp class SampleDimensionTest extends TestCase {
         assertTrue   ("identity", converted.getTransferFunction().get().isIdentity());
         assertTrue   ("background", Double.isNaN(converted.getBackground().get().doubleValue()));
     }
+
+    /**
+     * Tests the creation of a sample dimension with an identity transfer function.
+     */
+    @Test
+    public void testIdentity() {
+        final SampleDimension dimension = new SampleDimension.Builder()
+                .setBackground (null, Float.NaN)           // Default to "Fill value" name,
potentially localized.
+                .addQuantitative("Temperature", -2f, 30f, Units.CELSIUS)
+                .build();
+
+        assertEquals("name", "Temperature", String.valueOf(dimension.getName()));
+        assertEquals("background", Float.NaN, dimension.getBackground().get());
+        assertEquals(0, dimension.getNoDataValues().toArray().length);
+
+        NumberRange<?> range = dimension.getSampleRange().get();
+        assertEquals("minimum", -2f, range.getMinValue());
+        assertEquals("maximum", 30f, range.getMaxValue());
+
+        range = dimension.getMeasurementRange().get();
+        assertEquals("minimum", -2d, range.getMinDouble(true), STRICT);
+        assertEquals("maximum", 30d, range.getMaxDouble(true), STRICT);
+        assertEquals("units",   Units.CELSIUS, dimension.getUnits().get());
+
+        final MathTransform1D tr = dimension.getTransferFunction().get();
+        assertInstanceOf("transferFunction", LinearTransform.class, tr);
+        assertTrue("identity", tr.isIdentity());
+
+        assertSame("forConvertedValues", dimension, dimension.forConvertedValues(true));
+        assertSame("forConvertedValues", dimension, dimension.forConvertedValues(false));
+    }
 }
diff --git a/pom.xml b/pom.xml
index 81529c9..d17afa0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -620,7 +620,7 @@
         <configuration>
           <release>${maven.compiler.target}</release>
           <encoding>${project.build.sourceEncoding}</encoding>
-          <useIncrementalCompilation>false</useIncrementalCompilation> <!--
https://jira.codehaus.org/browse/MCOMPILER-209 -->
+          <useIncrementalCompilation>false</useIncrementalCompilation> <!--
https://issues.apache.org/jira/browse/MCOMPILER-209 -->
           <compilerArgs>
             <arg>-Xlint:all</arg>
             <arg>-Xdoclint:syntax,html,missing/protected,accessibility/protected</arg>


Mime
View raw message