using System;

namespace Spark3D.Algebra3D
{
    public class Matrix3D
    {
        double[,] data = new double[3, 3];

        public Matrix3D()
        {
        }
        public Matrix3D(double[,] _data)
        {
            data = _data;
        }
        void Fill(double val)
        {
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    this[i, j] = val;
        }

        public double this[int i, int j]
        {
            get { return data[i, j]; }
            set { data[i, j] = value; }
        }

        public void PrintMe()
        {
            for (int i = 0; i < 3; i++)
                Console.WriteLine("[{0:0.00}, {1:0.00}, {2:0.00}]", this[i, 0], this[i, 1], this[i, 2]);
            Console.WriteLine("\n");
        }

        // Full matrix multiplication.
        public static Matrix3D operator *(Matrix3D a, Matrix3D b)
        {
            Matrix3D ret = new Matrix3D();
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                {
                    ret[i, j] = 0.0;
                    for (int k = 0; k < 3; k++)
                        ret[i, j] += a[i, k] * b[k, j];
                }
            return ret;
        }

        public static Vector3D operator *(Matrix3D a, Vector3D b)
        {
            Vector3D ret = new Vector3D();
            for (int i = 0; i < 3; i++)
            {
                ret[i] = 0.0;
                for (int j = 0; j < 3; j++)

                    ret[i] += a[i, j] * b[j];
            }
            return ret;
        }
        public static Vector3D operator *(Vector3D a, Matrix3D b)
        {
            Vector3D ret = new Vector3D();
            for (int i = 0; i < 3; i++)
            {
                ret[i] = 0.0;
                for (int j = 0; j < 3; j++)

                    ret[i] += a[i] * b[i, j];
            }
            return ret;
        }

        public static Matrix3D operator +(Matrix3D a, Matrix3D b)
        {
            Matrix3D ret = new Matrix3D();
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    ret[i, j] = a[i, j] + b[i, j];
            return ret;
        }

        public static Matrix3D operator -(Matrix3D a, Matrix3D b)
        {
            Matrix3D ret = new Matrix3D();
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    ret[i, j] = a[i, j] - b[i, j];
            return ret;
        }

    }
}
