[Dive4elements-commits] [PATCH] determineGauge tries now to find the correct Gauge by handling overlapping borders
Wald Commits
scm-commit at wald.intevation.org
Mon May 27 15:00:53 CEST 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1369659634 -7200
# Node ID 776229dd5bf724259a69372356f499f98874d3ed
# Parent d79bfbe55417b71d9bf84192ea7ba850c5e5bc93
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.
diff -r d79bfbe55417 -r 776229dd5bf7 backend/src/main/java/org/dive4elements/river/model/River.java
--- 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;
}
/**
More information about the Dive4elements-commits
mailing list