sascha@3138: package de.intevation.flys.artifacts.model; sascha@3138: sascha@3138: import java.io.Serializable; sascha@3138: sascha@3138: public class Range implements Serializable { sascha@3138: sascha@3138: public static final double EPSILON = 1e-5; sascha@3138: sascha@3138: protected double start; sascha@3138: protected double end; sascha@3138: sascha@3138: public Range() { sascha@3138: } sascha@3138: sascha@3401: public Range(Range other) { sascha@3401: start = other.start; sascha@3401: end = other.end; sascha@3401: } sascha@3401: sascha@3138: public Range(double start, double end) { sascha@3138: this.start = start; sascha@3138: this.end = end; sascha@3138: } sascha@3138: sascha@3138: public double getStart() { sascha@3138: return start; sascha@3138: } sascha@3138: sascha@3138: public double getEnd() { sascha@3138: return end; sascha@3138: } sascha@3138: sascha@3138: public boolean disjoint(Range other) { sascha@3138: return start > other.end || other.start > end; sascha@3138: } sascha@3138: sascha@3138: public boolean intersects(Range other) { sascha@3138: return !disjoint(other); sascha@3138: } sascha@3138: sascha@3138: public void extend(Range other) { sascha@3138: if (other.start < start) start = other.start; sascha@3138: if (other.end > end ) end = other.end; sascha@3138: } sascha@3138: sascha@3138: public boolean clip(Range other) { sascha@3138: if (disjoint(other)) return false; sascha@3138: sascha@3138: if (other.start > start) start = other.start; sascha@3138: if (other.end < end ) end = other.end; sascha@3138: sascha@3138: return true; sascha@3138: } sascha@3138: sascha@3138: public boolean inside(double x) { sascha@3138: return x > start-EPSILON && x < end+EPSILON; sascha@3138: } sascha@3138: } sascha@3138: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :