using Quaternion = UnityEngine.Quaternion;
namespace Passer.LinearAlgebra {

    public class QuaternionOf<T> {
        public T x;
        public T y;
        public T z;
        public T w;

        public QuaternionOf(T x, T y, T z, T w) {
            this.x = x;
            this.y = y;
            this.z = z;
            this.w = w;
        }

        public static Matrix2 ToRotationMatrix(Quaternion q) {
            float w = q.x, x = q.y, y = q.z, z = q.w;

            float[,] result = new float[,]
            {
                { 1 - 2 * (y * y + z * z), 2 * (x * y - w * z), 2 * (x * z + w * y) },
                { 2 * (x * y + w * z), 1 - 2 * (x * x + z * z), 2 * (y * z - w * x) },
                { 2 * (x * z - w * y), 2 * (y * z + w * x), 1 - 2 * (x * x + y * y) }
            };
            return new Matrix2(result);
        }
    }

    // public class Quaternion : QuaternionOf<float> {
    //     public Quaternion(float x, float y, float z, float w) : base(x, y, z, w) { }
    // }
}