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: Avoid a NaN in AzimuthalEquidistant when (x, y) coordinates are very close to (0, 0). Fix an error in ResampledImage.getPositionalConsistency() that prevented us from visualizing the ResamplingGrid errors.
Date Tue, 30 Jun 2020 10:02:42 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 a6ae6a9  Avoid a NaN in AzimuthalEquidistant when (x,y) coordinates are very close
to (0,0). Fix an error in ResampledImage.getPositionalConsistency() that prevented us from
visualizing the ResamplingGrid errors.
a6ae6a9 is described below

commit a6ae6a9a4e2763862960349c38baf86cd76ec3d0
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 30 12:00:42 2020 +0200

    Avoid a NaN in AzimuthalEquidistant when (x,y) coordinates are very close to (0,0).
    Fix an error in ResampledImage.getPositionalConsistency() that prevented us from visualizing
the ResamplingGrid errors.
---
 .../java/org/apache/sis/gui/coverage/CoverageCanvas.java     |  6 ++++--
 .../java/org/apache/sis/gui/coverage/CoverageControls.java   | 12 ++++++++++--
 .../src/main/java/org/apache/sis/image/ResampledImage.java   |  4 ++--
 .../operation/projection/AzimuthalEquidistant.java           |  9 +++++++--
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
index 50316e3..fd6bfa8 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
@@ -291,8 +291,10 @@ public class CoverageCanvas extends MapCanvasAWT {
                 } finally {
                     isPositionableProjection = false;
                 }
-            } catch (NoninvertibleTransformException | FactoryException | TransformException
e) {
-                ExceptionReporter.show(null, null, e);
+            } catch (Exception e) {
+                errorOccurred(e);
+                final Resources i18n = Resources.forLocale(getLocale());
+                ExceptionReporter.show(null, i18n.getString(Resources.Keys.CanNotUseRefSys_1,
projection), e);
             }
         }
 
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
index eb8eadf..e98811e 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageControls.java
@@ -29,6 +29,7 @@ import javafx.scene.layout.VBox;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
+import javafx.beans.binding.ObjectBinding;
 import javafx.collections.ObservableList;
 import javafx.scene.Node;
 import javafx.scene.control.ChoiceBox;
@@ -105,8 +106,15 @@ final class CoverageControls extends Controls {
             crsLabel.setFont(font);
             crsLabel.setPadding(Styles.FORM_INSETS);
             crsShown.setPadding(INDENT_OUTSIDE);
-            referenceSystem.addListener((p,o,n) -> {
-                crsShown.setText(IdentifiedObjects.getDisplayName(n, locale));
+            crsShown.textProperty().bind(new ObjectBinding<String>() {
+                /* Constructor */ {
+                    bind(referenceSystem);
+                }
+
+                /** Invoked when the reference system changed. */
+                @Override protected String computeValue() {
+                    return IdentifiedObjects.getDisplayName(referenceSystem.get(), locale);
+                }
             });
             /*
              * The pane containing controls will be divided in sections separated by labels:
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
index bb31faa..0b90ff6 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/ResampledImage.java
@@ -354,10 +354,10 @@ public class ResampledImage extends ComputedImage {
         if (image == null) {
             positionalConsistency = null;
             final Dimension s = interpolation.getSupportSize();
-            final double[] offset = new double[toSource.getSourceDimensions()];
+            final double[] offset = new double[toSourceSupport.getSourceDimensions()];
             offset[0] = -interpolationSupportOffset(s.width);
             offset[1] = -interpolationSupportOffset(s.height);
-            final MathTransform tr = MathTransforms.concatenate(toSource, MathTransforms.translation(offset));
+            final MathTransform tr = MathTransforms.concatenate(toSourceSupport, MathTransforms.translation(offset));
             image = new PositionalConsistencyImage(this, tr);
             positionalConsistency = image.reference();
         }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AzimuthalEquidistant.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AzimuthalEquidistant.java
index 0c630f9d..6f81b28 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AzimuthalEquidistant.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/AzimuthalEquidistant.java
@@ -178,7 +178,7 @@ public class AzimuthalEquidistant extends NormalizedProjection {
         final double  sinλ  = sin(λ);
         final double  cosφ  = cos(φ);
         final double  sinφ  = sin(φ);
-        final double  cosc  = sinφ0*sinφ + cosφ0*cosφ*cosλ;
+        final double  cosc  = min(1, max(-1, sinφ0*sinφ + cosφ0*cosφ*cosλ));
         final double  c     = acos(cosc);
         final boolean ind   = abs(c) < ANGULAR_TOLERANCE;
         final double  k     = ind ? 1 : c/sin(c);
@@ -229,6 +229,11 @@ public class AzimuthalEquidistant extends NormalizedProjection {
         final double sinD = sin(D);
         final double cosD = cos(D);
         dstPts[dstOff  ]  = atan2(x*sinD, (cosφ0*cosD*D - sinφ0*sinD*y));
-        dstPts[dstOff+1]  = asin(cosD*sinφ0 + sinD*cosφ0*y/D);
+        dstPts[dstOff+1]  = asin(D == 0 ? sinφ0 : sinφ0*cosD + cosφ0*sinD*(y/D));
+        /*
+         * Checking for strict equality (D == 0) is okay because even a very small value
+         * is sufficient for avoiding NaN. We get (y/D) ≤ 1 and sin(D) ≈ D, so the right
+         * term become close to zero.
+         */
     }
 }


Mime
View raw message