using MultiWheelC.TrajectoryPlanning.CoarsePath;

namespace MultiWheelC.TrajectoryPlanning.PathSmoothing;

/// <summary>平滑空间路径上的不可变采样点；位置和长度单位为 m，航向为 rad，曲率为 1/m。</summary>
public sealed class SmoothedPathPoint
{
    public SmoothedPathPoint(
        double xMeters,
        double yMeters,
        double headingRadians,
        double unwrappedHeadingRadians,
        double arcLengthMeters,
        TravelDirection direction,
        double geometricCurvaturePerMeter,
        double vehicleCurvaturePerMeter,
        double bodyClearanceMeters,
        bool isGearSwitchPoint,
        SmoothedPathPointSource source)
        : this(
            xMeters,
            yMeters,
            headingRadians,
            unwrappedHeadingRadians,
            arcLengthMeters,
            direction,
            geometricCurvaturePerMeter,
            vehicleCurvaturePerMeter,
            0d,
            bodyClearanceMeters,
            isGearSwitchPoint,
            source)
    {
    }

    /// <summary>创建带有车辆曲率对弧长导数的不可变采样点。</summary>
    public SmoothedPathPoint(
        double xMeters,
        double yMeters,
        double headingRadians,
        double unwrappedHeadingRadians,
        double arcLengthMeters,
        TravelDirection direction,
        double geometricCurvaturePerMeter,
        double vehicleCurvaturePerMeter,
        double vehicleCurvatureDerivativePerSquareMeter,
        double bodyClearanceMeters,
        bool isGearSwitchPoint,
        SmoothedPathPointSource source)
    {
        X = xMeters;
        Y = yMeters;
        Heading = headingRadians;
        UnwrappedHeading = unwrappedHeadingRadians;
        ArcLength = arcLengthMeters;
        Direction = direction;
        GeometricCurvature = geometricCurvaturePerMeter;
        VehicleCurvature = vehicleCurvaturePerMeter;
        VehicleCurvatureDerivative = vehicleCurvatureDerivativePerSquareMeter;
        BodyClearance = bodyClearanceMeters;
        IsGearSwitchPoint = isGearSwitchPoint;
        Source = source;
    }

    /// <summary>世界 X 坐标，单位 m。</summary>
    public double X { get; }

    /// <summary>世界 Y 坐标，单位 m。</summary>
    public double Y { get; }

    /// <summary>归一化的车辆航向，单位 rad。</summary>
    public double Heading { get; }

    /// <summary>连续展开的车辆航向，单位 rad。</summary>
    public double UnwrappedHeading { get; }

    /// <summary>从完整路径起点累计的弧长，单位 m。</summary>
    public double ArcLength { get; }

    /// <summary>该点所在连续方向段的行驶方向。</summary>
    public TravelDirection Direction { get; }

    /// <summary>按几何弧长计算的有符号路径曲率，单位 1/m。</summary>
    public double GeometricCurvature { get; }

    /// <summary>车辆模型使用的有符号曲率，单位 1/m。</summary>
    public double VehicleCurvature { get; }

    /// <summary>车辆曲率对弧长的导数 dκ/ds，单位 1/m²。</summary>
    public double VehicleCurvatureDerivative { get; }

    /// <summary>扩大车体后的保守净空下界，单位 m。</summary>
    public double BodyClearance { get; }

    /// <summary>该点是否为新方向段开始的换向点。</summary>
    public bool IsGearSwitchPoint { get; }

    /// <summary>该点在平滑流程中的来源。</summary>
    public SmoothedPathPointSource Source { get; }
}
