/**
* This method should be fast if no changes to bounding box have been made.
*/
@SuppressWarnings("unchecked")
private void refreshLocalBoundingBox() {
Rectangle2D newBoundingBox = super.getBoundingBox(false);
if (newBoundingBox == null) {
newBoundingBox = new Rectangle2D(new Vector2D(0, 0), new Vector2D(1, 1));
this.localBoundingBox = newBoundingBox;
}
if (this.tileNumHorizontally <= 0) {
// StaticMethods.logDebug("Number of tiles horizontally must be positive, is: " + this.tileNumHorizontally, this.getParCollection());
return;
}
if (this.tileNumVertically <= 0) {
// StaticMethods.logDebug("Number of tiles vertically must be positive, is: " + this.tileNumVertically, this.getParCollection());
return;
}
// If bounding box changed (==> refresh and reset tile coordinates).
if (this.oldBoundingBox == null
|| Math.abs(this.oldBoundingBox.upperLeftCorner().x - newBoundingBox.upperLeftCorner().x) > epsilon
|| Math.abs(this.oldBoundingBox.upperLeftCorner().y - newBoundingBox.upperLeftCorner().y) > epsilon
|| Math.abs(this.oldBoundingBox.lowerRightCorner().x - newBoundingBox.lowerRightCorner().x) > epsilon
|| Math.abs(this.oldBoundingBox.lowerRightCorner().y - newBoundingBox.lowerRightCorner().y) > epsilon) {
double x1 = newBoundingBox.upperLeftCorner().x - boundingBuffer.x,
x2 = newBoundingBox.lowerRightCorner().x + boundingBuffer.x,
y1 = newBoundingBox.upperLeftCorner().y - boundingBuffer.y,
y2 = newBoundingBox.lowerRightCorner().y + boundingBuffer.y;
// System.out.println("bound");
tiles = new LinkedList[tileNumHorizontally][tileNumVertically];
this.localBoundingBox = new Rectangle2D(new Vector2D(x1, y1), new Vector2D(x2, y2));
this.oldBoundingBox = new Rectangle2D(newBoundingBox);
this.tileCoordinates = new Rectangle2D[tileNumHorizontally][tileNumVertically];
this.agentTouchingTiles.clear();
}
}