1. /*
  2. * @(#)Polygon.java 1.52 04/05/18
  3. *
  4. * Copyright 2004 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. import sun.awt.geom.Crossings;
  13. /**
  14. * The <code>Polygon</code> class encapsulates a description of a
  15. * closed, two-dimensional region within a coordinate space. This
  16. * region is bounded by an arbitrary number of line segments, each of
  17. * which is one side of the polygon. Internally, a polygon
  18. * comprises of a list of (<i>x</i>, <i>y</i>)
  19. * coordinate pairs, where each pair defines a <i>vertex</i> of the
  20. * polygon, and two successive pairs are the endpoints of a
  21. * line that is a side of the polygon. The first and final
  22. * pairs of (<i>x</i>, <i>y</i>) points are joined by a line segment
  23. * that closes the polygon. This <code>Polygon</code> is defined with
  24. * an even-odd winding rule. See
  25. * {@link java.awt.geom.PathIterator#WIND_EVEN_ODD WIND_EVEN_ODD}
  26. * for a definition of the even-odd winding rule.
  27. * This class's hit-testing methods, which include the
  28. * <code>contains</code>, <code>intersects</code> and <code>inside</code>
  29. * methods, use the <i>insideness</i> definition described in the
  30. * {@link Shape} class comments.
  31. *
  32. * @version 1.26, 07/24/98
  33. * @author Sami Shaio
  34. * @see Shape
  35. * @author Herb Jellinek
  36. * @since JDK1.0
  37. */
  38. public class Polygon implements Shape, java.io.Serializable {
  39. /**
  40. * The total number of points. The value of <code>npoints</code>
  41. * represents the number of valid points in this <code>Polygon</code>
  42. * and might be less than the number of elements in
  43. * {@link #xpoints xpoints} or {@link #ypoints ypoints}.
  44. * This value can be NULL.
  45. *
  46. * @serial
  47. * @see #addPoint(int, int)
  48. */
  49. public int npoints;
  50. /**
  51. * The array of <i>x</i> coordinates. The number of elements in
  52. * this array might be more than the number of <i>x</i> coordinates
  53. * in this <code>Polygon</code>. The extra elements allow new points
  54. * to be added to this <code>Polygon</code> without re-creating this
  55. * array. The value of {@link #npoints npoints} is equal to the
  56. * number of valid points in this <code>Polygon</code>.
  57. *
  58. * @serial
  59. * @see #addPoint(int, int)
  60. */
  61. public int xpoints[];
  62. /**
  63. * The array of <i>y</i> coordinates. The number of elements in
  64. * this array might be more than the number of <i>y</i> coordinates
  65. * in this <code>Polygon</code>. The extra elements allow new points
  66. * to be added to this <code>Polygon</code> without re-creating this
  67. * array. The value of <code>npoints</code> is equal to the
  68. * number of valid points in this <code>Polygon</code>.
  69. *
  70. * @serial
  71. * @see #addPoint(int, int)
  72. */
  73. public int ypoints[];
  74. /**
  75. * Bounds of the polygon.
  76. * This value can be NULL.
  77. * Please see the javadoc comments getBounds().
  78. *
  79. * @serial
  80. * @see #getBoundingBox()
  81. * @see #getBounds()
  82. */
  83. protected Rectangle bounds;
  84. /*
  85. * JDK 1.1 serialVersionUID
  86. */
  87. private static final long serialVersionUID = -6460061437900069969L;
  88. /**
  89. * Creates an empty polygon.
  90. */
  91. public Polygon() {
  92. xpoints = new int[4];
  93. ypoints = new int[4];
  94. }
  95. /**
  96. * Constructs and initializes a <code>Polygon</code> from the specified
  97. * parameters.
  98. * @param xpoints an array of <i>x</i> coordinates
  99. * @param ypoints an array of <i>y</i> coordinates
  100. * @param npoints the total number of points in the
  101. * <code>Polygon</code>
  102. * @exception NegativeArraySizeException if the value of
  103. * <code>npoints</code> is negative.
  104. * @exception IndexOutOfBoundsException if <code>npoints</code> is
  105. * greater than the length of <code>xpoints</code>
  106. * or the length of <code>ypoints</code>.
  107. * @exception NullPointerException if <code>xpoints</code> or
  108. * <code>ypoints</code> is <code>null</code>.
  109. */
  110. public Polygon(int xpoints[], int ypoints[], int npoints) {
  111. // Fix 4489009: should throw IndexOutofBoundsException instead
  112. // of OutofMemoryException if npoints is huge and > {x,y}points.length
  113. if (npoints > xpoints.length || npoints > ypoints.length) {
  114. throw new IndexOutOfBoundsException("npoints > xpoints.length || npoints > ypoints.length");
  115. }
  116. this.npoints = npoints;
  117. this.xpoints = new int[npoints];
  118. this.ypoints = new int[npoints];
  119. System.arraycopy(xpoints, 0, this.xpoints, 0, npoints);
  120. System.arraycopy(ypoints, 0, this.ypoints, 0, npoints);
  121. }
  122. /**
  123. * Resets this <code>Polygon</code> object to an empty polygon.
  124. * The coordinate arrays and the data in them are left untouched
  125. * but the number of points is reset to zero to mark the old
  126. * vertex data as invalid and to start accumulating new vertex
  127. * data at the beginning.
  128. * All internally-cached data relating to the old vertices
  129. * are discarded.
  130. * Note that since the coordinate arrays from before the reset
  131. * are reused, creating a new empty <code>Polygon</code> might
  132. * be more memory efficient than resetting the current one if
  133. * the number of vertices in the new polygon data is significantly
  134. * smaller than the number of vertices in the data from before the
  135. * reset.
  136. * @see java.awt.Polygon#invalidate
  137. * @since 1.4
  138. */
  139. public void reset() {
  140. npoints = 0;
  141. bounds = null;
  142. }
  143. /**
  144. * Invalidates or flushes any internally-cached data that depends
  145. * on the vertex coordinates of this <code>Polygon</code>.
  146. * This method should be called after any direct manipulation
  147. * of the coordinates in the <code>xpoints</code> or
  148. * <code>ypoints</code> arrays to avoid inconsistent results
  149. * from methods such as <code>getBounds</code> or <code>contains</code>
  150. * that might cache data from earlier computations relating to
  151. * the vertex coordinates.
  152. * @see java.awt.Polygon#getBounds
  153. * @since 1.4
  154. */
  155. public void invalidate() {
  156. bounds = null;
  157. }
  158. /**
  159. * Translates the vertices of the <code>Polygon</code> by
  160. * <code>deltaX</code> along the x axis and by
  161. * <code>deltaY</code> along the y axis.
  162. * @param deltaX the amount to translate along the <i>x</i> axis
  163. * @param deltaY the amount to translate along the <i>y</i> axis
  164. * @since JDK1.1
  165. */
  166. public void translate(int deltaX, int deltaY) {
  167. for (int i = 0; i < npoints; i++) {
  168. xpoints[i] += deltaX;
  169. ypoints[i] += deltaY;
  170. }
  171. if (bounds != null) {
  172. bounds.translate(deltaX, deltaY);
  173. }
  174. }
  175. /*
  176. * Calculates the bounding box of the points passed to the constructor.
  177. * Sets <code>bounds</code> to the result.
  178. * @param xpoints[] array of <i>x</i> coordinates
  179. * @param ypoints[] array of <i>y</i> coordinates
  180. * @param npoints the total number of points
  181. */
  182. void calculateBounds(int xpoints[], int ypoints[], int npoints) {
  183. int boundsMinX = Integer.MAX_VALUE;
  184. int boundsMinY = Integer.MAX_VALUE;
  185. int boundsMaxX = Integer.MIN_VALUE;
  186. int boundsMaxY = Integer.MIN_VALUE;
  187. for (int i = 0; i < npoints; i++) {
  188. int x = xpoints[i];
  189. boundsMinX = Math.min(boundsMinX, x);
  190. boundsMaxX = Math.max(boundsMaxX, x);
  191. int y = ypoints[i];
  192. boundsMinY = Math.min(boundsMinY, y);
  193. boundsMaxY = Math.max(boundsMaxY, y);
  194. }
  195. bounds = new Rectangle(boundsMinX, boundsMinY,
  196. boundsMaxX - boundsMinX,
  197. boundsMaxY - boundsMinY);
  198. }
  199. /*
  200. * Resizes the bounding box to accomodate the specified coordinates.
  201. * @param x, y the specified coordinates
  202. */
  203. void updateBounds(int x, int y) {
  204. if (x < bounds.x) {
  205. bounds.width = bounds.width + (bounds.x - x);
  206. bounds.x = x;
  207. }
  208. else {
  209. bounds.width = Math.max(bounds.width, x - bounds.x);
  210. // bounds.x = bounds.x;
  211. }
  212. if (y < bounds.y) {
  213. bounds.height = bounds.height + (bounds.y - y);
  214. bounds.y = y;
  215. }
  216. else {
  217. bounds.height = Math.max(bounds.height, y - bounds.y);
  218. // bounds.y = bounds.y;
  219. }
  220. }
  221. /**
  222. * Appends the specified coordinates to this <code>Polygon</code>.
  223. * <p>
  224. * If an operation that calculates the bounding box of this
  225. * <code>Polygon</code> has already been performed, such as
  226. * <code>getBounds</code> or <code>contains</code>, then this
  227. * method updates the bounding box.
  228. * @param x the specified x coordinate
  229. * @param y the specified y coordinate
  230. * @see java.awt.Polygon#getBounds
  231. * @see java.awt.Polygon#contains
  232. */
  233. public void addPoint(int x, int y) {
  234. if (npoints == xpoints.length) {
  235. int tmp[];
  236. tmp = new int[npoints * 2];
  237. System.arraycopy(xpoints, 0, tmp, 0, npoints);
  238. xpoints = tmp;
  239. tmp = new int[npoints * 2];
  240. System.arraycopy(ypoints, 0, tmp, 0, npoints);
  241. ypoints = tmp;
  242. }
  243. xpoints[npoints] = x;
  244. ypoints[npoints] = y;
  245. npoints++;
  246. if (bounds != null) {
  247. updateBounds(x, y);
  248. }
  249. }
  250. /**
  251. * Gets the bounding box of this <code>Polygon</code>.
  252. * The bounding box is the smallest {@link Rectangle} whose
  253. * sides are parallel to the x and y axes of the
  254. * coordinate space, and can completely contain the <code>Polygon</code>.
  255. * @return a <code>Rectangle</code> that defines the bounds of this
  256. * <code>Polygon</code>.
  257. * @since JDK1.1
  258. */
  259. public Rectangle getBounds() {
  260. return getBoundingBox();
  261. }
  262. /**
  263. * Returns the bounds of this <code>Polygon</code>.
  264. * @return the bounds of this <code>Polygon</code>.
  265. * @deprecated As of JDK version 1.1,
  266. * replaced by <code>getBounds()</code>.
  267. */
  268. @Deprecated
  269. public Rectangle getBoundingBox() {
  270. if (npoints == 0) {
  271. return new Rectangle();
  272. }
  273. if (bounds == null) {
  274. calculateBounds(xpoints, ypoints, npoints);
  275. }
  276. return bounds.getBounds();
  277. }
  278. /**
  279. * Determines whether the specified {@link Point} is inside this
  280. * <code>Polygon</code>.
  281. * @param p the specified <code>Point</code> to be tested
  282. * @return <code>true</code> if the <code>Polygon</code> contains the
  283. * <code>Point</code> <code>false</code> otherwise.
  284. * @see #contains(double, double)
  285. */
  286. public boolean contains(Point p) {
  287. return contains(p.x, p.y);
  288. }
  289. /**
  290. * Determines whether the specified coordinates are inside this
  291. * <code>Polygon</code>.
  292. * <p>
  293. * @param x the specified x coordinate to be tested
  294. * @param y the specified y coordinate to be tested
  295. * @return <code>true</code> if this <code>Polygon</code> contains
  296. * the specified coordinates, (<i>x</i>, <i>y</i>);
  297. * <code>false</code> otherwise.
  298. * @see #contains(double, double)
  299. * @since JDK1.1
  300. */
  301. public boolean contains(int x, int y) {
  302. return contains((double) x, (double) y);
  303. }
  304. /**
  305. * Determines whether the specified coordinates are contained in this
  306. * <code>Polygon</code>.
  307. * @param x the specified x coordinate to be tested
  308. * @param y the specified y coordinate to be tested
  309. * @return <code>true</code> if this <code>Polygon</code> contains
  310. * the specified coordinates, (<i>x</i>, <i>y</i>);
  311. * <code>false</code> otherwise.
  312. * @see #contains(double, double)
  313. * @deprecated As of JDK version 1.1,
  314. * replaced by <code>contains(int, int)</code>.
  315. */
  316. @Deprecated
  317. public boolean inside(int x, int y) {
  318. return contains((double) x, (double) y);
  319. }
  320. /**
  321. * Returns the high precision bounding box of the {@link Shape}.
  322. * @return a {@link Rectangle2D} that precisely
  323. * bounds the <code>Shape</code>.
  324. */
  325. public Rectangle2D getBounds2D() {
  326. return getBounds();
  327. }
  328. /**
  329. * Determines if the specified coordinates are inside this
  330. * <code>Polygon</code>. For the definition of
  331. * <i>insideness</i>, see the class comments of {@link Shape}.
  332. * @param x the specified x coordinate
  333. * @param y the specified y coordinate
  334. * @return <code>true</code> if the <code>Polygon</code> contains the
  335. * specified coordinates; <code>false</code> otherwise.
  336. */
  337. public boolean contains(double x, double y) {
  338. if (npoints <= 2 || !getBoundingBox().contains(x, y)) {
  339. return false;
  340. }
  341. int hits = 0;
  342. int lastx = xpoints[npoints - 1];
  343. int lasty = ypoints[npoints - 1];
  344. int curx, cury;
  345. // Walk the edges of the polygon
  346. for (int i = 0; i < npoints; lastx = curx, lasty = cury, i++) {
  347. curx = xpoints[i];
  348. cury = ypoints[i];
  349. if (cury == lasty) {
  350. continue;
  351. }
  352. int leftx;
  353. if (curx < lastx) {
  354. if (x >= lastx) {
  355. continue;
  356. }
  357. leftx = curx;
  358. } else {
  359. if (x >= curx) {
  360. continue;
  361. }
  362. leftx = lastx;
  363. }
  364. double test1, test2;
  365. if (cury < lasty) {
  366. if (y < cury || y >= lasty) {
  367. continue;
  368. }
  369. if (x < leftx) {
  370. hits++;
  371. continue;
  372. }
  373. test1 = x - curx;
  374. test2 = y - cury;
  375. } else {
  376. if (y < lasty || y >= cury) {
  377. continue;
  378. }
  379. if (x < leftx) {
  380. hits++;
  381. continue;
  382. }
  383. test1 = x - lastx;
  384. test2 = y - lasty;
  385. }
  386. if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {
  387. hits++;
  388. }
  389. }
  390. return ((hits & 1) != 0);
  391. }
  392. private Crossings getCrossings(double xlo, double ylo,
  393. double xhi, double yhi)
  394. {
  395. Crossings cross = new Crossings.EvenOdd(xlo, ylo, xhi, yhi);
  396. int lastx = xpoints[npoints - 1];
  397. int lasty = ypoints[npoints - 1];
  398. int curx, cury;
  399. // Walk the edges of the polygon
  400. for (int i = 0; i < npoints; i++) {
  401. curx = xpoints[i];
  402. cury = ypoints[i];
  403. if (cross.accumulateLine(lastx, lasty, curx, cury)) {
  404. return null;
  405. }
  406. lastx = curx;
  407. lasty = cury;
  408. }
  409. return cross;
  410. }
  411. /**
  412. * Tests if a specified {@link Point2D} is inside the boundary of this
  413. * <code>Polygon</code>.
  414. * @param p a specified <code>Point2D</code>
  415. * @return <code>true</code> if this <code>Polygon</code> contains the
  416. * specified <code>Point2D</code> <code>false</code>
  417. * otherwise.
  418. * @see #contains(double, double)
  419. */
  420. public boolean contains(Point2D p) {
  421. return contains(p.getX(), p.getY());
  422. }
  423. /**
  424. * Tests if the interior of this <code>Polygon</code> intersects the
  425. * interior of a specified set of rectangular coordinates.
  426. * @param x the x coordinate of the specified rectangular
  427. * shape's top-left corner
  428. * @param y the y coordinate of the specified rectangular
  429. * shape's top-left corner
  430. * @param w the width of the specified rectangular shape
  431. * @param h the height of the specified rectangular shape
  432. * @return <code>true</code> if the interior of this
  433. * <code>Polygon</code> and the interior of the
  434. * specified set of rectangular
  435. * coordinates intersect each other;
  436. * <code>false</code> otherwise
  437. * @since 1.2
  438. */
  439. public boolean intersects(double x, double y, double w, double h) {
  440. if (npoints <= 0 || !getBoundingBox().intersects(x, y, w, h)) {
  441. return false;
  442. }
  443. Crossings cross = getCrossings(x, y, x+w, y+h);
  444. return (cross == null || !cross.isEmpty());
  445. }
  446. /**
  447. * Tests if the interior of this <code>Polygon</code> intersects the
  448. * interior of a specified <code>Rectangle2D</code>.
  449. * @param r a specified <code>Rectangle2D</code>
  450. * @return <code>true</code> if this <code>Polygon</code> and the
  451. * interior of the specified <code>Rectangle2D</code>
  452. * intersect each other; <code>false</code>
  453. * otherwise.
  454. */
  455. public boolean intersects(Rectangle2D r) {
  456. return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
  457. }
  458. /**
  459. * Tests if the interior of this <code>Polygon</code> entirely
  460. * contains the specified set of rectangular coordinates.
  461. * @param x the x coordinate of the top-left corner of the
  462. * specified set of rectangular coordinates
  463. * @param y the y coordinate of the top-left corner of the
  464. * specified set of rectangular coordinates
  465. * @param w the width of the set of rectangular coordinates
  466. * @param h the height of the set of rectangular coordinates
  467. * @return <code>true</code> if this <code>Polygon</code> entirely
  468. * contains the specified set of rectangular
  469. * coordinates; <code>false</code> otherwise
  470. * @since 1.2
  471. */
  472. public boolean contains(double x, double y, double w, double h) {
  473. if (npoints <= 0 || !getBoundingBox().intersects(x, y, w, h)) {
  474. return false;
  475. }
  476. Crossings cross = getCrossings(x, y, x+w, y+h);
  477. return (cross != null && cross.covers(y, y+h));
  478. }
  479. /**
  480. * Tests if the interior of this <code>Polygon</code> entirely
  481. * contains the specified <code>Rectangle2D</code>.
  482. * @param r the specified <code>Rectangle2D</code>
  483. * @return <code>true</code> if this <code>Polygon</code> entirely
  484. * contains the specified <code>Rectangle2D</code>
  485. * <code>false</code> otherwise.
  486. * @see #contains(double, double, double, double)
  487. */
  488. public boolean contains(Rectangle2D r) {
  489. return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
  490. }
  491. /**
  492. * Returns an iterator object that iterates along the boundary of this
  493. * <code>Polygon</code> and provides access to the geometry
  494. * of the outline of this <code>Polygon</code>. An optional
  495. * {@link AffineTransform} can be specified so that the coordinates
  496. * returned in the iteration are transformed accordingly.
  497. * @param at an optional <code>AffineTransform</code> to be applied to the
  498. * coordinates as they are returned in the iteration, or
  499. * <code>null</code> if untransformed coordinates are desired
  500. * @return a {@link PathIterator} object that provides access to the
  501. * geometry of this <code>Polygon</code>.
  502. */
  503. public PathIterator getPathIterator(AffineTransform at) {
  504. return new PolygonPathIterator(this, at);
  505. }
  506. /**
  507. * Returns an iterator object that iterates along the boundary of
  508. * the <code>Shape</code> and provides access to the geometry of the
  509. * outline of the <code>Shape</code>. Only SEG_MOVETO, SEG_LINETO, and
  510. * SEG_CLOSE point types are returned by the iterator.
  511. * Since polygons are already flat, the <code>flatness</code> parameter
  512. * is ignored. An optional <code>AffineTransform</code> can be specified
  513. * in which case the coordinates returned in the iteration are transformed
  514. * accordingly.
  515. * @param at an optional <code>AffineTransform</code> to be applied to the
  516. * coordinates as they are returned in the iteration, or
  517. * <code>null</code> if untransformed coordinates are desired
  518. * @param flatness the maximum amount that the control points
  519. * for a given curve can vary from colinear before a subdivided
  520. * curve is replaced by a straight line connecting the
  521. * endpoints. Since polygons are already flat the
  522. * <code>flatness</code> parameter is ignored.
  523. * @return a <code>PathIterator</code> object that provides access to the
  524. * <code>Shape</code> object's geometry.
  525. */
  526. public PathIterator getPathIterator(AffineTransform at, double flatness) {
  527. return getPathIterator(at);
  528. }
  529. class PolygonPathIterator implements PathIterator {
  530. Polygon poly;
  531. AffineTransform transform;
  532. int index;
  533. public PolygonPathIterator(Polygon pg, AffineTransform at) {
  534. poly = pg;
  535. transform = at;
  536. if (pg.npoints == 0) {
  537. // Prevent a spurious SEG_CLOSE segment
  538. index = 1;
  539. }
  540. }
  541. /**
  542. * Returns the winding rule for determining the interior of the
  543. * path.
  544. * @return an integer representing the current winding rule.
  545. * @see PathIterator#WIND_NON_ZERO
  546. */
  547. public int getWindingRule() {
  548. return WIND_EVEN_ODD;
  549. }
  550. /**
  551. * Tests if there are more points to read.
  552. * @return <code>true</code> if there are more points to read;
  553. * <code>false</code> otherwise.
  554. */
  555. public boolean isDone() {
  556. return index > poly.npoints;
  557. }
  558. /**
  559. * Moves the iterator forwards, along the primary direction of
  560. * traversal, to the next segment of the path when there are
  561. * more points in that direction.
  562. */
  563. public void next() {
  564. index++;
  565. }
  566. /**
  567. * Returns the coordinates and type of the current path segment in
  568. * the iteration.
  569. * The return value is the path segment type:
  570. * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
  571. * A <code>float</code> array of length 2 must be passed in and
  572. * can be used to store the coordinates of the point(s).
  573. * Each point is stored as a pair of <code>float</code> x, y
  574. * coordinates. SEG_MOVETO and SEG_LINETO types return one
  575. * point, and SEG_CLOSE does not return any points.
  576. * @param coords a <code>float</code> array that specifies the
  577. * coordinates of the point(s)
  578. * @return an integer representing the type and coordinates of the
  579. * current path segment.
  580. * @see PathIterator#SEG_MOVETO
  581. * @see PathIterator#SEG_LINETO
  582. * @see PathIterator#SEG_CLOSE
  583. */
  584. public int currentSegment(float[] coords) {
  585. if (index >= poly.npoints) {
  586. return SEG_CLOSE;
  587. }
  588. coords[0] = poly.xpoints[index];
  589. coords[1] = poly.ypoints[index];
  590. if (transform != null) {
  591. transform.transform(coords, 0, coords, 0, 1);
  592. }
  593. return (index == 0 ? SEG_MOVETO : SEG_LINETO);
  594. }
  595. /**
  596. * Returns the coordinates and type of the current path segment in
  597. * the iteration.
  598. * The return value is the path segment type:
  599. * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
  600. * A <code>double</code> array of length 2 must be passed in and
  601. * can be used to store the coordinates of the point(s).
  602. * Each point is stored as a pair of <code>double</code> x, y
  603. * coordinates.
  604. * SEG_MOVETO and SEG_LINETO types return one point,
  605. * and SEG_CLOSE does not return any points.
  606. * @param coords a <code>double</code> array that specifies the
  607. * coordinates of the point(s)
  608. * @return an integer representing the type and coordinates of the
  609. * current path segment.
  610. * @see PathIterator#SEG_MOVETO
  611. * @see PathIterator#SEG_LINETO
  612. * @see PathIterator#SEG_CLOSE
  613. */
  614. public int currentSegment(double[] coords) {
  615. if (index >= poly.npoints) {
  616. return SEG_CLOSE;
  617. }
  618. coords[0] = poly.xpoints[index];
  619. coords[1] = poly.ypoints[index];
  620. if (transform != null) {
  621. transform.transform(coords, 0, coords, 0, 1);
  622. }
  623. return (index == 0 ? SEG_MOVETO : SEG_LINETO);
  624. }
  625. }
  626. }