PathIterator.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* PathIterator.java -- describes a shape by iterating over its vertices
  2. Copyright (C) 2000, 2002 Free Software Foundation
  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.geom;
  32. /**
  33. * This interface provides a directed path over the boundary of a shape. The
  34. * path can contain 1st through 3rd order Bezier curves (lines, and quadratic
  35. * and cubic splines). A shape can have multiple disjoint paths via the
  36. * MOVETO directive, and can close a circular path back to the previos
  37. * MOVETO via the CLOSE directive.
  38. *
  39. * @author Tom Tromey <tromey@cygnus.com>
  40. * @author Eric Blake <ebb9@email.byu.edu>
  41. * @see Shape
  42. * @see Stroke
  43. * @see FlatteningPathIterator
  44. * @since 1.2
  45. * @status updated to 1.4
  46. */
  47. public interface PathIterator
  48. {
  49. /**
  50. * The even-odd winding mode: a point is internal to the shape if a ray
  51. * from the point to infinity (in any direction) crosses an odd number of
  52. * segments.
  53. */
  54. static final int WIND_EVEN_ODD = 0;
  55. /**
  56. * The non-zero winding mode: a point is internal to the shape if a ray
  57. * from the point to infinity (in any direction) crosses a different number
  58. * of segments headed clockwise than those headed counterclockwise.
  59. */
  60. static final int WIND_NON_ZERO = 1;
  61. /**
  62. * Starts a new subpath. There is no segment from the previous vertex.
  63. */
  64. static final int SEG_MOVETO = 0;
  65. /**
  66. * The current segment is a line.
  67. */
  68. static final int SEG_LINETO = 1;
  69. /**
  70. * The current segment is a quadratic parametric curve. It is interpolated
  71. * as t varies from 0 to 1 over the current point (CP), first control point
  72. * (P1), and final interpolated control point (P2):
  73. * <pre>
  74. * P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2
  75. * 0 &lt;= t &lt;= 1
  76. * B(n,m) = mth coefficient of nth degree Bernstein polynomial
  77. * = C(n,m) * t^(m) * (1 - t)^(n-m)
  78. * C(n,m) = Combinations of n things, taken m at a time
  79. * = n! / (m! * (n-m)!)
  80. * </pre>
  81. */
  82. static final int SEG_QUADTO = 2;
  83. /**
  84. * The current segment is a cubic parametric curve (more commonly known as
  85. * a Bezier curve). It is interpolated as t varies from 0 to 1 over the
  86. * current point (CP), first control point (P1), the second control point
  87. * (P2), and final interpolated control point (P3):
  88. * <pre>
  89. * P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3
  90. * 0 &lt;= t &lt;= 1
  91. * B(n,m) = mth coefficient of nth degree Bernstein polynomial
  92. * = C(n,m) * t^(m) * (1 - t)^(n-m)
  93. * C(n,m) = Combinations of n things, taken m at a time
  94. * = n! / (m! * (n-m)!)
  95. * </pre>
  96. */
  97. static final int SEG_CUBICTO = 3;
  98. /**
  99. * The current segment closes a loop by an implicit line to the previous
  100. * SEG_MOVETO coordinate.
  101. */
  102. static final int SEG_CLOSE = 4;
  103. /**
  104. * Returns the winding rule to determine which points are inside this path.
  105. *
  106. * @return the winding rule
  107. * @see #WIND_EVEN_ODD
  108. * @see #WIND_NON_ZERO
  109. */
  110. int getWindingRule();
  111. /**
  112. * Tests if the iterator is exhausted. If this returns false, currentSegment
  113. * and next may throw a NoSuchElementException (although this is not
  114. * required).
  115. *
  116. * @return true if the iteration is complete
  117. */
  118. boolean isDone();
  119. /**
  120. * Advance to the next segment in the iteration. It is not specified what
  121. * this does if called when isDone() returns false.
  122. *
  123. * @throws java.util.NoSuchElementException optional when isDone() is true
  124. */
  125. void next();
  126. /**
  127. * Returns the coordinates of the next point(s), as well as the type of
  128. * line segment. The input array must be at least a float[6], to accomodate
  129. * up to three (x,y) point pairs (although if you know the iterator is
  130. * flat, you can probably get by with a float[2]). If the returned type is
  131. * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if
  132. * the returned type is SEG_QUADTO, the first two points are modified; if
  133. * the returned type is SEG_CUBICTO, all three points are modified; and if
  134. * the returned type is SEG_CLOSE, the array is untouched.
  135. *
  136. * @param coords the array to place the point coordinates in
  137. * @return the segment type
  138. * @throws NullPointerException if coords is null
  139. * @throws ArrayIndexOutOfBoundsException if coords is too small
  140. * @throws java.util.NoSuchElementException optional when isDone() is true
  141. * @see #SEG_MOVETO
  142. * @see #SEG_LINETO
  143. * @see #SEG_QUADTO
  144. * @see #SEG_CUBICTO
  145. * @see #SEG_CLOSE
  146. */
  147. int currentSegment(float[] coords);
  148. /**
  149. * Returns the coordinates of the next point(s), as well as the type of
  150. * line segment. The input array must be at least a double[6], to accomodate
  151. * up to three (x,y) point pairs (although if you know the iterator is
  152. * flat, you can probably get by with a double[2]). If the returned type is
  153. * SEG_MOVETO or SEG_LINETO, the first point in the array is modified; if
  154. * the returned type is SEG_QUADTO, the first two points are modified; if
  155. * the returned type is SEG_CUBICTO, all three points are modified; and if
  156. * the returned type is SEG_CLOSE, the array is untouched.
  157. *
  158. * @param coords the array to place the point coordinates in
  159. * @return the segment type
  160. * @throws NullPointerException if coords is null
  161. * @throws ArrayIndexOutOfBoundsException if coords is too small
  162. * @throws java.util.NoSuchElementException optional when isDone() is true
  163. * @see #SEG_MOVETO
  164. * @see #SEG_LINETO
  165. * @see #SEG_QUADTO
  166. * @see #SEG_CUBICTO
  167. * @see #SEG_CLOSE
  168. */
  169. int currentSegment(double[] coords);
  170. } // interface PathIterator