Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Range.java @ 3298:b92e86a78895
Removed superfluous imports.
flys-artifacts/trunk@4983 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 13 Jul 2012 10:15:55 +0000 |
parents | 9c147bbffc36 |
children | 086326be721c |
rev | line source |
---|---|
3138
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.Serializable; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 public class Range implements Serializable { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 public static final double EPSILON = 1e-5; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 protected double start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 protected double end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 public Range() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public Range(double start, double end) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 this.start = start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 this.end = end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public double getStart() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 return start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public double getEnd() { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 return end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public boolean disjoint(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 return start > other.end || other.start > end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public boolean intersects(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 return !disjoint(other); |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public void extend(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 if (other.start < start) start = other.start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 if (other.end > end ) end = other.end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 public boolean clip(Range other) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 if (disjoint(other)) return false; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 if (other.start > start) start = other.start; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 if (other.end < end ) end = other.end; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 return true; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 public boolean inside(double x) { |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 return x > start-EPSILON && x < end+EPSILON; |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
9c147bbffc36
FixA: Move Range out of FixingsOverview
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |