Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/Range.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java@f7208c190e4a |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.model; | |
2 | |
3 import java.io.Serializable; | |
4 | |
5 /** A range from ... to .*/ | |
6 public class Range implements Serializable { | |
7 | |
8 public static final double EPSILON = 1e-5; | |
9 | |
10 protected double start; | |
11 protected double end; | |
12 | |
13 public Range() { | |
14 } | |
15 | |
16 public Range(Range other) { | |
17 start = other.start; | |
18 end = other.end; | |
19 } | |
20 | |
21 public Range(double start, double end) { | |
22 this.start = start; | |
23 this.end = end; | |
24 } | |
25 | |
26 public double getStart() { | |
27 return start; | |
28 } | |
29 | |
30 public double getEnd() { | |
31 return end; | |
32 } | |
33 | |
34 public boolean disjoint(double ostart, double oend) { | |
35 return start > oend || ostart > end; | |
36 } | |
37 | |
38 public boolean disjoint(Range other) { | |
39 return start > other.end || other.start > end; | |
40 } | |
41 | |
42 public boolean intersects(Range other) { | |
43 return !disjoint(other); | |
44 } | |
45 | |
46 public void extend(Range other) { | |
47 if (other.start < start) start = other.start; | |
48 if (other.end > end ) end = other.end; | |
49 } | |
50 | |
51 public boolean clip(Range other) { | |
52 if (disjoint(other)) return false; | |
53 | |
54 if (other.start > start) start = other.start; | |
55 if (other.end < end ) end = other.end; | |
56 | |
57 return true; | |
58 } | |
59 | |
60 /** True if start>x<end (+ some epsilon) . */ | |
61 public boolean inside(double x) { | |
62 return x > start-EPSILON && x < end+EPSILON; | |
63 } | |
64 } | |
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |