001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2001, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.resources.geometry;
018:
019: // J2SE dependencies
020: import java.awt.geom.Line2D;
021: import java.awt.geom.Point2D;
022: import java.awt.geom.Rectangle2D;
023: import java.io.ObjectStreamException;
024: import java.io.Serializable;
025:
026: /**
027: * An immutable subclass of a {@link Rectangle2D} with bounds extending toward infinities.
028: * The {@link #getMinX} and {@link #getMinY} methods return always
029: * {@link java.lang.Double#NEGATIVE_INFINITY}, while the {@link #getMaxX} and
030: * {@link #getMaxY} methods return always {@link java.lang.Double#POSITIVE_INFINITY}.
031: * This rectangle can be used as argument in the {@link XRectangle2D} constructor for
032: * initializing a new {@code XRectangle2D} to infinite bounds.
033: *
034: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/resources/geometry/InfiniteRectangle2D.java $
035: * @version $Id: InfiniteRectangle2D.java 22482 2006-10-31 02:58:00Z desruisseaux $
036: * @author Martin Desruisseaux
037: */
038: final class InfiniteRectangle2D extends Rectangle2D implements
039: Serializable {
040: /**
041: * Serial number for interoperability with different versions.
042: */
043: private static final long serialVersionUID = 5281254268988984523L;
044:
045: /**
046: * A singleton instance of {@code InfiniteRectangle2D}.
047: */
048: public static final Rectangle2D INFINITY = new InfiniteRectangle2D();
049:
050: /**
051: * Private constructor for the {@link #INFINITY} singleton only.
052: */
053: private InfiniteRectangle2D() {
054: }
055:
056: /**
057: * Returns the minimum value, which is negative infinity.
058: */
059: public double getX() {
060: return java.lang.Double.NEGATIVE_INFINITY;
061: }
062:
063: /**
064: * Returns the minimum value, which is negative infinity.
065: */
066: public double getY() {
067: return java.lang.Double.NEGATIVE_INFINITY;
068: }
069:
070: /**
071: * Returns the minimum value, which is negative infinity.
072: */
073: public double getMinX() {
074: return java.lang.Double.NEGATIVE_INFINITY;
075: }
076:
077: /**
078: * Returns the minimum value, which is negative infinity.
079: */
080: public double getMinY() {
081: return java.lang.Double.NEGATIVE_INFINITY;
082: }
083:
084: /**
085: * Returns the maximum value, which is positive infinity.
086: */
087: public double getMaxX() {
088: return java.lang.Double.POSITIVE_INFINITY;
089: }
090:
091: /**
092: * Returns the maximum value, which is positive infinity.
093: */
094: public double getMaxY() {
095: return java.lang.Double.POSITIVE_INFINITY;
096: }
097:
098: /**
099: * Returns the width, which is positive infinity.
100: */
101: public double getWidth() {
102: return java.lang.Double.POSITIVE_INFINITY;
103: }
104:
105: /**
106: * Returns the height, which is positive infinity.
107: */
108: public double getHeight() {
109: return java.lang.Double.POSITIVE_INFINITY;
110: }
111:
112: /**
113: * Returns the center, which is NaN since we can't compute a center from infinite bounds.
114: */
115: public double getCenterX() {
116: return java.lang.Double.NaN;
117: }
118:
119: /**
120: * Returns the center, which is NaN since we can't compute a center from infinite bounds.
121: */
122: public double getCenterY() {
123: return java.lang.Double.NaN;
124: }
125:
126: /**
127: * Do nothing, since we can't extends an infinite rectangle.
128: */
129: public void add(Rectangle2D rect) {
130: }
131:
132: /**
133: * Do nothing, since we can't extends an infinite rectangle.
134: */
135: public void add(Point2D point) {
136: }
137:
138: /**
139: * Do nothing, since we can't extends an infinite rectangle.
140: */
141: public void add(double x, double y) {
142: }
143:
144: /**
145: * Returns 0, since the specified point can't be outside this rectangle.
146: */
147: public int outcode(double x, double y) {
148: return 0;
149: }
150:
151: /**
152: * Returns 0, since the specified point can't be outside this rectangle.
153: */
154: public int outcode(Point2D point) {
155: return 0;
156: }
157:
158: /**
159: * Returns {@code true} since this rectangle contains all points.
160: */
161: public boolean contains(Point2D point) {
162: return true;
163: }
164:
165: /**
166: * Returns {@code true} since this rectangle contains all points.
167: */
168: public boolean contains(Rectangle2D rect) {
169: return true;
170: }
171:
172: /**
173: * Returns {@code true} since this rectangle contains all points.
174: */
175: public boolean contains(double x, double y) {
176: return true;
177: }
178:
179: /**
180: * Returns {@code true} since this rectangle contains all points.
181: */
182: public boolean contains(double x, double y, double w, double h) {
183: return true;
184: }
185:
186: /**
187: * Returns {@code true} since this rectangle contains all points.
188: */
189: public boolean intersects(Rectangle2D rect) {
190: return true;
191: }
192:
193: /**
194: * Returns {@code true} since this rectangle contains all points.
195: */
196: public boolean intersects(double x, double y, double w, double h) {
197: return true;
198: }
199:
200: /**
201: * Returns {@code true} since this rectangle contains all points.
202: */
203: public boolean intersectsLine(double x, double y, double u, double v) {
204: return true;
205: }
206:
207: /**
208: * Returns {@code true} since this rectangle contains all points.
209: */
210: public boolean intersectsLine(Line2D line) {
211: return true;
212: }
213:
214: /**
215: * Returns {@code false} since an infinite rectangle is far from empty.
216: */
217: public boolean isEmpty() {
218: return false;
219: }
220:
221: /**
222: * Returns {@code this}.
223: * No need to returns a clone, since this rectangle is immutable.
224: */
225: public Rectangle2D getFrame() {
226: return this ;
227: }
228:
229: /**
230: * Returns {@code this}.
231: * No need to returns a clone, since this rectangle is immutable.
232: */
233: public Rectangle2D getBounds2D() {
234: return this ;
235: }
236:
237: /**
238: * Returns {@code this}, since this rectangle can't be extended.
239: * No need to returns a clone, since this rectangle is immutable.
240: */
241: public Rectangle2D createUnion(Rectangle2D rect) {
242: return this ;
243: }
244:
245: /**
246: * Returns a clone of the specified rectangle.
247: */
248: public Rectangle2D createIntersection(Rectangle2D rect) {
249: return (Rectangle2D) rect.clone();
250: }
251:
252: /**
253: * Always throws an exception, since this rectangle is immutable.
254: *
255: * @todo Throws UnmodifiableGeometryException instead?
256: * (defined in renderer module for now)
257: */
258: public void setRect(double x, double y, double w, double h) {
259: throw new UnsupportedOperationException();
260: }
261:
262: /**
263: * Returns the singleton instance of {@code InfiniteRectangle2D}.
264: */
265: private Object readResolve() throws ObjectStreamException {
266: return INFINITY;
267: }
268: }
|