001: /*
002: * The JTS Topology Suite is a collection of Java classes that
003: * implement the fundamental operations required to validate a given
004: * geo-spatial data set to a known topological specification.
005: *
006: * Copyright (C) 2001 Vivid Solutions
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033: package com.vividsolutions.jts.index.bintree;
034:
035: /**
036: * Represents an (1-dimensional) closed interval on the Real number line.
037: *
038: * @version 1.7
039: */
040: public class Interval {
041:
042: public double min, max;
043:
044: public Interval() {
045: min = 0.0;
046: max = 0.0;
047: }
048:
049: public Interval(double min, double max) {
050: init(min, max);
051: }
052:
053: public Interval(Interval interval) {
054: init(interval.min, interval.max);
055: }
056:
057: public void init(double min, double max) {
058: this .min = min;
059: this .max = max;
060: if (min > max) {
061: this .min = max;
062: this .max = min;
063: }
064: }
065:
066: public double getMin() {
067: return min;
068: }
069:
070: public double getMax() {
071: return max;
072: }
073:
074: public double getWidth() {
075: return max - min;
076: }
077:
078: public void expandToInclude(Interval interval) {
079: if (interval.max > max)
080: max = interval.max;
081: if (interval.min < min)
082: min = interval.min;
083: }
084:
085: public boolean overlaps(Interval interval) {
086: return overlaps(interval.min, interval.max);
087: }
088:
089: public boolean overlaps(double min, double max) {
090: if (this .min > max || this .max < min)
091: return false;
092: return true;
093: }
094:
095: public boolean contains(Interval interval) {
096: return contains(interval.min, interval.max);
097: }
098:
099: public boolean contains(double min, double max) {
100: return (min >= this .min && max <= this .max);
101: }
102:
103: public boolean contains(double p) {
104: return (p >= this .min && p <= this .max);
105: }
106:
107: public String toString() {
108: return "[" + min + ", " + max + "]";
109: }
110: }
|