Game Development Reference
In-Depth Information
npoints++;
if (bounds != null) {
updateBounds(x, y);
}
}
void updateBounds(int x, int y) {
if (x < bounds.x) {
bounds.width = bounds.width + (bounds.x - x);
bounds.x = x;
} else {
bounds.width = Math.max(bounds.width, x - bounds.x);
}
if (y < bounds.y) {
bounds.height = bounds.height + (bounds.y - y);
bounds.y = y;
} else {
bounds.height = Math.max(bounds.height, y - bounds.y);
}
}
public Rectangle getBoundingBox() {
if (npoints == 0) {
return new Rectangle();
}
if (bounds == null) {
calculateBounds(xpoints, ypoints, npoints);
}
return bounds;
}
/**
* Determines if the specified coordinates are inside this
* <code>Polygon</code>.
*
* @param x
* @param y
* @return
*/
public boolean contains(int x, int y) {
if (npoints <= 2 || !getBoundingBox().contains(x, y)) {
return false;
}
int hits = 0;
int lastx = xpoints[npoints - 1];
int lasty = ypoints[npoints - 1];
int curx, cury;
Search WWH ::




Custom Search