import * as validate from '@mmit/validate';

class Point2D {
    x;
    y;
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
}
class CatmullRom {
    percentage(percent) {
        return this.position(percent / 100);
    }
}
class CatmullRomSpline extends CatmullRom {
    _p0;
    _p1;
    _p2;
    _p3;
    constructor(_p0, _p1, _p2, _p3) {
        super();
        this._p0 = _p0;
        this._p1 = _p1;
        this._p2 = _p2;
        this._p3 = _p3;
    }
    static noEndpoints(p1, p2) {
        return new CatmullRomSpline(p1, p1, p2, p2);
    }
    position(distance) {
        validate.inclusiveBetween(distance, 0, 1, () => `Distance must be between 0 and 1 but was ${distance}`);
        return (0.5 *
            (2 * this._p1 +
                (this._p2 - this._p0) * distance +
                (2 * this._p0 - 5 * this._p1 + 4 * this._p2 - this._p3) * distance * distance +
                (3 * this._p1 - this._p0 - 3 * this._p2 + this._p3) *
                    distance *
                    distance *
                    distance));
    }
}
class CatmullRomSpline2D extends CatmullRom {
    _p0;
    _p1;
    _p2;
    _p3;
    // prettier-ignore
    constructor(_p0, _p1, _p2, _p3) {
        super();
        this._p0 = _p0;
        this._p1 = _p1;
        this._p2 = _p2;
        this._p3 = _p3;
    }
    // prettier-ignore
    static noEndpoints(_p0, _p1) {
        return new CatmullRomSpline2D(_p0, _p0, _p1, _p1);
    }
    position(distance) {
        validate.inclusiveBetween(distance, 0, 1, () => `Distance must be between 0 and 1 but was ${distance}`);
        return new Point2D(new CatmullRomSpline(this._p0.x, this._p1.x, this._p2.x, this._p3.x).position(distance), new CatmullRomSpline(this._p0.y, this._p1.y, this._p2.y, this._p3.y).position(distance));
    }
}

export { CatmullRom, CatmullRomSpline, CatmullRomSpline2D, Point2D };
//# sourceMappingURL=CatmullRomSpline.js.map
