0N/A/*
2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.geom.PathIterator;
0N/Aimport java.awt.geom.Point2D;
0N/Aimport java.awt.geom.Rectangle2D;
0N/Aimport sun.awt.geom.Crossings;
0N/Aimport java.util.Arrays;
0N/A
0N/A/**
0N/A * The <code>Polygon</code> class encapsulates a description of a
0N/A * closed, two-dimensional region within a coordinate space. This
0N/A * region is bounded by an arbitrary number of line segments, each of
0N/A * which is one side of the polygon. Internally, a polygon
0N/A * comprises of a list of {@code (x,y)}
0N/A * coordinate pairs, where each pair defines a <i>vertex</i> of the
0N/A * polygon, and two successive pairs are the endpoints of a
0N/A * line that is a side of the polygon. The first and final
0N/A * pairs of {@code (x,y)} points are joined by a line segment
0N/A * that closes the polygon. This <code>Polygon</code> is defined with
0N/A * an even-odd winding rule. See
0N/A * {@link java.awt.geom.PathIterator#WIND_EVEN_ODD WIND_EVEN_ODD}
0N/A * for a definition of the even-odd winding rule.
0N/A * This class's hit-testing methods, which include the
0N/A * <code>contains</code>, <code>intersects</code> and <code>inside</code>
0N/A * methods, use the <i>insideness</i> definition described in the
0N/A * {@link Shape} class comments.
0N/A *
0N/A * @author Sami Shaio
0N/A * @see Shape
0N/A * @author Herb Jellinek
0N/A * @since 1.0
0N/A */
0N/Apublic class Polygon implements Shape, java.io.Serializable {
0N/A
0N/A /**
0N/A * The total number of points. The value of <code>npoints</code>
0N/A * represents the number of valid points in this <code>Polygon</code>
0N/A * and might be less than the number of elements in
0N/A * {@link #xpoints xpoints} or {@link #ypoints ypoints}.
0N/A * This value can be NULL.
0N/A *
0N/A * @serial
0N/A * @see #addPoint(int, int)
0N/A * @since 1.0
0N/A */
0N/A public int npoints;
0N/A
0N/A /**
0N/A * The array of X coordinates. The number of elements in
0N/A * this array might be more than the number of X coordinates
0N/A * in this <code>Polygon</code>. The extra elements allow new points
0N/A * to be added to this <code>Polygon</code> without re-creating this
0N/A * array. The value of {@link #npoints npoints} is equal to the
0N/A * number of valid points in this <code>Polygon</code>.
0N/A *
0N/A * @serial
0N/A * @see #addPoint(int, int)
0N/A * @since 1.0
0N/A */
0N/A public int xpoints[];
0N/A
0N/A /**
0N/A * The array of Y coordinates. The number of elements in
0N/A * this array might be more than the number of Y coordinates
0N/A * in this <code>Polygon</code>. The extra elements allow new points
0N/A * to be added to this <code>Polygon</code> without re-creating this
0N/A * array. The value of <code>npoints</code> is equal to the
0N/A * number of valid points in this <code>Polygon</code>.
0N/A *
0N/A * @serial
0N/A * @see #addPoint(int, int)
0N/A * @since 1.0
0N/A */
0N/A public int ypoints[];
0N/A
0N/A /**
0N/A * The bounds of this {@code Polygon}.
0N/A * This value can be null.
0N/A *
0N/A * @serial
0N/A * @see #getBoundingBox()
0N/A * @see #getBounds()
0N/A * @since 1.0
0N/A */
0N/A protected Rectangle bounds;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -6460061437900069969L;
0N/A
0N/A /*
0N/A * Default length for xpoints and ypoints.
0N/A */
0N/A private static final int MIN_LENGTH = 4;
0N/A
0N/A /**
0N/A * Creates an empty polygon.
0N/A * @since 1.0
0N/A */
0N/A public Polygon() {
0N/A xpoints = new int[MIN_LENGTH];
0N/A ypoints = new int[MIN_LENGTH];
0N/A }
0N/A
0N/A /**
0N/A * Constructs and initializes a <code>Polygon</code> from the specified
0N/A * parameters.
0N/A * @param xpoints an array of X coordinates
0N/A * @param ypoints an array of Y coordinates
0N/A * @param npoints the total number of points in the
0N/A * <code>Polygon</code>
0N/A * @exception NegativeArraySizeException if the value of
0N/A * <code>npoints</code> is negative.
0N/A * @exception IndexOutOfBoundsException if <code>npoints</code> is
0N/A * greater than the length of <code>xpoints</code>
0N/A * or the length of <code>ypoints</code>.
0N/A * @exception NullPointerException if <code>xpoints</code> or
0N/A * <code>ypoints</code> is <code>null</code>.
0N/A * @since 1.0
0N/A */
0N/A public Polygon(int xpoints[], int ypoints[], int npoints) {
0N/A // Fix 4489009: should throw IndexOutofBoundsException instead
0N/A // of OutofMemoryException if npoints is huge and > {x,y}points.length
0N/A if (npoints > xpoints.length || npoints > ypoints.length) {
0N/A throw new IndexOutOfBoundsException("npoints > xpoints.length || "+
0N/A "npoints > ypoints.length");
0N/A }
0N/A // Fix 6191114: should throw NegativeArraySizeException with
0N/A // negative npoints
0N/A if (npoints < 0) {
0N/A throw new NegativeArraySizeException("npoints < 0");
0N/A }
0N/A // Fix 6343431: Applet compatibility problems if arrays are not
0N/A // exactly npoints in length
0N/A this.npoints = npoints;
0N/A this.xpoints = Arrays.copyOf(xpoints, npoints);
0N/A this.ypoints = Arrays.copyOf(ypoints, npoints);
0N/A }
0N/A
0N/A /**
0N/A * Resets this <code>Polygon</code> object to an empty polygon.
0N/A * The coordinate arrays and the data in them are left untouched
0N/A * but the number of points is reset to zero to mark the old
0N/A * vertex data as invalid and to start accumulating new vertex
0N/A * data at the beginning.
0N/A * All internally-cached data relating to the old vertices
0N/A * are discarded.
0N/A * Note that since the coordinate arrays from before the reset
0N/A * are reused, creating a new empty <code>Polygon</code> might
0N/A * be more memory efficient than resetting the current one if
0N/A * the number of vertices in the new polygon data is significantly
0N/A * smaller than the number of vertices in the data from before the
0N/A * reset.
0N/A * @see java.awt.Polygon#invalidate
0N/A * @since 1.4
0N/A */
0N/A public void reset() {
0N/A npoints = 0;
0N/A bounds = null;
0N/A }
0N/A
0N/A /**
0N/A * Invalidates or flushes any internally-cached data that depends
0N/A * on the vertex coordinates of this <code>Polygon</code>.
0N/A * This method should be called after any direct manipulation
0N/A * of the coordinates in the <code>xpoints</code> or
0N/A * <code>ypoints</code> arrays to avoid inconsistent results
0N/A * from methods such as <code>getBounds</code> or <code>contains</code>
0N/A * that might cache data from earlier computations relating to
0N/A * the vertex coordinates.
0N/A * @see java.awt.Polygon#getBounds
0N/A * @since 1.4
0N/A */
0N/A public void invalidate() {
0N/A bounds = null;
0N/A }
0N/A
0N/A /**
0N/A * Translates the vertices of the <code>Polygon</code> by
0N/A * <code>deltaX</code> along the x axis and by
0N/A * <code>deltaY</code> along the y axis.
0N/A * @param deltaX the amount to translate along the X axis
0N/A * @param deltaY the amount to translate along the Y axis
0N/A * @since 1.1
0N/A */
0N/A public void translate(int deltaX, int deltaY) {
0N/A for (int i = 0; i < npoints; i++) {
0N/A xpoints[i] += deltaX;
0N/A ypoints[i] += deltaY;
0N/A }
0N/A if (bounds != null) {
0N/A bounds.translate(deltaX, deltaY);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Calculates the bounding box of the points passed to the constructor.
0N/A * Sets <code>bounds</code> to the result.
0N/A * @param xpoints[] array of <i>x</i> coordinates
0N/A * @param ypoints[] array of <i>y</i> coordinates
0N/A * @param npoints the total number of points
0N/A */
0N/A void calculateBounds(int xpoints[], int ypoints[], int npoints) {
0N/A int boundsMinX = Integer.MAX_VALUE;
0N/A int boundsMinY = Integer.MAX_VALUE;
0N/A int boundsMaxX = Integer.MIN_VALUE;
0N/A int boundsMaxY = Integer.MIN_VALUE;
0N/A
0N/A for (int i = 0; i < npoints; i++) {
0N/A int x = xpoints[i];
0N/A boundsMinX = Math.min(boundsMinX, x);
0N/A boundsMaxX = Math.max(boundsMaxX, x);
0N/A int y = ypoints[i];
0N/A boundsMinY = Math.min(boundsMinY, y);
0N/A boundsMaxY = Math.max(boundsMaxY, y);
0N/A }
0N/A bounds = new Rectangle(boundsMinX, boundsMinY,
0N/A boundsMaxX - boundsMinX,
0N/A boundsMaxY - boundsMinY);
0N/A }
0N/A
0N/A /*
0N/A * Resizes the bounding box to accomodate the specified coordinates.
0N/A * @param x,&nbsp;y the specified coordinates
0N/A */
0N/A void updateBounds(int x, int y) {
0N/A if (x < bounds.x) {
0N/A bounds.width = bounds.width + (bounds.x - x);
0N/A bounds.x = x;
0N/A }
0N/A else {
0N/A bounds.width = Math.max(bounds.width, x - bounds.x);
0N/A // bounds.x = bounds.x;
0N/A }
0N/A
0N/A if (y < bounds.y) {
0N/A bounds.height = bounds.height + (bounds.y - y);
0N/A bounds.y = y;
0N/A }
0N/A else {
0N/A bounds.height = Math.max(bounds.height, y - bounds.y);
0N/A // bounds.y = bounds.y;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Appends the specified coordinates to this <code>Polygon</code>.
0N/A * <p>
0N/A * If an operation that calculates the bounding box of this
0N/A * <code>Polygon</code> has already been performed, such as
0N/A * <code>getBounds</code> or <code>contains</code>, then this
0N/A * method updates the bounding box.
0N/A * @param x the specified X coordinate
0N/A * @param y the specified Y coordinate
0N/A * @see java.awt.Polygon#getBounds
0N/A * @see java.awt.Polygon#contains
0N/A * @since 1.0
0N/A */
0N/A public void addPoint(int x, int y) {
0N/A if (npoints >= xpoints.length || npoints >= ypoints.length) {
0N/A int newLength = npoints * 2;
0N/A // Make sure that newLength will be greater than MIN_LENGTH and
0N/A // aligned to the power of 2
0N/A if (newLength < MIN_LENGTH) {
0N/A newLength = MIN_LENGTH;
0N/A } else if ((newLength & (newLength - 1)) != 0) {
0N/A newLength = Integer.highestOneBit(newLength);
0N/A }
0N/A
0N/A xpoints = Arrays.copyOf(xpoints, newLength);
0N/A ypoints = Arrays.copyOf(ypoints, newLength);
0N/A }
0N/A xpoints[npoints] = x;
0N/A ypoints[npoints] = y;
0N/A npoints++;
0N/A if (bounds != null) {
0N/A updateBounds(x, y);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets the bounding box of this <code>Polygon</code>.
0N/A * The bounding box is the smallest {@link Rectangle} whose
0N/A * sides are parallel to the x and y axes of the
0N/A * coordinate space, and can completely contain the <code>Polygon</code>.
0N/A * @return a <code>Rectangle</code> that defines the bounds of this
0N/A * <code>Polygon</code>.
0N/A * @since 1.1
0N/A */
0N/A public Rectangle getBounds() {
0N/A return getBoundingBox();
0N/A }
0N/A
0N/A /**
0N/A * Returns the bounds of this <code>Polygon</code>.
0N/A * @return the bounds of this <code>Polygon</code>.
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>getBounds()</code>.
0N/A * @since 1.0
0N/A */
0N/A @Deprecated
0N/A public Rectangle getBoundingBox() {
0N/A if (npoints == 0) {
0N/A return new Rectangle();
0N/A }
0N/A if (bounds == null) {
0N/A calculateBounds(xpoints, ypoints, npoints);
0N/A }
0N/A return bounds.getBounds();
0N/A }
0N/A
0N/A /**
0N/A * Determines whether the specified {@link Point} is inside this
0N/A * <code>Polygon</code>.
0N/A * @param p the specified <code>Point</code> to be tested
0N/A * @return <code>true</code> if the <code>Polygon</code> contains the
0N/A * <code>Point</code>; <code>false</code> otherwise.
0N/A * @see #contains(double, double)
0N/A * @since 1.0
0N/A */
0N/A public boolean contains(Point p) {
0N/A return contains(p.x, p.y);
0N/A }
0N/A
0N/A /**
0N/A * Determines whether the specified coordinates are inside this
0N/A * <code>Polygon</code>.
0N/A * <p>
0N/A * @param x the specified X coordinate to be tested
0N/A * @param y the specified Y coordinate to be tested
0N/A * @return {@code true} if this {@code Polygon} contains
0N/A * the specified coordinates {@code (x,y)};
0N/A * {@code false} otherwise.
0N/A * @see #contains(double, double)
0N/A * @since 1.1
0N/A */
0N/A public boolean contains(int x, int y) {
0N/A return contains((double) x, (double) y);
0N/A }
0N/A
0N/A /**
0N/A * Determines whether the specified coordinates are contained in this
0N/A * <code>Polygon</code>.
0N/A * @param x the specified X coordinate to be tested
0N/A * @param y the specified Y coordinate to be tested
0N/A * @return {@code true} if this {@code Polygon} contains
0N/A * the specified coordinates {@code (x,y)};
0N/A * {@code false} otherwise.
0N/A * @see #contains(double, double)
0N/A * @deprecated As of JDK version 1.1,
0N/A * replaced by <code>contains(int, int)</code>.
0N/A * @since 1.0
0N/A */
0N/A @Deprecated
0N/A public boolean inside(int x, int y) {
0N/A return contains((double) x, (double) y);
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public Rectangle2D getBounds2D() {
0N/A return getBounds();
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean contains(double x, double y) {
0N/A if (npoints <= 2 || !getBoundingBox().contains(x, y)) {
0N/A return false;
0N/A }
0N/A int hits = 0;
0N/A
0N/A int lastx = xpoints[npoints - 1];
0N/A int lasty = ypoints[npoints - 1];
0N/A int curx, cury;
0N/A
0N/A // Walk the edges of the polygon
0N/A for (int i = 0; i < npoints; lastx = curx, lasty = cury, i++) {
0N/A curx = xpoints[i];
0N/A cury = ypoints[i];
0N/A
0N/A if (cury == lasty) {
0N/A continue;
0N/A }
0N/A
0N/A int leftx;
0N/A if (curx < lastx) {
0N/A if (x >= lastx) {
0N/A continue;
0N/A }
0N/A leftx = curx;
0N/A } else {
0N/A if (x >= curx) {
0N/A continue;
0N/A }
0N/A leftx = lastx;
0N/A }
0N/A
0N/A double test1, test2;
0N/A if (cury < lasty) {
0N/A if (y < cury || y >= lasty) {
0N/A continue;
0N/A }
0N/A if (x < leftx) {
0N/A hits++;
0N/A continue;
0N/A }
0N/A test1 = x - curx;
0N/A test2 = y - cury;
0N/A } else {
0N/A if (y < lasty || y >= cury) {
0N/A continue;
0N/A }
0N/A if (x < leftx) {
0N/A hits++;
0N/A continue;
0N/A }
0N/A test1 = x - lastx;
0N/A test2 = y - lasty;
0N/A }
0N/A
0N/A if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {
0N/A hits++;
0N/A }
0N/A }
0N/A
0N/A return ((hits & 1) != 0);
0N/A }
0N/A
0N/A private Crossings getCrossings(double xlo, double ylo,
0N/A double xhi, double yhi)
0N/A {
0N/A Crossings cross = new Crossings.EvenOdd(xlo, ylo, xhi, yhi);
0N/A int lastx = xpoints[npoints - 1];
0N/A int lasty = ypoints[npoints - 1];
0N/A int curx, cury;
0N/A
0N/A // Walk the edges of the polygon
0N/A for (int i = 0; i < npoints; i++) {
0N/A curx = xpoints[i];
0N/A cury = ypoints[i];
0N/A if (cross.accumulateLine(lastx, lasty, curx, cury)) {
0N/A return null;
0N/A }
0N/A lastx = curx;
0N/A lasty = cury;
0N/A }
0N/A
0N/A return cross;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean contains(Point2D p) {
0N/A return contains(p.getX(), p.getY());
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean intersects(double x, double y, double w, double h) {
0N/A if (npoints <= 0 || !getBoundingBox().intersects(x, y, w, h)) {
0N/A return false;
0N/A }
0N/A
0N/A Crossings cross = getCrossings(x, y, x+w, y+h);
0N/A return (cross == null || !cross.isEmpty());
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean intersects(Rectangle2D r) {
0N/A return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean contains(double x, double y, double w, double h) {
0N/A if (npoints <= 0 || !getBoundingBox().intersects(x, y, w, h)) {
0N/A return false;
0N/A }
0N/A
0N/A Crossings cross = getCrossings(x, y, x+w, y+h);
0N/A return (cross != null && cross.covers(y, y+h));
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.2
0N/A */
0N/A public boolean contains(Rectangle2D r) {
0N/A return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
0N/A }
0N/A
0N/A /**
0N/A * Returns an iterator object that iterates along the boundary of this
0N/A * <code>Polygon</code> and provides access to the geometry
0N/A * of the outline of this <code>Polygon</code>. An optional
0N/A * {@link AffineTransform} can be specified so that the coordinates
0N/A * returned in the iteration are transformed accordingly.
0N/A * @param at an optional <code>AffineTransform</code> to be applied to the
0N/A * coordinates as they are returned in the iteration, or
0N/A * <code>null</code> if untransformed coordinates are desired
0N/A * @return a {@link PathIterator} object that provides access to the
0N/A * geometry of this <code>Polygon</code>.
0N/A * @since 1.2
0N/A */
0N/A public PathIterator getPathIterator(AffineTransform at) {
0N/A return new PolygonPathIterator(this, at);
0N/A }
0N/A
0N/A /**
0N/A * Returns an iterator object that iterates along the boundary of
0N/A * the <code>Shape</code> and provides access to the geometry of the
0N/A * outline of the <code>Shape</code>. Only SEG_MOVETO, SEG_LINETO, and
0N/A * SEG_CLOSE point types are returned by the iterator.
0N/A * Since polygons are already flat, the <code>flatness</code> parameter
0N/A * is ignored. An optional <code>AffineTransform</code> can be specified
0N/A * in which case the coordinates returned in the iteration are transformed
0N/A * accordingly.
0N/A * @param at an optional <code>AffineTransform</code> to be applied to the
0N/A * coordinates as they are returned in the iteration, or
0N/A * <code>null</code> if untransformed coordinates are desired
0N/A * @param flatness the maximum amount that the control points
0N/A * for a given curve can vary from colinear before a subdivided
0N/A * curve is replaced by a straight line connecting the
0N/A * endpoints. Since polygons are already flat the
0N/A * <code>flatness</code> parameter is ignored.
0N/A * @return a <code>PathIterator</code> object that provides access to the
0N/A * <code>Shape</code> object's geometry.
0N/A * @since 1.2
0N/A */
0N/A public PathIterator getPathIterator(AffineTransform at, double flatness) {
0N/A return getPathIterator(at);
0N/A }
0N/A
0N/A class PolygonPathIterator implements PathIterator {
0N/A Polygon poly;
0N/A AffineTransform transform;
0N/A int index;
0N/A
0N/A public PolygonPathIterator(Polygon pg, AffineTransform at) {
0N/A poly = pg;
0N/A transform = at;
0N/A if (pg.npoints == 0) {
0N/A // Prevent a spurious SEG_CLOSE segment
0N/A index = 1;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the winding rule for determining the interior of the
0N/A * path.
0N/A * @return an integer representing the current winding rule.
0N/A * @see PathIterator#WIND_NON_ZERO
0N/A */
0N/A public int getWindingRule() {
0N/A return WIND_EVEN_ODD;
0N/A }
0N/A
0N/A /**
0N/A * Tests if there are more points to read.
0N/A * @return <code>true</code> if there are more points to read;
0N/A * <code>false</code> otherwise.
0N/A */
0N/A public boolean isDone() {
0N/A return index > poly.npoints;
0N/A }
0N/A
0N/A /**
0N/A * Moves the iterator forwards, along the primary direction of
0N/A * traversal, to the next segment of the path when there are
0N/A * more points in that direction.
0N/A */
0N/A public void next() {
0N/A index++;
0N/A }
0N/A
0N/A /**
0N/A * Returns the coordinates and type of the current path segment in
0N/A * the iteration.
0N/A * The return value is the path segment type:
0N/A * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
0N/A * A <code>float</code> array of length 2 must be passed in and
0N/A * can be used to store the coordinates of the point(s).
0N/A * Each point is stored as a pair of <code>float</code> x,&nbsp;y
0N/A * coordinates. SEG_MOVETO and SEG_LINETO types return one
0N/A * point, and SEG_CLOSE does not return any points.
0N/A * @param coords a <code>float</code> array that specifies the
0N/A * coordinates of the point(s)
0N/A * @return an integer representing the type and coordinates of the
0N/A * current path segment.
0N/A * @see PathIterator#SEG_MOVETO
0N/A * @see PathIterator#SEG_LINETO
0N/A * @see PathIterator#SEG_CLOSE
0N/A */
0N/A public int currentSegment(float[] coords) {
0N/A if (index >= poly.npoints) {
0N/A return SEG_CLOSE;
0N/A }
0N/A coords[0] = poly.xpoints[index];
0N/A coords[1] = poly.ypoints[index];
0N/A if (transform != null) {
0N/A transform.transform(coords, 0, coords, 0, 1);
0N/A }
0N/A return (index == 0 ? SEG_MOVETO : SEG_LINETO);
0N/A }
0N/A
0N/A /**
0N/A * Returns the coordinates and type of the current path segment in
0N/A * the iteration.
0N/A * The return value is the path segment type:
0N/A * SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
0N/A * A <code>double</code> array of length 2 must be passed in and
0N/A * can be used to store the coordinates of the point(s).
0N/A * Each point is stored as a pair of <code>double</code> x,&nbsp;y
0N/A * coordinates.
0N/A * SEG_MOVETO and SEG_LINETO types return one point,
0N/A * and SEG_CLOSE does not return any points.
0N/A * @param coords a <code>double</code> array that specifies the
0N/A * coordinates of the point(s)
0N/A * @return an integer representing the type and coordinates of the
0N/A * current path segment.
0N/A * @see PathIterator#SEG_MOVETO
0N/A * @see PathIterator#SEG_LINETO
0N/A * @see PathIterator#SEG_CLOSE
0N/A */
0N/A public int currentSegment(double[] coords) {
0N/A if (index >= poly.npoints) {
0N/A return SEG_CLOSE;
0N/A }
0N/A coords[0] = poly.xpoints[index];
0N/A coords[1] = poly.ypoints[index];
0N/A if (transform != null) {
0N/A transform.transform(coords, 0, coords, 0, 1);
0N/A }
0N/A return (index == 0 ? SEG_MOVETO : SEG_LINETO);
0N/A }
0N/A }
0N/A}