"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.CubicEvaluator = void 0;
/** @packageDocumentation
 * @module Curve
 */
const XYCurveEvaluator_1 = require("./XYCurveEvaluator");
/**
 * Intermediate class for evaluation of bare cubic spirals `y = m*x^3` with x axis from [0..xLength]
 * * This implements all the computations among fraction, x, and y.
 * * Derived classes implement specialized logic such as (a) precomputing `m` and (b) domain-specific fraction-to-distance
 * approximations.
 * @internal
 */
class CubicEvaluator extends XYCurveEvaluator_1.XYCurveEvaluator {
    _cubicM;
    _axisLength;
    constructor(axisLength, cubicM) {
        super();
        this._cubicM = cubicM;
        this._axisLength = axisLength;
    }
    /** Update both constants. */
    setConstants(axisLength, cubicM) {
        this._axisLength = axisLength;
        this._cubicM = cubicM;
    }
    get axisLength() {
        return this._axisLength;
    }
    get cubicM() {
        return this._cubicM;
    }
    /**
     * Apply `scaleFactor` to the xLength and cubicM.
     * * Derived classes commonly call this as `super.scaleInPlace()`, and additionally apply the scale to their members.
     */
    scaleInPlace(scaleFactor) {
        this._axisLength *= scaleFactor;
        // "x" arriving at "m * x^3" will be scaled. "m" has to be divided by the scale to cancel 2 of the 3
        this._cubicM /= (scaleFactor * scaleFactor);
    }
    /** Evaluate X at fraction. */
    fractionToX(fraction) {
        return fraction * this._axisLength;
    }
    /** Evaluate derivative of X with respect to fraction. */
    fractionToDX(_fraction) {
        return this._axisLength;
    }
    /** Evaluate second derivative of X with respect to fraction. */
    fractionToDDX(_fraction) {
        return 0.0;
    }
    /** Evaluate third derivative of X with respect to fraction. */
    fractionToD3X(_fraction) {
        return 0.0;
    }
    /** Evaluate Y at fraction. */
    fractionToY(fraction) {
        const x = fraction * this._axisLength;
        return this._cubicM * x * x * x;
    }
    /** Evaluate derivative of Y with respect to fraction. */
    fractionToDY(fraction) {
        const x = fraction * this._axisLength;
        return 3.0 * this._cubicM * x * x * this._axisLength;
    }
    /** Evaluate second derivative of Y with respect to fraction. */
    fractionToDDY(fraction) {
        const x = fraction * this._axisLength;
        return 6.0 * this._cubicM * x * this._axisLength * this._axisLength;
    }
    /** Evaluate third derivative of Y with respect to fraction. */
    fractionToD3Y(_fraction) {
        return 6.0 * this._cubicM * this._axisLength * this._axisLength * this._axisLength;
    }
    /** Evaluate fraction at x. */
    xToFraction(x) {
        return x / this._axisLength;
    }
}
exports.CubicEvaluator = CubicEvaluator;
//# sourceMappingURL=CubicEvaluator.js.map