# HG changeset patch # User Felix Wolfsteller # Date 1366203139 -7200 # Node ID 80b9218ac0071d786ff312ad324b5cb83568af1f # Parent a4a894b15c35df411f8c8e5fafb38114134cbca0 Add containsTolerant to Range. diff -r a4a894b15c35 -r 80b9218ac007 flys-backend/src/main/java/de/intevation/flys/model/Range.java --- 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();