1. /*
  2. * @(#)PathIterator.java 1.12 00/02/02
  3. *
  4. * Copyright 1997-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.geom;
  11. /**
  12. * The <code>PathIterator</code> interface provides the mechanism
  13. * for objects that implement the {@link java.awt.Shape Shape}
  14. * interface to return the geometry of their boundary by allowing
  15. * a caller to retrieve the path of that boundary a segment at a
  16. * time. This interface allows these objects to retrieve the path of
  17. * their boundary a segment at a time by using 1st through 3rd order
  18. * Bézier curves, which are lines and quadratic or cubic
  19. * Bézier splines.
  20. * <p>
  21. * Multiple subpaths can be expressed by using a "MOVETO" segment to
  22. * create a discontinuity in the geometry to move from the end of
  23. * one subpath to the beginning of the next.
  24. * <p>
  25. * Each subpath can be closed manually by ending the last segment in
  26. * the subpath on the same coordinate as the beginning "MOVETO" segment
  27. * for that subpath or by using a "CLOSE" segment to append a line
  28. * segment from the last point back to the first.
  29. * Be aware that manually closing an outline as opposed to using a
  30. * "CLOSE" segment to close the path might result in different line
  31. * style decorations being used at the end points of the subpath.
  32. * For example, the {@link java.awt.BasicStroke BasicStroke} object
  33. * uses a line "JOIN" decoration to connect the first and last points
  34. * if a "CLOSE" segment is encountered, whereas simply ending the path
  35. * on the same coordinate as the beginning coordinate results in line
  36. * "CAP" decorations being used at the ends.
  37. *
  38. * @see java.awt.Shape
  39. * @see java.awt.BasicStroke
  40. *
  41. * @version 1.12, 02/02/00
  42. * @author Jim Graham
  43. */
  44. public interface PathIterator {
  45. /**
  46. * The winding rule constant for specifying an even-odd rule
  47. * for determining the interior of a path.
  48. * The even-odd rule specifies that a point lies inside the
  49. * path if a ray drawn in any direction from that point to
  50. * infinity is crossed by path segments an odd number of times.
  51. */
  52. public static final int WIND_EVEN_ODD = 0;
  53. /**
  54. * The winding rule constant for specifying a non-zero rule
  55. * for determining the interior of a path.
  56. * The non-zero rule specifies that a point lies inside the
  57. * path if a ray drawn in any direction from that point to
  58. * infinity is crossed by path segments a different number
  59. * of times in the counter-clockwise direction than the
  60. * clockwise direction.
  61. */
  62. public static final int WIND_NON_ZERO = 1;
  63. /**
  64. * The segment type constant for a point that specifies the
  65. * starting location for a new subpath.
  66. */
  67. public static final int SEG_MOVETO = 0;
  68. /**
  69. * The segment type constant for a point that specifies the
  70. * end point of a line to be drawn from the most recently
  71. * specified point.
  72. */
  73. public static final int SEG_LINETO = 1;
  74. /**
  75. * The segment type constant for the pair of points that specify
  76. * a quadratic parametric curve to be drawn from the most recently
  77. * specified point.
  78. * The curve is interpolated by solving the parametric control
  79. * equation in the range <code>(t=[0..1])</code> using
  80. * the most recently specified (current) point (CP),
  81. * the first control point (P1),
  82. * and the final interpolated control point (P2).
  83. * The parametric control equation for this curve is:
  84. * <pre>
  85. * P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2
  86. * 0 <= t <= 1
  87. *
  88. * B(n,m) = mth coefficient of nth degree Bernstein polynomial
  89. * = C(n,m) * t^(m) * (1 - t)^(n-m)
  90. * C(n,m) = Combinations of n things, taken m at a time
  91. * = n! / (m! * (n-m)!)
  92. * </pre>
  93. */
  94. public static final int SEG_QUADTO = 2;
  95. /**
  96. * The segment type constant for the set of 3 points that specify
  97. * a cubic parametric curve to be drawn from the most recently
  98. * specified point.
  99. * The curve is interpolated by solving the parametric control
  100. * equation in the range <code>(t=[0..1])</code> using
  101. * the most recently specified (current) point (CP),
  102. * the first control point (P1),
  103. * the second control point (P2),
  104. * and the final interpolated control point (P3).
  105. * The parametric control equation for this curve is:
  106. * <pre>
  107. * P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3
  108. * 0 <= t <= 1
  109. *
  110. * B(n,m) = mth coefficient of nth degree Bernstein polynomial
  111. * = C(n,m) * t^(m) * (1 - t)^(n-m)
  112. * C(n,m) = Combinations of n things, taken m at a time
  113. * = n! / (m! * (n-m)!)
  114. * </pre>
  115. * This form of curve is commonly known as a Bézier curve.
  116. */
  117. public static final int SEG_CUBICTO = 3;
  118. /**
  119. * The segment type constant that specifies that
  120. * the preceding subpath should be closed by appending a line segment
  121. * back to the point corresponding to the most recent SEG_MOVETO.
  122. */
  123. public static final int SEG_CLOSE = 4;
  124. /**
  125. * Returns the winding rule for determining the interior of the
  126. * path.
  127. * @return the winding rule.
  128. * @see #WIND_EVEN_ODD
  129. * @see #WIND_NON_ZERO
  130. */
  131. public int getWindingRule();
  132. /**
  133. * Tests if the iteration is complete.
  134. * @return <code>true</code> if all the segments have
  135. * been read; <code>false</code> otherwise.
  136. */
  137. public boolean isDone();
  138. /**
  139. * Moves the iterator to the next segment of the path forwards
  140. * along the primary direction of traversal as long as there are
  141. * more points in that direction.
  142. */
  143. public void next();
  144. /**
  145. * Returns the coordinates and type of the current path segment in
  146. * the iteration.
  147. * The return value is the path segment type:
  148. * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
  149. * A float array of length 6 must be passed in and can be used to
  150. * store the coordinates of the point(s).
  151. * Each point is stored as a pair of float x,y coordinates.
  152. * SEG_MOVETO and SEG_LINETO types returns one point,
  153. * SEG_QUADTO returns two points,
  154. * SEG_CUBICTO returns 3 points
  155. * and SEG_CLOSE does not return any points.
  156. * @param coords an array that holds the data returned from
  157. * this method
  158. * @return the path segment type of the current path segment.
  159. * @see #SEG_MOVETO
  160. * @see #SEG_LINETO
  161. * @see #SEG_QUADTO
  162. * @see #SEG_CUBICTO
  163. * @see #SEG_CLOSE
  164. */
  165. public int currentSegment(float[] coords);
  166. /**
  167. * Returns the coordinates and type of the current path segment in
  168. * the iteration.
  169. * The return value is the path segment type:
  170. * SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE.
  171. * A double array of length 6 must be passed in and can be used to
  172. * store the coordinates of the point(s).
  173. * Each point is stored as a pair of double x,y coordinates.
  174. * SEG_MOVETO and SEG_LINETO types returns one point,
  175. * SEG_QUADTO returns two points,
  176. * SEG_CUBICTO returns 3 points
  177. * and SEG_CLOSE does not return any points.
  178. * @param coords an array that holds the data returned from
  179. * this method
  180. * @see #SEG_MOVETO
  181. * @see #SEG_LINETO
  182. * @see #SEG_QUADTO
  183. * @see #SEG_CUBICTO
  184. * @see #SEG_CLOSE
  185. */
  186. public int currentSegment(double[] coords);
  187. }