comparison backend/src/main/java/org/dive4elements/river/model/River.java @ 6229:3fea9701d58d

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.
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 06 Jun 2013 18:23:17 +0200
parents 776229dd5bf7
children 6ff574778491
comparison
equal deleted inserted replaced
6228:cb536a9a6c17 6229:3fea9701d58d
299 * the first intersecting gauge if that is impossible. 299 * the first intersecting gauge if that is impossible.
300 */ 300 */
301 public Gauge determineGauge(double a, double b) { 301 public Gauge determineGauge(double a, double b) {
302 List<Gauge> gauges = determineGauges(a, b); 302 List<Gauge> gauges = determineGauges(a, b);
303 303
304 int idx = a < b ? 0 : gauges.size() - 1;
305
306 if (a > b) { 304 if (a > b) {
307 for (int i = gauges.size() - 1; i >= 0; i--) { 305 for (int i = gauges.size() - 1; i >= 0; i--) {
308 Gauge g = gauges.get(i); 306 Gauge g = gauges.get(i);
309 if (g.getRange().getA().doubleValue() == b) 307 if (KM_CMP.compare(g.getRange().getA().doubleValue(), a) == 0)
310 continue; 308 continue;
311 return g; 309 return g;
312 } 310 }
313 } 311 }
314 312
315 for (Gauge g: gauges) { 313 for (Gauge g: gauges) {
316 if ( g.getRange().getB().doubleValue() == a ) { 314 if (KM_CMP.compare(g.getRange().getB().doubleValue(), a) == 0) {
317 continue; 315 continue;
318 } 316 }
319 return g; 317 return g;
320 } 318 }
321 319

http://dive4elements.wald.intevation.org