
    jf                     :    d Z ddlmZmZmZ  G d de          ZdS )z
    cairocffi.matrix
    ~~~~~~~~~~~~~~~~

    Transformation matrices.

    :copyright: Copyright 2013-2019 by Simon Sapin
    :license: BSD, see LICENSE for details.

   )_check_statuscairoffic                      e Zd ZdZddZed             Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd ZeZd ZddZd Zd Zd Zd Zd Zd Z ed          Z ed          Z ed          Z ed          Z ed          Z ed          Z[dS )Matrixa  A 2D transformation matrix.

    Matrices are used throughout cairo to convert between
    different coordinate spaces.
    A :class:`Matrix` holds an affine transformation,
    such as a scale, rotation, shear, or a combination of these.
    The transformation of a point (x,y) is given by::

        x_new = xx * x + xy * y + x0
        y_new = yx * x + yy * y + y0

    The current transformation matrix of a :class:`Context`,
    represented as a :class:`Matrix`,
    defines the transformation from user-space coordinates
    to device-space coordinates.
    See :meth:`Context.get_matrix` and :meth:`Context.set_matrix`.

    The default values produce an identity matrix.

    Matrices can be compared with ``m1 == m2`` and ``m2 != m2``
    as well as multiplied with ``m3 = m1 * m2``.

    r       c           	      v    t          j        d          | _        t          j        | j        ||||||           d S )Nzcairo_matrix_t *)r   new_pointerr   cairo_matrix_init)selfxxyxxyyyx0y0s          W/home/ubuntu/budget-transfer-bot/.venv/lib/python3.11/site-packages/cairocffi/matrix.py__init__zMatrix.__init__'   s9     233r2r2r2FFFFF    c                 N     |             }t          j        |j        |           |S )a  Return a new :class:`Matrix` for a transformation
        that rotates by ``radians``.

        :type radians: float
        :param radians:
            Angle of rotation, in radians.
            The direction of rotation is defined such that
            positive angles rotate in the direction
            from the positive X axis toward the positive Y axis.
            With the default axis orientation of cairo,
            positive angles rotate in a clockwise direction.

        )r   cairo_matrix_init_rotater   )clsradiansresults      r   init_rotatezMatrix.init_rotate+   s)     &v@@@r   c                 \    | j         }|j        |j        |j        |j        |j        |j        fS )uu   Return all of the matrix’s components.

        :returns: A ``(xx, yx, xy, yy, x0, y0)`` tuple of floats.

        )r   r   r   r   r   r   r   )r   ptrs     r   as_tuplezMatrix.as_tuple>   s*     m??r   c                 J     t          |           |                                  S )z!Return a new copy of this matrix.)typer   r   s    r   copyzMatrix.copyG   s    tDzz4==??++r   c                 8    t          | j        d|                   S )N)r   r   r   r   r   r   getattrr   )r   indexs     r   __getitem__zMatrix.__getitem__K   s$    M?FH H 	Hr   c                 D    t          |                                           S N)iterr   r"   s    r   __iter__zMatrix.__iter__O   s    DMMOO$$$r   c                 V    |                                  |                                 k    S r*   r   r   others     r   __eq__zMatrix.__eq__R       }}%.."2"222r   c                 V    |                                  |                                 k    S r*   r.   r/   s     r   __ne__zMatrix.__ne__U   r2   r   c                 `    t          |           }d|j        g|                                 R z  S )Nz%s(%g, %g, %g, %g, %g, %g))r!   __name__r   )r   class_s     r   __repr__zMatrix.__repr__X   s2    d+_/t}}//1 	1r   c                 l    t                      }t          j        |j        | j        |j                   |S )zMultiply with another matrix
        and return the result as a new :class:`Matrix` object.
        Same as ``self * other``.

        )r   r   cairo_matrix_multiplyr   )r   r0   ress      r   multiplyzMatrix.multiply]   s4     hh#L$-	9 	9 	9
