/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Curve
 */
import { Geometry } from "../../Geometry";
import { CubicEvaluator } from "./CubicEvaluator";
/**
 * MX Cubic along arc.
 * This is y = m*x^3 with
 * * x any point on the x axis.
 * * `fraction` along the spiral goes to `x = fraction * Lx`.
 * * m is (1/6RL).
 * * construction length L is nominal along the curve.
 * * x length Lx is along the axis, determined by two terms of the clothoid x series.
 * @internal
 */
export class MXCubicAlongArcEvaluator extends CubicEvaluator {
    nominalLength1;
    nominalRadius1;
    /** Constructor is private.  Caller responsible for cubicM validity. */
    constructor(length1, radius1, axisLength, cubicM) {
        super(axisLength, cubicM);
        this.nominalLength1 = length1;
        this.nominalRadius1 = radius1;
    }
    /** Compute the cubic constant. */
    static computeCubicM(length1, radius1) {
        const axisLength = MXCubicAlongArcEvaluator.approximateDistanceAlongToX(length1, radius1, length1);
        return 1.0 / (6.0 * radius1 * axisLength);
    }
    static create(length1, radius1) {
        const m = this.computeCubicM(length1, radius1);
        if (m === undefined)
            return undefined;
        const xMax = MXCubicAlongArcEvaluator.approximateDistanceAlongToX(length1, radius1, length1);
        return new MXCubicAlongArcEvaluator(length1, radius1, xMax, m);
    }
    scaleInPlace(scaleFactor) {
        this.nominalLength1 *= scaleFactor;
        this.nominalRadius1 *= scaleFactor;
        super.scaleInPlace(scaleFactor);
    }
    /** Return a deep copy of the evaluator. */
    clone() {
        return new MXCubicAlongArcEvaluator(this.nominalLength1, this.nominalRadius1, this.axisLength, this.cubicM);
    }
    /** Member by member matchup. */
    isAlmostEqual(other) {
        if (other instanceof MXCubicAlongArcEvaluator) {
            return Geometry.isSameCoordinate(this.nominalLength1, other.nominalLength1)
                && Geometry.isSameCoordinate(this.nominalRadius1, other.nominalRadius1);
        }
        return false;
    }
    /**
     * Return a (fast but mediocre) approximation of spiral x position as function of approximate distance along the curve.
     * * This x-to-distance relation is not as precise as the CurvePrimitive method moveSignedDistanceFromFraction.
     * * It is supported here for users interested in replicating the Czech distance mapping rather than the more accurate
     * CurvePrimitive measurements.
     * @param x distance along the x axis.
     */
    static approximateDistanceAlongToX(nominalLength1, nominalRadius1, nominalDistanceAlong) {
        const l2 = nominalLength1 * nominalLength1;
        const r2 = nominalRadius1 * nominalRadius1;
        const xx = nominalDistanceAlong * nominalDistanceAlong;
        return nominalDistanceAlong * (1.0 - xx * xx / (40.0 * r2 * l2));
    }
}
//# sourceMappingURL=MXCubicAlongArcSpiralEvaluator.js.map