using System;
using System.Numerics;

namespace NavisworksTransport.Utils.CoordinateSystem
{
    /// <summary>
    /// Rail 路径在 Canonical Space 中的局部坐标系。
    /// Forward 沿路径前进方向，Normal 表示安装法向，Lateral 由二者叉乘确定。
    /// </summary>
    public sealed class RailLocalFrame
    {
        public RailLocalFrame(Vector3 forward, Vector3 lateral, Vector3 normal)
        {
            Forward = Normalize(forward, nameof(forward));
            Lateral = Normalize(lateral, nameof(lateral));
            Normal = Normalize(normal, nameof(normal));
        }

        public Vector3 Forward { get; }
        public Vector3 Lateral { get; }
        public Vector3 Normal { get; }

        private static Vector3 Normalize(Vector3 value, string name)
        {
            if (value.LengthSquared() < 1e-12f)
            {
                throw new ArgumentException("局部坐标轴长度不能为零。", name);
            }

            return Vector3.Normalize(value);
        }
    }
}
