comparison backend/src/main/java/org/dive4elements/river/model/River.java @ 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 4c3ccf2b0304
children 3fea9701d58d
comparison
equal deleted inserted replaced
6105:d79bfbe55417 6106:776229dd5bf7
288 } 288 }
289 289
290 290
291 /** 291 /**
292 * This method returns the first gauge that is intersected by <i>a</i> and 292 * This method returns the first gauge that is intersected by <i>a</i> and
293 * <i>b</i>, 293 * <i>b</i>, but which possibly does not ends with a or starts with b.
294 * 294 *
295 * @param a A start point. 295 * @param a A start point.
296 * @param b An end point. 296 * @param b An end point.
297 * 297 *
298 * @return the first intersecting gauge. 298 * @return the first intersecting gauge that does not border with a or b,
299 * the first intersecting gauge if that is impossible.
299 */ 300 */
300 public Gauge determineGauge(double a, double b) { 301 public Gauge determineGauge(double a, double b) {
301 List<Gauge> gauges = determineGauges(a, b); 302 List<Gauge> gauges = determineGauges(a, b);
302 303
303 int idx = a < b ? 0 : gauges.size() - 1; 304 int idx = a < b ? 0 : gauges.size() - 1;
304 305
305 return gauges.isEmpty() ? null : gauges.get(idx); 306 if (a > b) {
307 for (int i = gauges.size() - 1; i >= 0; i--) {
308 Gauge g = gauges.get(i);
309 if (g.getRange().getA().doubleValue() == b)
310 continue;
311 return g;
312 }
313 }
314
315 for (Gauge g: gauges) {
316 if ( g.getRange().getB().doubleValue() == a ) {
317 continue;
318 }
319 return g;
320 }
321
322 return null;
306 } 323 }
307 324
308 /** 325 /**
309 * Returns the min and max distance of this river. The first position in the 326 * Returns the min and max distance of this river. The first position in the
310 * resulting array contains the min distance, the second position the max 327 * resulting array contains the min distance, the second position the max

http://dive4elements.wald.intevation.org