import { Vector3 } from "./Vector3.js";
export class Plane {
    normal;
    constant;
    constructor(normal = Vector3.up.clone(), constant = 0) {
        const len = normal.length();
        if (len === 0)
            throw new RangeError("Plane normal must be non-zero.");
        this.normal = normal.multiplyScalar(1 / len);
        this.constant = constant / len;
    }
    static fromPointNormal(point, normal) {
        const normalized = normal.normalize();
        return new Plane(normalized, -point.dot(normalized));
    }
    distanceToPoint(point) {
        return this.normal.dot(point) + this.constant;
    }
    projectPoint(point) {
        return point.subtract(this.normal.multiplyScalar(this.distanceToPoint(point)));
    }
    intersectLine(start, end) {
        const direction = end.subtract(start);
        const denominator = this.normal.dot(direction);
        if (Math.abs(denominator) < 1e-12)
            return undefined;
        const t = -(start.dot(this.normal) + this.constant) / denominator;
        return t < 0 || t > 1 ? undefined : start.add(direction.multiplyScalar(t));
    }
}
//# sourceMappingURL=Plane.js.map