Matrix.h

#pragma once


namespace Robotics
{
    ref class Vector;


    /// 行列
    public ref class Matrix
    {
    // Construction --------------------------------------------------------
    public:
        Matrix( Matrix^ other );
        Matrix( int row, int column );


    // Operation -----------------------------------------------------------
    public:
        void SetSize( int row, int column );

        void UnitMatrix();
        void ZeroMatrix();

        Matrix^ TransposedMatrix();
        bool InverseMatrix( Matrix^% result );

        bool IsUnitMatrix( double precision );
        bool IsZeroMatrix();
        bool IsOrthogonalMatrix( double precision );

        virtual System::String^ ToString() override;

    private:
        void SecureDomain( int row );

        bool LuDecomposition( array< int >^% informationToChangeRow );
        array< double >^ GetComponentWithMaximumAbsoluteValue();

        void RemoveErrorComponent();

        bool IsEqualSize( Matrix^ obj );
        bool IsSquareMatrix();


    // Overload ------------------------------------------------------------
    public:
        Matrix^ operator+=( Matrix^ obj );
        Matrix^ operator-=( Matrix^ obj );
        Matrix^ operator*=( double val );
        Matrix^ operator*=( Matrix^ obj );

        virtual bool Equals( Matrix^ obj );
        virtual bool Equals( Matrix^ obj, double precision );

        static bool operator==( Matrix^ left, Matrix^ right );
        static bool operator!=( Matrix^ left, Matrix^ right );

        static Matrix^ operator+( Matrix^ left, Matrix^ right );
        static Matrix^ operator-( Matrix^ left, Matrix^ right );

        static Vector^ operator*( Matrix^ matrix, Vector^ vector );
        static Vector^ operator*( Vector^ vector, Matrix^ matrix );
        static Matrix^ operator*( Matrix^ left, Matrix^ right );


        /// @note
        /// インスタンスとハンドルを混同する恐れがあるため、
        /// 代入演算は多重定義していない。


    // Attribute ===========================================================
    private:
        array< Vector^ >^ m_rowVectors;    ///< 行ベクトル


    // static
        literal double Tolerance = 1.0E-8;    ///< 許容誤差


    // Property ------------------------------------------------------------
    public:
        /// Indexer
        property Vector^ default[ int ]
        {
            Vector^ get( int index );
        }

        /// 行数
        property int Row
        {
            int get()
            {
                return m_rowVectors->Length;
            }
        }

        /// 列数
        property int Column
        {
            int get();
        }
    };
}

// [ Reference ]「数値計算以前」Yamada.K ( http://www.asahi-net.or.jp/~uc3k-ymd/index.html )