changeset 3273:739aa90eb79e

Fix issue694. flys-artifacts/trunk@4917 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 10 Jul 2012 16:04:44 +0000
parents 31168ac9c7e7
children 43e42315ce22
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jul 10 15:31:56 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jul 10 16:04:44 2012 +0000
@@ -1,3 +1,10 @@
+2012-07-10	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Fix for issue694.
+
+	* src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java:
+	  Also resolve edge cases (last/first cross section km).
+
 2012-07-10	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	Partial fix for issue694 (Heightmarks snap to nearest cross section
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Tue Jul 10 15:31:56 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Tue Jul 10 16:04:44 2012 +0000
@@ -280,20 +280,19 @@
      *
      * @param wkms WKms in which to search for a spatially close W value.
      * @param km the input km, which is compared to values from wkms.
-     * @param next the next available input km.
-     * @param prev the previous available input km.
+     * @param next the next available input km (-1 if unavailable).
+     * @param prev the previous available input km (-1 if unavailable).
      *
      * @return W in wkms that is closer to km than to next and prev, or Double.NaN.
      */
     public double getWAtCloseKm(WKms wkms, double km, double next, double prev) {
         int size = wkms.size();
-        // TODO handle edge cases (with no next or prev).
         for (int i = 0; i < size; i++) {
             double wkmsKm = wkms.getKm(i);
             double dist = Distance.distance(wkmsKm, km);
-            if ((prev != km && dist <= Distance.distance(wkmsKm, prev))
-                && dist <= Distance.distance(wkmsKm, next)) {
-                return wkms.getW(i);    
+            if ((prev == -1d || dist <= Distance.distance(wkmsKm, prev))
+                && (next == -1d || dist <= Distance.distance(wkmsKm, next))) {
+                return wkms.getW(i);
             }
         }
 

http://dive4elements.wald.intevation.org