/** * Determines whether the specified {@link Point} is inside this * <code>Polygon</code>. * @param p the specified <code>Point</code> to be tested * @return <code>true</code> if the <code>Polygon</code> contains the * <code>Point</code>; <code>false</code> otherwise. * @see #contains(double, double) */ public boolean contains(Point p) { return contains(p.x, p.y); }
/** * Constructs and initializes a <code>Polygon2D</code> from the specified * Polygon. * @param pol the Polygon * @exception NullPointerException pol is <code>null</code>. */ public Polygon2D(Polygon pol) { if (pol == null) { throw new IndexOutOfBoundsException("null Polygon"); } this.npoints = pol.npoints; this.xpoints = new float[pol.npoints]; this.ypoints = new float[pol.npoints]; for (int i = 0; i < pol.npoints; i++) { xpoints[i] = pol.xpoints[i]; ypoints[i] = pol.ypoints[i]; } calculatePath(); }
/** * Returns an iterator object that iterates along the boundary of this * <code>Polygon</code> and provides access to the geometry * of the outline of this <code>Polygon</code>. An optional * {@link AffineTransform} can be specified so that the coordinates * returned in the iteration are transformed accordingly. * @param at an optional <code>AffineTransform</code> to be applied to the * coordinates as they are returned in the iteration, or * <code>null</code> if untransformed coordinates are desired * @return a {@link PathIterator} object that provides access to the * geometry of this <code>Polygon</code>. */ public PathIterator getPathIterator(AffineTransform at) { updateComputingPath(); if (closedPath == null) return null; else return closedPath.getPathIterator(at); }
public void addPoint(Point2D p) { addPoint((float)p.getX(), (float)p.getY()); }
/** * Tests if the interior of this <code>Polygon</code> intersects the * interior of a specified <code>Rectangle2D</code>. * @param r a specified <code>Rectangle2D</code> * @return <code>true</code> if this <code>Polygon</code> and the * interior of the specified <code>Rectangle2D</code> * intersect each other; <code>false</code> * otherwise. */ public boolean intersects(Rectangle2D r) { return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
/** * Appends the specified coordinates to this <code>Polygon2D</code>. * @param x the specified x coordinate * @param y the specified y coordinate */ public void addPoint(float x, float y) { if (npoints == xpoints.length) { float[] tmp; tmp = new float[npoints * 2]; System.arraycopy(xpoints, 0, tmp, 0, npoints); xpoints = tmp; tmp = new float[npoints * 2]; System.arraycopy(ypoints, 0, tmp, 0, npoints); ypoints = tmp; } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; updatePath(x, y); }
/** * Returns an iterator object that iterates along the boundary of * the <code>Polygon2D</code> and provides access to the geometry of the * outline of the <code>Shape</code>. Only SEG_MOVETO, SEG_LINETO, and * SEG_CLOSE point types are returned by the iterator. * Since polygons are already flat, the <code>flatness</code> parameter * is ignored. * @param at an optional <code>AffineTransform</code> to be applied to the * coordinates as they are returned in the iteration, or * <code>null</code> if untransformed coordinates are desired * @param flatness the maximum amount that the control points * for a given curve can vary from colinear before a subdivided * curve is replaced by a straight line connecting the * endpoints. Since polygons are already flat the * <code>flatness</code> parameter is ignored. * @return a <code>PathIterator</code> object that provides access to the * <code>Shape</code> object's geometry. */ public PathIterator getPathIterator(AffineTransform at, double flatness) { return getPathIterator(at); } }
/** * Returns an iterator object that iterates along the boundary of this * <code>Polygon</code> and provides access to the geometry * of the outline of this <code>Polygon</code>. An optional * {@link AffineTransform} can be specified so that the coordinates * returned in the iteration are transformed accordingly. * @param at an optional <code>AffineTransform</code> to be applied to the * coordinates as they are returned in the iteration, or * <code>null</code> if untransformed coordinates are desired * @return a {@link PathIterator} object that provides access to the * geometry of this <code>Polygon</code>. */ public PathIterator getPathIterator(AffineTransform at) { updateComputingPath(); if (closedPath == null) return null; else return closedPath.getPathIterator(at); }
public void addPoint(Point2D p) { addPoint((float)p.getX(), (float)p.getY()); }
/** * Tests if the interior of this <code>Polygon</code> intersects the * interior of a specified <code>Rectangle2D</code>. * @param r a specified <code>Rectangle2D</code> * @return <code>true</code> if this <code>Polygon</code> and the * interior of the specified <code>Rectangle2D</code> * intersect each other; <code>false</code> * otherwise. */ public boolean intersects(Rectangle2D r) { return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
/** * Appends the specified coordinates to this <code>Polygon2D</code>. * @param x the specified x coordinate * @param y the specified y coordinate */ public void addPoint(float x, float y) { if (npoints == xpoints.length) { float[] tmp; tmp = new float[npoints * 2]; System.arraycopy(xpoints, 0, tmp, 0, npoints); xpoints = tmp; tmp = new float[npoints * 2]; System.arraycopy(ypoints, 0, tmp, 0, npoints); ypoints = tmp; } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; updatePath(x, y); }
/** * Returns an iterator object that iterates along the boundary of * the <code>Polygon2D</code> and provides access to the geometry of the * outline of the <code>Shape</code>. Only SEG_MOVETO, SEG_LINETO, and * SEG_CLOSE point types are returned by the iterator. * Since polygons are already flat, the <code>flatness</code> parameter * is ignored. * @param at an optional <code>AffineTransform</code> to be applied to the * coordinates as they are returned in the iteration, or * <code>null</code> if untransformed coordinates are desired * @param flatness the maximum amount that the control points * for a given curve can vary from colinear before a subdivided * curve is replaced by a straight line connecting the * endpoints. Since polygons are already flat the * <code>flatness</code> parameter is ignored. * @return a <code>PathIterator</code> object that provides access to the * <code>Shape</code> object's geometry. */ public PathIterator getPathIterator(AffineTransform at, double flatness) { return getPathIterator(at); } }
/** * Determines whether the specified coordinates are inside this * <code>Polygon</code>. * <p> * @param x the specified x coordinate to be tested * @param y the specified y coordinate to be tested * @return <code>true</code> if this <code>Polygon</code> contains * the specified coordinates, (<i>x</i>, <i>y</i>); * <code>false</code> otherwise. */ public boolean contains(int x, int y) { return contains((double) x, (double) y); }
Polygon2D pol = new Polygon2D(_xpts, _ypts, count); paint(brushObject, penObject, pol);
/** * Returns an iterator object that iterates along the boundary of this * <code>Polygon</code> and provides access to the geometry * of the outline of this <code>Polygon</code>. An optional * {@link AffineTransform} can be specified so that the coordinates * returned in the iteration are transformed accordingly. * @param at an optional <code>AffineTransform</code> to be applied to the * coordinates as they are returned in the iteration, or * <code>null</code> if untransformed coordinates are desired * @return a {@link PathIterator} object that provides access to the * geometry of this <code>Polygon</code>. */ public PathIterator getPathIterator(AffineTransform at) { updateComputingPath(); if (closedPath == null) return null; else return closedPath.getPathIterator(at); }