Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/model/Range.java @ 5743:80b9218ac007
Add containsTolerant to Range.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 17 Apr 2013 14:52:19 +0200 |
parents | 7b1c5fe4ebf3 |
children |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/Range.java Wed Apr 17 10:06:13 2013 +0200 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Range.java Wed Apr 17 14:52:19 2013 +0200 @@ -19,6 +19,7 @@ public class Range implements Serializable { + public static final double EPSILON = 1e-5; private Integer id; private BigDecimal a; private BigDecimal b; @@ -73,6 +74,22 @@ this.b = b; } + public boolean containsTolerant(double x) { + return containsTolerant(x, EPSILON); + } + + public boolean containsTolerant(double x, double tolerance) { + BigDecimal b = this.b != null ? this.b : a; + double av = a.doubleValue(); + double bv = b.doubleValue(); + if (av > bv) { + double t = av; + av = bv; + bv = t; + } + return x+tolerance >= av && x-tolerance <= bv; + } + public boolean contains(double x) { BigDecimal b = this.b != null ? this.b : a; double av = a.doubleValue();