[Dive4elements-commits] [PATCH 1 of 4] Fix gauge determination

Wald Commits scm-commit at wald.intevation.org
Fri Jun 7 11:49:59 CEST 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1370535797 -7200
# Node ID 3fea9701d58d948e5a91ffb550bbdf1857ef6b7f
# Parent  cb536a9a6c17eec63a64bde794d28ad75ca9e284
Fix gauge determination.

    If we look upstream ( a > b ) we still have to compare
    the start value of our range against the gauge and not the end
    value. The start value is always the relevant value as we
    handle the direction by checking this against A or B of the gauge.

    Also:
    I will never compare doubles with == again.
    I will never compare doubles with == again.
    I will never compare doubles with == again.
    I will never compare doubles with == again.
    I will never compare doubles with == again.

diff -r cb536a9a6c17 -r 3fea9701d58d backend/src/main/java/org/dive4elements/river/model/River.java
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Thu Jun 06 18:10:19 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Thu Jun 06 18:23:17 2013 +0200
@@ -301,19 +301,17 @@
     public Gauge determineGauge(double a, double b) {
         List<Gauge> gauges = determineGauges(a, b);
 
-        int idx = a < b ? 0 : gauges.size() - 1;
-
         if (a > b) {
             for (int i = gauges.size() - 1; i >= 0; i--) {
                 Gauge g = gauges.get(i);
-                if (g.getRange().getA().doubleValue() == b)
+                if (KM_CMP.compare(g.getRange().getA().doubleValue(), a) == 0)
                     continue;
                 return g;
             }
         }
 
         for (Gauge g: gauges) {
-            if ( g.getRange().getB().doubleValue() == a ) {
+            if (KM_CMP.compare(g.getRange().getB().doubleValue(), a) == 0) {
                 continue;
             }
             return g;


More information about the Dive4elements-commits mailing list