changeset 6106:776229dd5bf7

determineGauge tries now to find the correct Gauge by handling overlapping borders otherwise for the exact borders of a gauge the upstream/downstream element was selected.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 27 May 2013 15:00:34 +0200
parents d79bfbe55417
children e296c05a0c5b
files backend/src/main/java/org/dive4elements/river/model/River.java
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Mon May 27 13:35:08 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Mon May 27 15:00:34 2013 +0200
@@ -290,19 +290,36 @@
 
     /**
      * This method returns the first gauge that is intersected by <i>a</i> and
-     * <i>b</i>,
+     * <i>b</i>, but which possibly does not ends with a or starts with b.
      *
      * @param a A start point.
      * @param b An end point.
      *
-     * @return the first intersecting gauge.
+     * @return the first intersecting gauge that does not border with a or b,
+     * the first intersecting gauge if that is impossible.
      */
     public Gauge determineGauge(double a, double b) {
         List<Gauge> gauges = determineGauges(a, b);
 
         int idx = a < b ? 0 : gauges.size() - 1;
 
-        return gauges.isEmpty() ? null : gauges.get(idx);
+        if (a > b) {
+            for (int i = gauges.size() - 1; i >= 0; i--) {
+                Gauge g = gauges.get(i);
+                if (g.getRange().getA().doubleValue() == b)
+                    continue;
+                return g;
+            }
+        }
+
+        for (Gauge g: gauges) {
+            if ( g.getRange().getB().doubleValue() == a ) {
+                continue;
+            }
+            return g;
+        }
+
+        return null;
     }
 
     /**

http://dive4elements.wald.intevation.org