comparison backend/src/main/java/org/dive4elements/river/utils/EpsilonComparator.java @ 7730:e1b831fe435a slt-simplify-cross-sections

Merged default into slt-simplify-cross-sections branch and updated package and class names.
author Tom Gottfried <tom@intevation.de>
date Mon, 20 Jan 2014 14:04:20 +0100
parents 164e2f2c9bea
children
comparison
equal deleted inserted replaced
5084:ca45dd039b54 7730:e1b831fe435a
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.utils;
10
11 import java.util.Comparator;
12 import java.io.Serializable;
13
14 /** Comparator with some tolerance (epsilon). */
15 public class EpsilonComparator implements Comparator<Double>, Serializable
16 {
17 public static final double EPSILON = 1e-4;
18
19 /** Ready-made comparator with 1e-4 tolerance. */
20 public static final EpsilonComparator CMP = new EpsilonComparator(EPSILON);
21
22 private double epsilon;
23
24 public EpsilonComparator(double epsilon) {
25 this.epsilon = epsilon;
26 }
27
28 @Override
29 public int compare(Double a, Double b) {
30 double diff = a - b;
31 if (diff < -epsilon) return -1;
32 if (diff > epsilon) return +1;
33 return 0;
34 }
35 }
36 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org