|
|
|
@ -53,27 +53,6 @@ export class Rectangle {
|
|
|
|
|
return a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a rectangle arround a rotated point
|
|
|
|
|
* @param {Array<Vector>} points
|
|
|
|
|
* @param {number} angle
|
|
|
|
|
* @returns {Rectangle}
|
|
|
|
|
*/
|
|
|
|
|
static getAroundPointsRotated(points, angle) {
|
|
|
|
|
let minX = 1e10;
|
|
|
|
|
let minY = 1e10;
|
|
|
|
|
let maxX = -1e10;
|
|
|
|
|
let maxY = -1e10;
|
|
|
|
|
for (let i = 0; i < points.length; ++i) {
|
|
|
|
|
const rotated = points[i].rotated(angle);
|
|
|
|
|
minX = Math.min(minX, rotated.x);
|
|
|
|
|
minY = Math.min(minY, rotated.y);
|
|
|
|
|
maxX = Math.max(maxX, rotated.x);
|
|
|
|
|
maxY = Math.max(maxY, rotated.y);
|
|
|
|
|
}
|
|
|
|
|
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copies this instance
|
|
|
|
|
* @returns {Rectangle}
|
|
|
|
@ -82,28 +61,6 @@ export class Rectangle {
|
|
|
|
|
return new Rectangle(this.x, this.y, this.w, this.h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ensures the rectangle contains the given square
|
|
|
|
|
* @param {number} centerX
|
|
|
|
|
* @param {number} centerY
|
|
|
|
|
* @param {number} halfWidth
|
|
|
|
|
* @param {number} halfHeight
|
|
|
|
|
*/
|
|
|
|
|
extendBySquare(centerX, centerY, halfWidth, halfHeight) {
|
|
|
|
|
if (this.isEmpty()) {
|
|
|
|
|
// Just assign values since this rectangle is empty
|
|
|
|
|
this.x = centerX - halfWidth;
|
|
|
|
|
this.y = centerY - halfHeight;
|
|
|
|
|
this.w = halfWidth * 2;
|
|
|
|
|
this.h = halfHeight * 2;
|
|
|
|
|
} else {
|
|
|
|
|
this.setLeft(Math.min(this.x, centerX - halfWidth));
|
|
|
|
|
this.setRight(Math.max(this.right(), centerX + halfWidth));
|
|
|
|
|
this.setTop(Math.min(this.y, centerY - halfHeight));
|
|
|
|
|
this.setBottom(Math.max(this.bottom(), centerY + halfHeight));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns if this rectangle is empty
|
|
|
|
|
* @returns {boolean}
|
|
|
|
@ -259,14 +216,6 @@ export class Rectangle {
|
|
|
|
|
return new Rectangle(this.x - amount, this.y - amount, this.w + 2 * amount, this.h + 2 * amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for computing a culling area. Returns the top left tile
|
|
|
|
|
* @returns {Vector}
|
|
|
|
|
*/
|
|
|
|
|
getMinStartTile() {
|
|
|
|
|
return new Vector(this.x, this.y).snapWorldToTile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns if the given rectangle is contained
|
|
|
|
|
* @param {Rectangle} rect
|
|
|
|
@ -394,7 +343,7 @@ export class Rectangle {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a new recangle in tile space which includes all tiles which are visible in this rect
|
|
|
|
|
* Returns a new rectangle in tile space which includes all tiles which are visible in this rect
|
|
|
|
|
* @returns {Rectangle}
|
|
|
|
|
*/
|
|
|
|
|
toTileCullRectangle() {
|
|
|
|
|