changeset 8468:67ae70259011

Cross section navigation: behave equally, regardless of whether an input value is below or above the range of possible values.
author Tom Gottfried <tom@intevation.de>
date Wed, 05 Nov 2014 19:07:49 +0100
parents 5fa1c8be43db
children 079147282650
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/CrossSectionChartThemePanel.java
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/CrossSectionChartThemePanel.java	Wed Nov 05 15:44:04 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/CrossSectionChartThemePanel.java	Wed Nov 05 19:07:49 2014 +0100
@@ -279,7 +279,7 @@
      * @param to the value to be as close to as possible.
      * @param up if true, prefer numerically higher values in case of two
      *           values with equal distance to \param to.
-     * @return value from in that is closest to to, -1 if none.
+     * @return value from in that is closest to to, NaN if none.
      */
     public static Double closest(Double[] in, double to, boolean up) {
         if (in == null || in.length == 0) {
@@ -289,15 +289,16 @@
         GWT.log ("Closest match for " + (up ? "next" : "previous") + " value to: " +
                 to + " candidates: " + Arrays.toString(in));
         if (up) {
-            // take the first one that is larger
+            double max = in[in.length - 1];
             for (int i = 0; i < in.length; i++) {
-                if (in[i] >= to) {
+                if (in[i] >= to || in[i] == max) {
                     return in[i];
                 }
             }
         } else {
+            double min = in[0];
             for (int i = in.length - 1; i >= 0; i--) {
-                if (in[i] <= to) {
+                if (in[i] <= to || in[i] == min) {
                     return in[i];
                 }
             }

http://dive4elements.wald.intevation.org