Shape.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* Shape.java -- the classic Object-Oriented shape interface
  2. Copyright (C) 1999, 2002 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt;
  32. import java.awt.geom.AffineTransform;
  33. import java.awt.geom.PathIterator;
  34. import java.awt.geom.Point2D;
  35. import java.awt.geom.Rectangle2D;
  36. /**
  37. * This interface represents an abstract shape. The shape is described by
  38. * a {@link PathIterator}, and has callbacks for determining bounding box,
  39. * where points and rectangles lie in relation to the shape, and tracing
  40. * the trajectory.
  41. *
  42. * <p>A point is inside if it is completely inside, or on the boundary and
  43. * adjacent points in the increasing x or y direction are completely inside.
  44. * Unclosed shapes are considered as implicitly closed when performing
  45. * <code>contains</code> or <code>intersects</code>.
  46. *
  47. * @author Aaron M. Renn <arenn@urbanophile.com>
  48. * @see PathIterator
  49. * @see AffineTransform
  50. * @see FlatteningPathIterator
  51. * @see GeneralPath
  52. * @since 1.0
  53. * @status updated to 1.4
  54. */
  55. public interface Shape
  56. {
  57. /**
  58. * Returns a <code>Rectange</code> that bounds the shape. There is no
  59. * guarantee that this is the minimum bounding box, particularly if
  60. * the shape overflows the finite integer range of a bound. Generally,
  61. * <code>getBounds2D</code> returns a tighter bound.
  62. *
  63. * @return the shape's bounding box
  64. * @see #getBounds2D()
  65. */
  66. Rectangle getBounds();
  67. /**
  68. * Returns a high precision bounding box of the shape. There is no guarantee
  69. * that this is the minimum bounding box, but at least it never overflows.
  70. *
  71. * @return the shape's bounding box
  72. * @see #getBounds()
  73. * @since 1.2
  74. */
  75. Rectangle2D getBounds2D();
  76. /**
  77. * Test if the coordinates lie in the shape.
  78. *
  79. * @param x the x coordinate
  80. * @param y the y coordinate
  81. * @return true if (x,y) lies inside the shape
  82. * @since 1.2
  83. */
  84. boolean contains(double x, double y);
  85. /**
  86. * Test if the point lie in the shape.
  87. *
  88. * @param p the high-precision point
  89. * @return true if p lies inside the shape
  90. * @throws NullPointerException if p is null
  91. * @since 1.2
  92. */
  93. boolean contains(Point2D p);
  94. /**
  95. * Test if a high-precision rectangle intersects the shape. This is true
  96. * if any point in the rectangle is in the shape, with the caveat that the
  97. * operation may include high probability estimates when the actual
  98. * calculation is prohibitively expensive. The {@link Area} class can
  99. * be used for more precise answers.
  100. *
  101. * @param x the x coordinate of the rectangle
  102. * @param y the y coordinate of the rectangle
  103. * @param w the width of the rectangle, undefined results if negative
  104. * @param h the height of the rectangle, undefined results if negative
  105. * @return true if the rectangle intersects this shape
  106. * @see Area
  107. * @since 1.2
  108. */
  109. boolean intersects(double x, double y, double w, double h);
  110. /**
  111. * Test if a high-precision rectangle intersects the shape. This is true
  112. * if any point in the rectangle is in the shape, with the caveat that the
  113. * operation may include high probability estimates when the actual
  114. * calculation is prohibitively expensive. The {@link Area} class can
  115. * be used for more precise answers.
  116. *
  117. * @param r the rectangle
  118. * @return true if the rectangle intersects this shape
  119. * @throws NullPointerException if r is null
  120. * @see #intersects(double, double, double, double)
  121. * @since 1.2
  122. */
  123. boolean intersects(Rectangle2D r);
  124. /**
  125. * Test if a high-precision rectangle lies completely in the shape. This is
  126. * true if all points in the rectangle are in the shape, with the caveat
  127. * that the operation may include high probability estimates when the actual
  128. * calculation is prohibitively expensive. The {@link Area} class can
  129. * be used for more precise answers.
  130. *
  131. * @param x the x coordinate of the rectangle
  132. * @param y the y coordinate of the rectangle
  133. * @param w the width of the rectangle, undefined results if negative
  134. * @param h the height of the rectangle, undefined results if negative
  135. * @return true if the rectangle is contained in this shape
  136. * @see Area
  137. * @since 1.2
  138. */
  139. boolean contains(double x, double y, double w, double h);
  140. /**
  141. * Test if a high-precision rectangle lies completely in the shape. This is
  142. * true if all points in the rectangle are in the shape, with the caveat
  143. * that the operation may include high probability estimates when the actual
  144. * calculation is prohibitively expensive. The {@link Area} class can
  145. * be used for more precise answers.
  146. *
  147. * @param r the rectangle
  148. * @return true if the rectangle is contained in this shape
  149. * @throws NullPointerException if r is null
  150. * @see #contains(double, double, double, double)
  151. * @since 1.2
  152. */
  153. boolean contains(Rectangle2D r);
  154. /**
  155. * Return an iterator along the shape boundary. If the optional transform
  156. * is provided, the iterator is transformed accordingly. Each call returns
  157. * a new object, independent from others in use. It is recommended, but
  158. * not required, that the Shape isolate iterations from future changes to
  159. * the boundary, and document this fact.
  160. *
  161. * @param transform an optional transform to apply to the iterator
  162. * @return a new iterator over the boundary
  163. * @since 1.2
  164. */
  165. PathIterator getPathIterator(AffineTransform transform);
  166. /**
  167. * Return an iterator along the flattened version of the shape boundary.
  168. * Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE points are returned in the
  169. * iterator. The flatness paramter controls how far points are allowed to
  170. * differ from the real curve; although a limit on accuracy may cause this
  171. * parameter to be enlarged if needed.
  172. *
  173. * <p>If the optional transform is provided, the iterator is transformed
  174. * accordingly. Each call returns a new object, independent from others in
  175. * use. It is recommended, but not required, that the Shape isolate
  176. * iterations from future changes to the boundary, and document this fact.
  177. *
  178. * @param transform an optional transform to apply to the iterator
  179. * @param double the maximum distance for deviation from the real boundary
  180. * @return a new iterator over the boundary
  181. * @since 1.2
  182. */
  183. PathIterator getPathIterator(AffineTransform transform, double flatness);
  184. } // interface Shape