o
    @@i                     @   s*   d Z ddlZddlmZ G dd dZdS )z
In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers,
symbols, or expressions, arranged in rows and columns.
    N)Decimalc                   @   s   e Zd ZdZdd Zi fddZdeje fddZ	d	d
 Z
dedededejeeef fddZdefddZedddZededededededefddZd ddZdS )!Matrixu[  
    In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns.
    Provided that they have the same size (each matrix has the same number of rows and the same number of columns as the other),
    two matrices can be added or subtracted element by element (see conformable matrix).

    The rule for matrix multiplication, however, is that two matrices can be multiplied only when the number of columns
    in the first equals the number of rows in the second (i.e., the inner dimensions are the same, n for an (m×n)-matrix times an (n×p)-matrix,
    resulting in an (m×p)-matrix). There is no product the other way round—a first hint that matrix multiplication is not commutative.
    Any matrix can be multiplied element-wise by a scalar from its associated field.
    c                 C   s   g g g g| _ dS )z)
        Initialize a new Matrix
        Nmtxself r   ]/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/borb/pdf/canvas/geometry/matrix.py__init__   s   zMatrix.__init__c                 C   s   t  }| jd d | jd d | jd d g| jd d | jd d | jd d g| jd d | jd d | jd d gg|_|S )Nr         )r   r   )r   memodictmr   r   r	   __deepcopy__&   s   &&&zMatrix.__deepcopy__returnc                 C   s
   | j | S )Nr   )r   itemr   r   r	   __getitem__/   s   
zMatrix.__getitem__c                 C   s   dt | jd d t | jd d t | jd d t | jd d t | jd d t | jd d t | jd d t | jd d t | jd d f	 S )Nz$[[%f %f %f]
 [%f %f %f]
 [%f %f %f]]r   r   r   )floatr   r   r   r   r	   __str__2   s   zMatrix.__str__xyzc                 C   s   || d d  || d d   || d d   }|| d d  || d d   || d d   }|| d d  || d d   || d d   }|||fS )au  
        This method calculates the dot-product of this Matrix
        with an input vector (represented by 3 input Decimal objects)
        and returns the result
        :param x:   the first component of the vector
        :param y:   the second component of the vector
        :param z:   the third component of the vector
        :return:    the result vector
        r   r   r   r   )r   r   r   r   x2y2z2r   r   r	   crossC   s   000
zMatrix.crossc                 C   s   | j d d | j d d | j d d  | j d d | j d d    | j d d | j d d | j d d  | j d d | j d d     | j d d | j d d | j d d  | j d d | j d d     S )a  
        In linear algebra, the determinant is a scalar value that can be computed from the elements of a square matrix
        and encodes certain properties of the linear transformation described by the matrix.
        The determinant of a matrix A is denoted det(A), det A, or |A|.
        Geometrically, it can be viewed as the volume scaling factor of the linear transformation described by the matrix.
        This is also the signed volume of the n-dimensional parallelepiped spanned by the column or row vectors of the matrix.
        The determinant is positive or negative according to whether the linear transformation preserves or reverses the orientation of a real vector space.
        :return:    the determinant of this Matrix
        r   r   r   r   r   r   r   r	   determinantT   s   666zMatrix.determinantc                  C   sL   t  } tdtdtdgtdtdtdgtdtdtdgg| _| S )z
        The identity matrix In of size n is the n-by-n matrix in which all the elements on the main diagonal
        are equal to 1 and all other elements are equal to 0.
        :return:    the identity Matrix
        r   r   r   r   r   )r   r   r   r	   identity_matrixg   s   zMatrix.identity_matrixabcdefc                 C   s4   t  }| |tdg||tdg||tdgg|_|S )ay  
        This method returns the matrix [[a, b, 0], [c, d, 0], [e, f, 1]]
        :param a:   the component at (0, 0)
        :param b:   the component at (0, 1)
        :param c:   the component at (1, 0)
        :param d:   the component at (1, 1)
        :param e:   the component at (2, 0)
        :param f:   the component at (2, 1)
        :return:    the Matrix
        r   r   r   )r   r    r!   r"   r#   r$   r   r   r   r	   matrix_from_six_valuesv   s   *zMatrix.matrix_from_six_valuesc              	   C   s   t dt dt dgt dt dt dgt dt dt dgg}tdD ]&}tdD ]}tdD ]}|| |  | j| | |j| |  7  < q0q*q$t }||_|S )z
        This function multiplies this Matrix with another Matrix, returning the result
        :param y:   the Matrix to multiply by
        :return:    the resulting Matrix
        r      )r   ranger   r   )r   r   m_valsijkr   r   r   r	   mul   s   .z
Matrix.mulN)r   r   )r   r   r   r   )__name__
__module____qualname____doc__r
   r   typingListr   r   r   Tupler   r   staticmethodr   r%   r,   r   r   r   r	   r      sB    
	
r   )r0   r1   decimalr   r   r   r   r   r	   <module>   s   