# HG changeset patch # User Tom Gottfried # Date 1415210869 -3600 # Node ID 67ae70259011adb1c4b5a41e5da845bf34eea3e5 # Parent 5fa1c8be43db99af4c060b43eb3a260f874dcc22 Cross section navigation: behave equally, regardless of whether an input value is below or above the range of possible values. diff -r 5fa1c8be43db -r 67ae70259011 gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/CrossSectionChartThemePanel.java --- 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]; } }