2
|
1 |
/*
|
|
2 |
* Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package java.awt;
|
|
27 |
|
|
28 |
import java.awt.geom.AffineTransform;
|
|
29 |
import java.awt.geom.PathIterator;
|
|
30 |
import java.awt.geom.Point2D;
|
|
31 |
import java.awt.geom.Rectangle2D;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* The <code>Shape</code> interface provides definitions for objects
|
|
35 |
* that represent some form of geometric shape. The <code>Shape</code>
|
|
36 |
* is described by a {@link PathIterator} object, which can express the
|
|
37 |
* outline of the <code>Shape</code> as well as a rule for determining
|
|
38 |
* how the outline divides the 2D plane into interior and exterior
|
|
39 |
* points. Each <code>Shape</code> object provides callbacks to get the
|
|
40 |
* bounding box of the geometry, determine whether points or
|
|
41 |
* rectangles lie partly or entirely within the interior
|
|
42 |
* of the <code>Shape</code>, and retrieve a <code>PathIterator</code>
|
|
43 |
* object that describes the trajectory path of the <code>Shape</code>
|
|
44 |
* outline.
|
|
45 |
* <p>
|
|
46 |
* <b>Definition of insideness:</b>
|
|
47 |
* A point is considered to lie inside a
|
|
48 |
* <code>Shape</code> if and only if:
|
|
49 |
* <ul>
|
|
50 |
* <li> it lies completely
|
|
51 |
* inside the<code>Shape</code> boundary <i>or</i>
|
|
52 |
* <li>
|
|
53 |
* it lies exactly on the <code>Shape</code> boundary <i>and</i> the
|
|
54 |
* space immediately adjacent to the
|
|
55 |
* point in the increasing <code>X</code> direction is
|
|
56 |
* entirely inside the boundary <i>or</i>
|
|
57 |
* <li>
|
|
58 |
* it lies exactly on a horizontal boundary segment <b>and</b> the
|
|
59 |
* space immediately adjacent to the point in the
|
|
60 |
* increasing <code>Y</code> direction is inside the boundary.
|
|
61 |
* </ul>
|
|
62 |
* <p>The <code>contains</code> and <code>intersects</code> methods
|
|
63 |
* consider the interior of a <code>Shape</code> to be the area it
|
|
64 |
* encloses as if it were filled. This means that these methods
|
|
65 |
* consider
|
|
66 |
* unclosed shapes to be implicitly closed for the purpose of
|
|
67 |
* determining if a shape contains or intersects a rectangle or if a
|
|
68 |
* shape contains a point.
|
|
69 |
*
|
|
70 |
* @see java.awt.geom.PathIterator
|
|
71 |
* @see java.awt.geom.AffineTransform
|
|
72 |
* @see java.awt.geom.FlatteningPathIterator
|
|
73 |
* @see java.awt.geom.GeneralPath
|
|
74 |
*
|
|
75 |
* @author Jim Graham
|
|
76 |
* @since 1.2
|
|
77 |
*/
|
|
78 |
public interface Shape {
|
|
79 |
/**
|
|
80 |
* Returns an integer {@link Rectangle} that completely encloses the
|
|
81 |
* <code>Shape</code>. Note that there is no guarantee that the
|
|
82 |
* returned <code>Rectangle</code> is the smallest bounding box that
|
|
83 |
* encloses the <code>Shape</code>, only that the <code>Shape</code>
|
|
84 |
* lies entirely within the indicated <code>Rectangle</code>. The
|
|
85 |
* returned <code>Rectangle</code> might also fail to completely
|
|
86 |
* enclose the <code>Shape</code> if the <code>Shape</code> overflows
|
|
87 |
* the limited range of the integer data type. The
|
|
88 |
* <code>getBounds2D</code> method generally returns a
|
|
89 |
* tighter bounding box due to its greater flexibility in
|
|
90 |
* representation.
|
|
91 |
* @return an integer <code>Rectangle</code> that completely encloses
|
|
92 |
* the <code>Shape</code>.
|
|
93 |
* @see #getBounds2D
|
|
94 |
* @since 1.2
|
|
95 |
*/
|
|
96 |
public Rectangle getBounds();
|
|
97 |
|
|
98 |
/**
|
|
99 |
* Returns a high precision and more accurate bounding box of
|
|
100 |
* the <code>Shape</code> than the <code>getBounds</code> method.
|
|
101 |
* Note that there is no guarantee that the returned
|
|
102 |
* {@link Rectangle2D} is the smallest bounding box that encloses
|
|
103 |
* the <code>Shape</code>, only that the <code>Shape</code> lies
|
|
104 |
* entirely within the indicated <code>Rectangle2D</code>. The
|
|
105 |
* bounding box returned by this method is usually tighter than that
|
|
106 |
* returned by the <code>getBounds</code> method and never fails due
|
|
107 |
* to overflow problems since the return value can be an instance of
|
|
108 |
* the <code>Rectangle2D</code> that uses double precision values to
|
|
109 |
* store the dimensions.
|
|
110 |
* @return an instance of <code>Rectangle2D</code> that is a
|
|
111 |
* high-precision bounding box of the <code>Shape</code>.
|
|
112 |
* @see #getBounds
|
|
113 |
* @since 1.2
|
|
114 |
*/
|
|
115 |
public Rectangle2D getBounds2D();
|
|
116 |
|
|
117 |
/**
|
|
118 |
* Tests if the specified coordinates are inside the boundary of the
|
|
119 |
* <code>Shape</code>.
|
|
120 |
* @param x the specified X coordinate to be tested
|
|
121 |
* @param y the specified Y coordinate to be tested
|
|
122 |
* @return <code>true</code> if the specified coordinates are inside
|
|
123 |
* the <code>Shape</code> boundary; <code>false</code>
|
|
124 |
* otherwise.
|
|
125 |
* @since 1.2
|
|
126 |
*/
|
|
127 |
public boolean contains(double x, double y);
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Tests if a specified {@link Point2D} is inside the boundary
|
|
131 |
* of the <code>Shape</code>.
|
|
132 |
* @param p the specified <code>Point2D</code> to be tested
|
|
133 |
* @return <code>true</code> if the specified <code>Point2D</code> is
|
|
134 |
* inside the boundary of the <code>Shape</code>;
|
|
135 |
* <code>false</code> otherwise.
|
|
136 |
* @since 1.2
|
|
137 |
*/
|
|
138 |
public boolean contains(Point2D p);
|
|
139 |
|
|
140 |
/**
|
|
141 |
* Tests if the interior of the <code>Shape</code> intersects the
|
|
142 |
* interior of a specified rectangular area.
|
|
143 |
* The rectangular area is considered to intersect the <code>Shape</code>
|
|
144 |
* if any point is contained in both the interior of the
|
|
145 |
* <code>Shape</code> and the specified rectangular area.
|
|
146 |
* <p>
|
|
147 |
* The {@code Shape.intersects()} method allows a {@code Shape}
|
|
148 |
* implementation to conservatively return {@code true} when:
|
|
149 |
* <ul>
|
|
150 |
* <li>
|
|
151 |
* there is a high probability that the rectangular area and the
|
|
152 |
* <code>Shape</code> intersect, but
|
|
153 |
* <li>
|
|
154 |
* the calculations to accurately determine this intersection
|
|
155 |
* are prohibitively expensive.
|
|
156 |
* </ul>
|
|
157 |
* This means that for some {@code Shapes} this method might
|
|
158 |
* return {@code true} even though the rectangular area does not
|
|
159 |
* intersect the {@code Shape}.
|
|
160 |
* The {@link java.awt.geom.Area Area} class performs
|
|
161 |
* more accurate computations of geometric intersection than most
|
|
162 |
* {@code Shape} objects and therefore can be used if a more precise
|
|
163 |
* answer is required.
|
|
164 |
*
|
|
165 |
* @param x the X coordinate of the upper-left corner
|
|
166 |
* of the specified rectangular area
|
|
167 |
* @param y the Y coordinate of the upper-left corner
|
|
168 |
* of the specified rectangular area
|
|
169 |
* @param w the width of the specified rectangular area
|
|
170 |
* @param h the height of the specified rectangular area
|
|
171 |
* @return <code>true</code> if the interior of the <code>Shape</code> and
|
|
172 |
* the interior of the rectangular area intersect, or are
|
|
173 |
* both highly likely to intersect and intersection calculations
|
|
174 |
* would be too expensive to perform; <code>false</code> otherwise.
|
|
175 |
* @see java.awt.geom.Area
|
|
176 |
* @since 1.2
|
|
177 |
*/
|
|
178 |
public boolean intersects(double x, double y, double w, double h);
|
|
179 |
|
|
180 |
/**
|
|
181 |
* Tests if the interior of the <code>Shape</code> intersects the
|
|
182 |
* interior of a specified <code>Rectangle2D</code>.
|
|
183 |
* The {@code Shape.intersects()} method allows a {@code Shape}
|
|
184 |
* implementation to conservatively return {@code true} when:
|
|
185 |
* <ul>
|
|
186 |
* <li>
|
|
187 |
* there is a high probability that the <code>Rectangle2D</code> and the
|
|
188 |
* <code>Shape</code> intersect, but
|
|
189 |
* <li>
|
|
190 |
* the calculations to accurately determine this intersection
|
|
191 |
* are prohibitively expensive.
|
|
192 |
* </ul>
|
|
193 |
* This means that for some {@code Shapes} this method might
|
|
194 |
* return {@code true} even though the {@code Rectangle2D} does not
|
|
195 |
* intersect the {@code Shape}.
|
|
196 |
* The {@link java.awt.geom.Area Area} class performs
|
|
197 |
* more accurate computations of geometric intersection than most
|
|
198 |
* {@code Shape} objects and therefore can be used if a more precise
|
|
199 |
* answer is required.
|
|
200 |
*
|
|
201 |
* @param r the specified <code>Rectangle2D</code>
|
|
202 |
* @return <code>true</code> if the interior of the <code>Shape</code> and
|
|
203 |
* the interior of the specified <code>Rectangle2D</code>
|
|
204 |
* intersect, or are both highly likely to intersect and intersection
|
|
205 |
* calculations would be too expensive to perform; <code>false</code>
|
|
206 |
* otherwise.
|
|
207 |
* @see #intersects(double, double, double, double)
|
|
208 |
* @since 1.2
|
|
209 |
*/
|
|
210 |
public boolean intersects(Rectangle2D r);
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Tests if the interior of the <code>Shape</code> entirely contains
|
|
214 |
* the specified rectangular area. All coordinates that lie inside
|
|
215 |
* the rectangular area must lie within the <code>Shape</code> for the
|
|
216 |
* entire rectanglar area to be considered contained within the
|
|
217 |
* <code>Shape</code>.
|
|
218 |
* <p>
|
|
219 |
* The {@code Shape.contains()} method allows a {@code Shape}
|
|
220 |
* implementation to conservatively return {@code false} when:
|
|
221 |
* <ul>
|
|
222 |
* <li>
|
|
223 |
* the <code>intersect</code> method returns <code>true</code> and
|
|
224 |
* <li>
|
|
225 |
* the calculations to determine whether or not the
|
|
226 |
* <code>Shape</code> entirely contains the rectangular area are
|
|
227 |
* prohibitively expensive.
|
|
228 |
* </ul>
|
|
229 |
* This means that for some {@code Shapes} this method might
|
|
230 |
* return {@code false} even though the {@code Shape} contains
|
|
231 |
* the rectangular area.
|
|
232 |
* The {@link java.awt.geom.Area Area} class performs
|
|
233 |
* more accurate geometric computations than most
|
|
234 |
* {@code Shape} objects and therefore can be used if a more precise
|
|
235 |
* answer is required.
|
|
236 |
*
|
|
237 |
* @param x the X coordinate of the upper-left corner
|
|
238 |
* of the specified rectangular area
|
|
239 |
* @param y the Y coordinate of the upper-left corner
|
|
240 |
* of the specified rectangular area
|
|
241 |
* @param w the width of the specified rectangular area
|
|
242 |
* @param h the height of the specified rectangular area
|
|
243 |
* @return <code>true</code> if the interior of the <code>Shape</code>
|
|
244 |
* entirely contains the specified rectangular area;
|
|
245 |
* <code>false</code> otherwise or, if the <code>Shape</code>
|
|
246 |
* contains the rectangular area and the
|
|
247 |
* <code>intersects</code> method returns <code>true</code>
|
|
248 |
* and the containment calculations would be too expensive to
|
|
249 |
* perform.
|
|
250 |
* @see java.awt.geom.Area
|
|
251 |
* @see #intersects
|
|
252 |
* @since 1.2
|
|
253 |
*/
|
|
254 |
public boolean contains(double x, double y, double w, double h);
|
|
255 |
|
|
256 |
/**
|
|
257 |
* Tests if the interior of the <code>Shape</code> entirely contains the
|
|
258 |
* specified <code>Rectangle2D</code>.
|
|
259 |
* The {@code Shape.contains()} method allows a {@code Shape}
|
|
260 |
* implementation to conservatively return {@code false} when:
|
|
261 |
* <ul>
|
|
262 |
* <li>
|
|
263 |
* the <code>intersect</code> method returns <code>true</code> and
|
|
264 |
* <li>
|
|
265 |
* the calculations to determine whether or not the
|
|
266 |
* <code>Shape</code> entirely contains the <code>Rectangle2D</code>
|
|
267 |
* are prohibitively expensive.
|
|
268 |
* </ul>
|
|
269 |
* This means that for some {@code Shapes} this method might
|
|
270 |
* return {@code false} even though the {@code Shape} contains
|
|
271 |
* the {@code Rectangle2D}.
|
|
272 |
* The {@link java.awt.geom.Area Area} class performs
|
|
273 |
* more accurate geometric computations than most
|
|
274 |
* {@code Shape} objects and therefore can be used if a more precise
|
|
275 |
* answer is required.
|
|
276 |
*
|
|
277 |
* @param r The specified <code>Rectangle2D</code>
|
|
278 |
* @return <code>true</code> if the interior of the <code>Shape</code>
|
|
279 |
* entirely contains the <code>Rectangle2D</code>;
|
|
280 |
* <code>false</code> otherwise or, if the <code>Shape</code>
|
|
281 |
* contains the <code>Rectangle2D</code> and the
|
|
282 |
* <code>intersects</code> method returns <code>true</code>
|
|
283 |
* and the containment calculations would be too expensive to
|
|
284 |
* perform.
|
|
285 |
* @see #contains(double, double, double, double)
|
|
286 |
* @since 1.2
|
|
287 |
*/
|
|
288 |
public boolean contains(Rectangle2D r);
|
|
289 |
|
|
290 |
/**
|
|
291 |
* Returns an iterator object that iterates along the
|
|
292 |
* <code>Shape</code> boundary and provides access to the geometry of the
|
|
293 |
* <code>Shape</code> outline. If an optional {@link AffineTransform}
|
|
294 |
* is specified, the coordinates returned in the iteration are
|
|
295 |
* transformed accordingly.
|
|
296 |
* <p>
|
|
297 |
* Each call to this method returns a fresh <code>PathIterator</code>
|
|
298 |
* object that traverses the geometry of the <code>Shape</code> object
|
|
299 |
* independently from any other <code>PathIterator</code> objects in use
|
|
300 |
* at the same time.
|
|
301 |
* <p>
|
|
302 |
* It is recommended, but not guaranteed, that objects
|
|
303 |
* implementing the <code>Shape</code> interface isolate iterations
|
|
304 |
* that are in process from any changes that might occur to the original
|
|
305 |
* object's geometry during such iterations.
|
|
306 |
*
|
|
307 |
* @param at an optional <code>AffineTransform</code> to be applied to the
|
|
308 |
* coordinates as they are returned in the iteration, or
|
|
309 |
* <code>null</code> if untransformed coordinates are desired
|
|
310 |
* @return a new <code>PathIterator</code> object, which independently
|
|
311 |
* traverses the geometry of the <code>Shape</code>.
|
|
312 |
* @since 1.2
|
|
313 |
*/
|
|
314 |
public PathIterator getPathIterator(AffineTransform at);
|
|
315 |
|
|
316 |
/**
|
|
317 |
* Returns an iterator object that iterates along the <code>Shape</code>
|
|
318 |
* boundary and provides access to a flattened view of the
|
|
319 |
* <code>Shape</code> outline geometry.
|
|
320 |
* <p>
|
|
321 |
* Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are
|
|
322 |
* returned by the iterator.
|
|
323 |
* <p>
|
|
324 |
* If an optional <code>AffineTransform</code> is specified,
|
|
325 |
* the coordinates returned in the iteration are transformed
|
|
326 |
* accordingly.
|
|
327 |
* <p>
|
|
328 |
* The amount of subdivision of the curved segments is controlled
|
|
329 |
* by the <code>flatness</code> parameter, which specifies the
|
|
330 |
* maximum distance that any point on the unflattened transformed
|
|
331 |
* curve can deviate from the returned flattened path segments.
|
|
332 |
* Note that a limit on the accuracy of the flattened path might be
|
|
333 |
* silently imposed, causing very small flattening parameters to be
|
|
334 |
* treated as larger values. This limit, if there is one, is
|
|
335 |
* defined by the particular implementation that is used.
|
|
336 |
* <p>
|
|
337 |
* Each call to this method returns a fresh <code>PathIterator</code>
|
|
338 |
* object that traverses the <code>Shape</code> object geometry
|
|
339 |
* independently from any other <code>PathIterator</code> objects in use at
|
|
340 |
* the same time.
|
|
341 |
* <p>
|
|
342 |
* It is recommended, but not guaranteed, that objects
|
|
343 |
* implementing the <code>Shape</code> interface isolate iterations
|
|
344 |
* that are in process from any changes that might occur to the original
|
|
345 |
* object's geometry during such iterations.
|
|
346 |
*
|
|
347 |
* @param at an optional <code>AffineTransform</code> to be applied to the
|
|
348 |
* coordinates as they are returned in the iteration, or
|
|
349 |
* <code>null</code> if untransformed coordinates are desired
|
|
350 |
* @param flatness the maximum distance that the line segments used to
|
|
351 |
* approximate the curved segments are allowed to deviate
|
|
352 |
* from any point on the original curve
|
|
353 |
* @return a new <code>PathIterator</code> that independently traverses
|
|
354 |
* a flattened view of the geometry of the <code>Shape</code>.
|
|
355 |
* @since 1.2
|
|
356 |
*/
|
|
357 |
public PathIterator getPathIterator(AffineTransform at, double flatness);
|
|
358 |
}
|