1. /*
  2. * @(#)Shape.java 1.16 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.geom.AffineTransform;
  9. import java.awt.geom.PathIterator;
  10. import java.awt.geom.Point2D;
  11. import java.awt.geom.Rectangle2D;
  12. /**
  13. * The <code>Shape</code> interface provides definitions for objects
  14. * that represent some form of geometric shape. The <code>Shape</code>
  15. * is described by a {@link PathIterator} object, which can express the
  16. * outline of the <code>Shape</code> as well as a rule for determining
  17. * how the outline divides the 2D plane into interior and exterior
  18. * points. Each <code>Shape</code> object provides callbacks to get the
  19. * bounding box of the geometry, determine whether points or
  20. * rectangles lie partly or entirely within the interior
  21. * of the <code>Shape</code>, and retrieve a <code>PathIterator</code>
  22. * object that describes the trajectory path of the <code>Shape</code>
  23. * outline.
  24. * <p>
  25. * <b>Definition of insideness:</b>
  26. * A point is considered to lie inside a
  27. * <code>Shape</code> if and only if:
  28. * <ul>
  29. * <li> it lies completely
  30. * inside the<code>Shape</code> boundary <i>or</i>
  31. * <li>
  32. * it lies exactly on the <code>Shape</code> boundary <i>and</i> the
  33. * space immediately adjacent to the
  34. * point in the increasing <code>X</code> direction is
  35. * entirely inside the boundary <i>or</i>
  36. * <li>
  37. * it lies exactly on a horizontal boundary segment <b>and</b> the
  38. * space immediately adjacent to the point in the
  39. * increasing <code>Y</code> direction is inside the boundary.
  40. * </ul>
  41. *
  42. * @see java.awt.geom.PathIterator
  43. * @see java.awt.geom.AffineTransform
  44. * @see java.awt.geom.FlatteningPathIterator
  45. * @see java.awt.geom.GeneralPath
  46. *
  47. * @version 1.19 06/24/98
  48. * @author Jim Graham
  49. */
  50. public interface Shape {
  51. /**
  52. * Returns an integer {@link Rectangle} that completely encloses the
  53. * <code>Shape</code>. Note that there is no guarantee that the
  54. * returned <code>Rectangle</code> is the smallest bounding box that
  55. * encloses the <code>Shape</code>, only that the <code>Shape</code>
  56. * lies entirely within the indicated <code>Rectangle</code>. The
  57. * returned <code>Rectangle</code> might also fail to completely
  58. * enclose the <code>Shape</code> if the <code>Shape</code> overflows
  59. * the limited range of the integer data type. The
  60. * <code>getBounds2D</code> method generally returns a
  61. * tighter bounding box due to its greater flexibility in
  62. * representation.
  63. * @return an integer <code>Rectangle</code> that completely encloses
  64. * the <code>Shape</code>.
  65. * @see #getBounds2D
  66. */
  67. public Rectangle getBounds();
  68. /**
  69. * Returns a high precision and more accurate bounding box of
  70. * the <code>Shape</code> than the <code>getBounds</code> method.
  71. * Note that there is no guarantee that the returned
  72. * {@link Rectangle2D} is the smallest bounding box that encloses
  73. * the <code>Shape</code>, only that the <code>Shape</code> lies
  74. * entirely within the indicated <code>Rectangle2D</code>. The
  75. * bounding box returned by this method is usually tighter than that
  76. * returned by the <code>getBounds</code> method and never fails due
  77. * to overflow problems since the return value can be an instance of
  78. * the <code>Rectangle2D</code> that uses double precision values to
  79. * store the dimensions.
  80. * @return an instance of <code>Rectangle2D</code> that is a
  81. * high-precision bounding box of the <code>Shape</code>.
  82. * @see #getBounds
  83. */
  84. public Rectangle2D getBounds2D();
  85. /**
  86. * Tests if the specified coordinates are inside the boundary of the
  87. * <code>Shape</code>.
  88. * @param x, y the specified coordinates
  89. * @return <code>true</code> if the specified coordinates are inside
  90. * the <code>Shape</code> boundary; <code>false</code>
  91. * otherwise.
  92. */
  93. public boolean contains(double x, double y);
  94. /**
  95. * Tests if a specified {@link Point2D} is inside the boundary
  96. * of the <code>Shape</code>.
  97. * @param p a specified <code>Point2D</code>
  98. * @return <code>true</code> if the specified <code>Point2D</code> is
  99. * inside the boundary of the <code>Shape</code>
  100. * <code>false</code> otherwise.
  101. */
  102. public boolean contains(Point2D p);
  103. /**
  104. * Tests if the interior of the <code>Shape</code> intersects the
  105. * interior of a specified rectangular area.
  106. * The rectangular area is considered to intersect the <code>Shape</code>
  107. * if any point is contained in both the interior of the
  108. * <code>Shape</code> and the specified rectangular area.
  109. * <p>
  110. * This method might conservatively return <code>true</code> when:
  111. * <ul>
  112. * <li>
  113. * there is a high probability that the rectangular area and the
  114. * <code>Shape</code> intersect, but
  115. * <li>
  116. * the calculations to accurately determine this intersection
  117. * are prohibitively expensive.
  118. * </ul>
  119. * This means that this method might return <code>true</code> even
  120. * though the rectangular area does not intersect the <code>Shape</code>.
  121. * The {@link java.awt.geom.Area Area} class can be used to perform
  122. * more accurate computations of geometric intersection for any
  123. * <code>Shape</code> object if a more precise answer is required.
  124. * @param x, y the coordinates of the specified rectangular area
  125. * @param w the width of the specified rectangular area
  126. * @param h the height of the specified rectangular area
  127. * @return <code>true</code> if the interior of the <code>Shape</code> and
  128. * the interior of the rectangular area intersect, or are
  129. * both highly likely to intersect and intersection calculations
  130. * would be too expensive to perform; <code>false</code> otherwise.
  131. * @see java.awt.geom.Area
  132. */
  133. public boolean intersects(double x, double y, double w, double h);
  134. /**
  135. * Tests if the interior of the <code>Shape</code> intersects the
  136. * interior of a specified <code>Rectangle2D</code>.
  137. * This method might conservatively return <code>true</code> when:
  138. * <ul>
  139. * <li>
  140. * there is a high probability that the <code>Rectangle2D</code> and the
  141. * <code>Shape</code> intersect, but
  142. * <li>
  143. * the calculations to accurately determine this intersection
  144. * are prohibitively expensive.
  145. * </ul>
  146. * This means that this method might return <code>true</code> even
  147. * though the <code>Rectangle2D</code> does not intersect the
  148. * <code>Shape</code>.
  149. * @param r the specified <code>Rectangle2D</code>
  150. * @return <code>true</code> if the interior of the <code>Shape</code> and
  151. * the interior of the specified <code>Rectangle2D</code>
  152. * intersect, or are both highly likely to intersect and intersection
  153. * calculations would be too expensive to perform; <code>false</code>
  154. * otherwise.
  155. * @see #intersects(double, double, double, double)
  156. */
  157. public boolean intersects(Rectangle2D r);
  158. /**
  159. * Tests if the interior of the <code>Shape</code> entirely contains
  160. * the specified rectangular area. All coordinates that lie inside
  161. * the rectangular area must lie within the <code>Shape</code> for the
  162. * entire rectanglar area to be considered contained within the
  163. * <code>Shape</code>.
  164. * <p>
  165. * This method might conservatively return <code>false</code> when:
  166. * <ul>
  167. * <li>
  168. * the <code>intersect</code> method returns <code>true</code> and
  169. * <li>
  170. * the calculations to determine whether or not the
  171. * <code>Shape</code> entirely contains the rectangular area are
  172. * prohibitively expensive.
  173. * </ul>
  174. * This means that this method might return <code>false</code> even
  175. * though the <code>Shape</code> contains the rectangular area.
  176. * The <code>Area</code> class can be used to perform more accurate
  177. * computations of geometric intersection for any <code>Shape</code>
  178. * object if a more precise answer is required.
  179. * @param x, y the coordinates of the specified rectangular area
  180. * @param w the width of the specified rectangular area
  181. * @param h the height of the specified rectangular area
  182. * @return <code>true</code> if the interior of the <code>Shape</code>
  183. * entirely contains the specified rectangular area;
  184. * <code>false</code> otherwise or, if the <code>Shape</code>
  185. * contains the rectangular area and the
  186. * <code>intersects</code> method returns <code>true</code>
  187. * and the containment calculations would be too expensive to
  188. * perform.
  189. * @see java.awt.geom.Area
  190. * @see #intersects
  191. */
  192. public boolean contains(double x, double y, double w, double h);
  193. /**
  194. * Tests if the interior of the <code>Shape</code> entirely contains the
  195. * specified <code>Rectangle2D</code>.
  196. * This method might conservatively return <code>false</code> when:
  197. * <ul>
  198. * <li>
  199. * the <code>intersect</code> method returns <code>true</code> and
  200. * <li>
  201. * the calculations to determine whether or not the
  202. * <code>Shape</code> entirely contains the <code>Rectangle2D</code>
  203. * are prohibitively expensive.
  204. * </ul>
  205. * This means that this method might return <code>false</code> even
  206. * though the <code>Shape</code> contains the
  207. * <code>Rectangle2D</code>.
  208. * The <code>Area</code> class can be used to perform more accurate
  209. * computations of geometric intersection for any <code>Shape</code>
  210. * object if a more precise answer is required.
  211. * @param r The specified <code>Rectangle2D</code>
  212. * @return <code>true</code> if the interior of the <code>Shape</code>
  213. * entirely contains the <code>Rectangle2D</code>
  214. * <code>false</code> otherwise or, if the <code>Shape</code>
  215. * contains the <code>Rectangle2D</code> and the
  216. * <code>intersects</code> method returns <code>true</code>
  217. * and the containment calculations would be too expensive to
  218. * perform.
  219. * @see #contains(double, double, double, double)
  220. */
  221. public boolean contains(Rectangle2D r);
  222. /**
  223. * Returns an iterator object that iterates along the
  224. * <code>Shape</code> boundary and provides access to the geometry of the
  225. * <code>Shape</code> outline. If an optional {@link AffineTransform}
  226. * is specified, the coordinates returned in the iteration are
  227. * transformed accordingly.
  228. * <p>
  229. * Each call to this method returns a fresh <code>PathIterator</code>
  230. * object that traverses the geometry of the <code>Shape</code> object
  231. * independently from any other <code>PathIterator</code> objects in use
  232. * at the same time.
  233. * <p>
  234. * It is recommended, but not guaranteed, that objects
  235. * implementing the <code>Shape</code> interface isolate iterations
  236. * that are in process from any changes that might occur to the original
  237. * object's geometry during such iterations.
  238. * <p>
  239. * Before using a particular implementation of the <code>Shape</code>
  240. * interface in more than one thread simultaneously, refer to its
  241. * documentation to verify that it guarantees that iterations are isolated
  242. * from modifications.
  243. * @param at an optional <code>AffineTransform</code> to be applied to the
  244. * coordinates as they are returned in the iteration, or
  245. * <code>null</code> if untransformed coordinates are desired
  246. * @return a new <code>PathIterator</code> object, which independently
  247. * traverses the geometry of the <code>Shape</code>.
  248. */
  249. public PathIterator getPathIterator(AffineTransform at);
  250. /**
  251. * Returns an iterator object that iterates along the <code>Shape</code>
  252. * boundary and provides access to a flattened view of the
  253. * <code>Shape</code> outline geometry.
  254. * <p>
  255. * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are
  256. * returned by the iterator.
  257. * <p>
  258. * If an optional <code>AffineTransform</code> is specified,
  259. * the coordinates returned in the iteration are transformed
  260. * accordingly.
  261. * <p>
  262. * The amount of subdivision of the curved segments is controlled
  263. * by the <code>flatness</code> parameter, which specifies the
  264. * maximum distance that any point on the unflattened transformed
  265. * curve can deviate from the returned flattened path segments.
  266. * Note that a limit on the accuracy of the flattened path might be
  267. * silently imposed, causing very small flattening parameters to be
  268. * treated as larger values. This limit, if there is one, is
  269. * defined by the particular implementation that is used.
  270. * <p>
  271. * Each call to this method returns a fresh <code>PathIterator</code>
  272. * object that traverses the <code>Shape</code> object geometry
  273. * independently from any other <code>PathIterator</code> objects in use at
  274. * the same time.
  275. * <p>
  276. * It is recommended, but not guaranteed, that objects
  277. * implementing the <code>Shape</code> interface isolate iterations
  278. * that are in process from any changes that might occur to the original
  279. * object's geometry during such iterations.
  280. * <p>
  281. * Before using a particular implementation of this interface in more
  282. * than one thread simultaneously, refer to its documentation to
  283. * verify that it guarantees that iterations are isolated from
  284. * modifications.
  285. * @param at an optional <code>AffineTransform</code> to be applied to the
  286. * coordinates as they are returned in the iteration, or
  287. * <code>null</code> if untransformed coordinates are desired
  288. * @param flatness the maximum distance that the line segments used to
  289. * approximate the curved segments are allowed to deviate
  290. * from any point on the original curve
  291. * @return a new <code>PathIterator</code> that independently traverses
  292. * the <code>Shape</code> geometry.
  293. */
  294. public PathIterator getPathIterator(AffineTransform at, double flatness);
  295. }