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