import { Box3, Vector3 } from "../math/index.js";
import { transformPoint } from "./MathTypes.js";
export class Bounds3 {
    min;
    max;
    constructor(min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity]) {
        this.min = [...min];
        this.max = [...max];
    }
    static fromCenterSize(center, size) {
        return new Bounds3([center[0] - size[0] / 2, center[1] - size[1] / 2, center[2] - size[2] / 2], [center[0] + size[0] / 2, center[1] + size[1] / 2, center[2] + size[2] / 2]);
    }
    static fromMathBox(box) {
        return new Bounds3(box.min.toArray(), box.max.toArray());
    }
    isEmpty() {
        return this.toMathBox().isEmpty();
    }
    union(other) {
        return Bounds3.fromMathBox(this.toMathBox().union(other.toMathBox()));
    }
    intersects(other) {
        return this.toMathBox().intersectsBox(other.toMathBox());
    }
    containsPoint(point) {
        return this.toMathBox().containsPoint(new Vector3(point[0], point[1], point[2]));
    }
    transform(matrix) {
        if (this.isEmpty())
            return new Bounds3();
        const corners = [
            [this.min[0], this.min[1], this.min[2]],
            [this.max[0], this.min[1], this.min[2]],
            [this.min[0], this.max[1], this.min[2]],
            [this.min[0], this.min[1], this.max[2]],
            [this.max[0], this.max[1], this.min[2]],
            [this.max[0], this.min[1], this.max[2]],
            [this.min[0], this.max[1], this.max[2]],
            [this.max[0], this.max[1], this.max[2]]
        ];
        return corners.reduce((bounds, corner) => bounds.includePoint(transformPoint(matrix, corner)), new Bounds3());
    }
    includePoint(point) {
        this.min = [Math.min(this.min[0], point[0]), Math.min(this.min[1], point[1]), Math.min(this.min[2], point[2])];
        this.max = [Math.max(this.max[0], point[0]), Math.max(this.max[1], point[1]), Math.max(this.max[2], point[2])];
        return this;
    }
    clone() {
        return new Bounds3(this.min, this.max);
    }
    toMathBox() {
        return new Box3(new Vector3(this.min[0], this.min[1], this.min[2]), new Vector3(this.max[0], this.max[1], this.max[2]));
    }
}
//# sourceMappingURL=Bounds.js.map