r   c                 <    t          j        | j        ||           dS )a  Applies a translation by ``tx``, ``ty``
        to the transformation in this matrix.

        The effect of the new transformation is to
        first translate the coordinates by ``tx`` and ``ty``,
        then apply the original transformation to the coordinates.

        .. note::
            This changes the matrix in-place.

        :param tx: Amount to translate in the X direction.
        :param ty: Amount to translate in the Y direction.
        :type tx: float
        :type ty: float

        N)r   cairo_matrix_translater   )r   txtys      r   	translatezMatrix.translatej   s!    " 	$T]B;;;;;r   Nc                 D    ||}t          j        | j        ||           dS )aM  Applies scaling by ``sx``, ``sy``
        to the transformation in this matrix.

        The effect of the new transformation is to
        first scale the coordinates by ``sx`` and ``sy``,
        then apply the original transformation to the coordinates.

        If ``sy`` is omitted, it is the same as ``sx``
        so that scaling preserves aspect ratios.

        .. note::
            This changes the matrix in-place.

        :param sx: Scale factor in the X direction.
        :param sy: Scale factor in the Y direction.
        :type sx: float
        :type sy: float

        N)r   cairo_matrix_scaler   )r   sxsys      r   scalezMatrix.scale}   s+    ( :B B77777r   c                 :    t          j        | j        |           dS )a  Applies a rotation by ``radians``
        to the transformation in this matrix.

        The effect of the new transformation is to
        first rotate the coordinates by ``radians``,
        then apply the original transformation to the coordinates.

        .. note::
            This changes the matrix in-place.

        :type radians: float
        :param radians:
            Angle of rotation, in radians.
            The direction of rotation is defined such that positive angles
            rotate in the direction from the positive X axis
            toward the positive Y axis.
            With the default axis orientation of cairo,
            positive angles rotate in a clockwise direction.

        N)r   cairo_matrix_rotater   )r   r   s     r   rotatezMatrix.rotate   s    * 	!$-99999r   c                 R    t          t          j        | j                             dS )au  Changes matrix to be the inverse of its original value.
        Not all transformation matrices have inverses;
        if the matrix collapses points together (it is degenerate),
        then it has no inverse and this function will fail.

        .. note::
            This changes the matrix in-place.

        :raises: :exc:`CairoError` on degenerate matrices.

        N)r   r   cairo_matrix_invertr   r"   s    r   invertzMatrix.invert   s%     	e/>>?????r   c                 V    |                                  }|                                 |S )zReturn the inverse of this matrix. See :meth:`invert`.

        :raises: :exc:`CairoError` on degenerate matrices.
        :returns: A new :class:`Matrix` object.

        )r#   rL   )r   matrixs     r   invertedzMatrix.inverted   s#     r   c                     t          j        d||g          }t          j        | j        |dz   |dz              t          |          S )zTransforms the point ``(x, y)`` by this matrix.

        :param x: X position.
        :param y: Y position.
        :type x: float
        :type y: float
        :returns: A ``(new_x, new_y)`` tuple of floats.

        	double[2]r   r   )r   r
   r   cairo_matrix_transform_pointr   tuple)r   xyr   s       r   transform_pointzMatrix.transform_point   sD     W[1a&))*4="q&"q&IIIRyyr   c                     t          j        d||g          }t          j        | j        |dz   |dz              t          |          S )a]  Transforms the distance vector ``(dx, dy)`` by this matrix.
        This is similar to :meth:`transform_point`
        except that the translation components of the transformation
        are ignored.
        The calculation of the returned vector is as follows::

            dx2 = dx1 * xx + dy1 * xy
            dy2 = dx1 * yx + dy1 * yy

        Affine transformations are position invariant,
        so the same vector always transforms to the same vector.
        If ``(x1, y1)`` transforms to ``(x2, y2)``
        then ``(x1 + dx1, y1 + dy1)`` will transform
        to ``(x1 + dx2, y1 + dy2)`` for all values of ``x1`` and ``x2``.

        :param dx: X component of a distance vector.
        :param dy: Y component of a distance vector.
        :type dx: float
        :type dy: float
        :returns: A ``(new_dx, new_dy)`` tuple of floats.

        rQ   r   r   )r   r
   r   cairo_matrix_transform_distancer   rS   )r   dxdyr   s       r   transform_distancezMatrix.transform_distance   sD    . W[2r(++-dmR!VR!VLLLRyyr   c                 4     t           fd fdd          S )Nc                 .    t          | j                  S r*   r%   )r   names    r   <lambda>z,Matrix._component_property.<locals>.<lambda>   s    55 r   c                 0    t          | j        |          S r*   )setattrr   )r   valuer^   s     r   r_   z,Matrix._component_property.<locals>.<lambda>   s    tU C C r   z8Read-write attribute access to a single float component.)doc)property)r^   s   `r   _component_propertyzMatrix._component_property   s9    5555CCCCJL L L 	Lr   r   r   r   r   r   r   )r   r   r   r   r   r   r*   )r6   
__module____qualname____doc__r   classmethodr   r   r#   r(   r,   r1   r4   r8   r<   __mul__rA   rF   rI   rL   rO   rV   r[   re   r   r   r   r   r   r    r   r   r   r      s        .G G G G   [$@ @ @, , ,H H H% % %3 3 33 3 31 1 1
	 	 	 G< < <&8 8 8 80: : :.@ @ @	 	 	    6L L L 
	T	"	"B		T	"	"B		T	"	"B		T	"	"B		T	"	"B		T	"	"Br   r   N)rh    r   r   r   objectr   rk   r   r   <module>rn      sm   	 	 ( ' ' ' ' ' ' ' ' 'k k k k kV k k k k kr   