diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java @ 3903:0623cdf32b38

Document issue880 flys-artifacts/trunk@5568 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Sat, 22 Sep 2012 09:55:01 +0000
parents afc7bfb4800b
children fe70edde0897
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Sat Sep 22 07:47:12 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Sat Sep 22 09:55:01 2012 +0000
@@ -303,12 +303,36 @@
      * @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) {
+        // TODO symbolic "-1" pr next/prev is a bad idea (tm), as we compare
+        //      distances to these values later.
+        // TODO issue888
+
         int size = wkms.size();
         for (int i = 0; i < size; i++) {
             double wkmsKm = wkms.getKm(i);
             double dist = Distance.distance(wkmsKm, km);
-            if ((prev == -1d || dist <= Distance.distance(wkmsKm, prev))
-                && (next == -1d || dist <= Distance.distance(wkmsKm, next))) {
+            if (dist == 0d) {
+                return wkms.getW(i);
+            }
+
+            // Problematic Cases:
+            // X == km , | and | == prev and next, (?) == wkmsKm
+            //
+            // Standard case:
+            // ----------|----X-----|-------
+            //     (1)    (2)    (3)   (4)
+            // 
+            // With prev==-1
+            // -1 ------X-------|------
+            //    (5)      (6)     (7)
+            //
+            // With next==-1
+            //
+            // ---|-----X----- -1
+            // (8)  (9)   (10)
+
+            if (dist <= Distance.distance(wkmsKm, prev)
+                && dist <= Distance.distance(wkmsKm, next)) {
                 return wkms.getW(i);
             }
         }

http://dive4elements.wald.intevation.org