changeset 5743:80b9218ac007

Add containsTolerant to Range.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 17 Apr 2013 14:52:19 +0200
parents a4a894b15c35
children 5bb179d4fd5f
files flys-backend/src/main/java/de/intevation/flys/model/Range.java
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
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();

http://dive4elements.wald.intevation.org