[PATCH] (issue1782) Select index based on km for step generation

Wald Commits scm-commit at wald.intevation.org
Tue Dec 16 15:29:48 CET 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1418740184 -3600
# Node ID 7d0c4e5088353de03d710e7f8c8312dc5fa92f5e
# Parent  da9365fc2f425e2c63a7f16f7a2197a475b16845
(issue1782) Select index based on km for step generation

    If we calculate from a larger KM to a smaller KM the
    larger index refers to the smaller KM so to correctly draw
    the steps with the assumption that the previous q is drawn
    together with the current q we have to select the next / prev
    index accordingly.

diff -r da9365fc2f42 -r 7d0c4e508835 artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Dec 16 14:27:13 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Tue Dec 16 15:29:44 2014 +0100
@@ -267,16 +267,25 @@
         for (int i = 0; i < size; i++) {
             if (i==0) {
                 series.add(wqkms.getKm(i), wqkms.getQ(i), false);
-            }
-            else {
+            } else if (i == size-1) {
+                series.add(wqkms.getKm(i), wqkms.getQ(i), false);
+            } else {
                 //Add two points.
-                double halveX = (wqkms.getKm(i-1) + wqkms.getKm(i)) / 2d;
-                series.add(halveX, wqkms.getQ(i-1), false);
+                double prevX;
+                double prevQ;
+                if (wqkms.getKm(i + 1) < wqkms.getKm(i)) {
+                    /* Depending on the data direction the previous km / q
+                     * might have a larger index when we draw right to left data. */
+                    prevX = wqkms.getKm(i + 1);
+                    prevQ = wqkms.getQ(i + 1);
+                } else {
+                    prevX = wqkms.getKm(i - 1);
+                    prevQ = wqkms.getQ(i - 1);
+                }
+                double halveX = (prevX + wqkms.getKm(i)) / 2d;
+                series.add(halveX, prevQ, false);
                 series.add(halveX, wqkms.getQ(i), false);
             }
-            if (i == size-1) {
-                series.add(wqkms.getKm(i), wqkms.getQ(i), false);
-            }
         }
     }
 


More information about the Dive4Elements-commits mailing list