@Override public Rectangle2D getBounds2D() { if (npoints == 0) { return new Rectangle2D.Float(); } if (bounds == null) { calculateBounds(xpoints, ypoints, npoints); } return (Rectangle2D) bounds.clone(); }
public void addPoint(float x, float y) { if (npoints >= xpoints.length || npoints >= ypoints.length) { int newLength = npoints * 2; // Make sure that newLength will be greater than MIN_LENGTH and // aligned to the power of 2 if (newLength < MIN_LENGTH) { newLength = MIN_LENGTH; } else if ((newLength & (newLength - 1)) != 0) { newLength = Integer.highestOneBit(newLength); } float[] helper = new float[newLength]; System.arraycopy(xpoints, 0, helper, 0, npoints); xpoints = helper; helper = new float[newLength]; System.arraycopy(ypoints, 0, helper, 0, npoints); ypoints = helper; } xpoints[npoints] = x; ypoints[npoints] = y; npoints++; if (bounds != null) { updateBounds(x, y); } }
public boolean contains(float x, float y) { if (npoints <= 2 || !getBounds2D().contains(x, y)) { return false;
@Override public boolean contains(double x, double y, double w, double h) { return contains((float) x, (float) y, (float) w, (float) h); }
@Override public void addPoint(double x, double y) { addPoint((float) x, (float) y); }
@Override public boolean intersects(double x, double y, double w, double h) { return intersects((float) x, (float) y, (float) w, (float) h); }
@Override public boolean contains(double x, double y) { return contains((float) x, (float) y); }
/** * Translates the vertices of the <code>Polygon</code> by * <code>deltaX</code> along the x axis and by * <code>deltaY</code> along the y axis. * @param deltaX the amount to translate along the X axis * @param deltaY the amount to translate along the Y axis * */ @Override public void translate(double deltaX, double deltaY) { translate((float) deltaX, (float) deltaY); }
public boolean contains(float x, float y, float w, float h) { if (npoints <= 0 || !getBounds2D().intersects(x, y, w, h)) { return false; } Crossings cross = getCrossings(x, y, x + w, y + h); return (cross != null && cross.covers(y, y + h)); }
public boolean intersects(float x, float y, float w, float h) { if (npoints <= 0 || !getBounds2D().intersects(x, y, w, h)) { return false; } Crossings cross = getCrossings(x, y, x + w, y + h); return (cross == null || !cross.isEmpty()); }