sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Do not round the median value in `WraparoundTransform`. Callers should round themselves if desired.
Date Thu, 01 Oct 2020 21:55:37 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 911d02c3d70afde9e582396591d0213f25203bc5
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Oct 1 11:31:30 2020 +0200

    Do not round the median value in `WraparoundTransform`. Callers should round themselves
if desired.
---
 .../sis/coverage/grid/CoordinateOperationFinder.java   | 18 +++++++++++++++---
 .../sis/internal/referencing/WraparoundTransform.java  | 16 +++++-----------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/CoordinateOperationFinder.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/CoordinateOperationFinder.java
index 3c24f7b..63af77d 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/CoordinateOperationFinder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/CoordinateOperationFinder.java
@@ -578,10 +578,12 @@ apply:          if (forwardChangeOfCRS == null) {
             /** The coordinates, computed when first needed. */
             private double[] coordinates;
 
-            @Override public int    getDimension()     {return coordinates().length;}
-            @Override public double getOrdinate(int i) {return coordinates()[i];}
+            /** Returns the number of dimensions. */
+            @Override public int getDimension() {
+                return coordinates().length;
+            }
 
-            /** Returns the coordinate tuple. */
+            /** Returns the coordinate tuple, computed when first needed. */
             @SuppressWarnings("ReturnOfCollectionOrArrayField")
             private double[] coordinates() {
                 if (coordinates == null) try {
@@ -597,6 +599,16 @@ apply:          if (forwardChangeOfCRS == null) {
                 }
                 return coordinates;
             }
+
+            /**
+             * Returns the median rounded to a value having an exact representation in base
2 using about 10 bits.
+             * The intent is to reduce the risk of rounding errors with add/subtract operations.
+             */
+            @Override public double getOrdinate(final int i) {
+                final double m = coordinates()[i];
+                final int power = 10 - Math.getExponent(m);
+                return Math.scalb(Math.rint(Math.scalb(m, power)), -power);
+            }
         };
     }
 
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
index 6a2a7be..647e6e2 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WraparoundTransform.java
@@ -262,23 +262,17 @@ public class WraparoundTransform extends AbstractMathTransform implements
Serial
             // Some implementations compute coordinates only when first needed.
             throw e.unwrapOrRethrow(TransformException.class);
         }
-        if (Double.isFinite(m)) {
-            /*
-             * Round the median to a value having an exact representation in base 2 using
about 10 bits.
-             * The intent is to reduce the risk of rounding errors with add/subtract operations.
-             */
-            final int power = 10 - Math.getExponent(m);
-            m = Math.scalb(Math.rint(Math.scalb(m, power)), -power);
-        } else if (targetMedian == null) {
+        if (!Double.isFinite(m)) {
+            if (targetMedian != null) {
+                // Invalid median value. Assume caller means "no wrap".
+                return tr;
+            }
             /*
              * May happen if `WraparoundAdjustment.range(…)` recognized a longitude axis
              * despite the `CoordinateSystemAxis` not declarining minimum/maximum values.
              * Use 0 as the range center (e.g. center of [-180 … 180]° longitude range).
              */
             m = 0;
-        } else {
-            // Invalid median value. Assume caller means "no wrap".
-            return tr;
         }
         final int dimension = tr.getTargetDimensions();
         MathTransform wraparound;


Mime
View raw message