
     hf                     2    d Z ddlmZmZmZ  G d de      Zy)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[y)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``.

    c           	          t        j                  d      | _        t        j                  | j                  ||||||       y )Nzcairo_matrix_t *)r   new_pointerr   cairo_matrix_init)selfxxyxxyyyx0y0s          l/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/cairocffi/matrix.py__init__zMatrix.__init__'   s1     23r2r2r2F    c                 T     |        }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>   s8     mm??r   c                 :     t        |       | j                          S )z!Return a new copy of this matrix.)typer   r   s    r   copyzMatrix.copyG   s    tDz4==?++r   c                 4    t        | j                  d|         S )N)r   r   r   r   r   r   getattrr
   )r   indexs     r   __getitem__zMatrix.__getitem__K   s     MM?FH 	Hr   c                 4    t        | j                               S N)iterr   r!   s    r   __iter__zMatrix.__iter__O   s    DMMO$$r   c                 D    | j                         |j                         k(  S r)   r   r   others     r   __eq__zMatrix.__eq__R       }}%.."222r   c                 D    | j                         |j                         k7  S r)   r-   r.   s     r   __ne__zMatrix.__ne__U   r1   r   c                 Z    t        |       }d|j                  g| j                         z  S )Nz%s(%g, %g, %g, %g, %g, %g))r    __name__r   )r   class_s     r   __repr__zMatrix.__repr__X   s-    d+__/t}}/1 	1r   c                     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   r/   ress      r   multiplyzMatrix.multiply]   s1     h##LL$--	9
r   c                 F    t        j                  | j                  ||       y)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                 N    ||}t        j                  | j                  ||       y)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7r   c                 D    t        j                  | j                  |       y)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    * 	!!$--9r   c                 T    t        t        j                  | j                               y)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                 F    | j                         }|j                          |S )zReturn the inverse of this matrix. See :meth:`invert`.

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

        )r"   rK   )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   cairo_matrix_transform_pointr
   tuple)r   xyr   s       r   transform_pointzMatrix.transform_point   s@     WW[1a&)**4=="q&"q&IRy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.

        rP   rQ   r   )r   r	   r   cairo_matrix_transform_distancer
   rS   )r   dxdyr   s       r   transform_distancezMatrix.transform_distance   s@    . WW[2r(+--dmmR!VR!VLRyr   c                 ,     t         fd fdd      S )Nc                 0    t        | j                        S r)   r$   )r   names    r   <lambda>z,Matrix._component_property.<locals>.<lambda>   s    5 r   c                 2    t        | j                  |      S r)   )setattrr
   )r   valuer^   s     r   r_   z,Matrix._component_property.<locals>.<lambda>   s    tU C r   z8Read-write attribute access to a single float component.)doc)property)r^   s   `r   _component_propertyzMatrix._component_property   s    5CJL 	Lr   r   r   r   r   r   r   )r   rQ   rQ   r   rQ   rQ   r)   )r5   
__module____qualname____doc__r   classmethodr   r   r"   r'   r+   r0   r3   r7   r;   __mul__r@   rE   rH   rK   rN   rV   r[   re   r   r   r   r   r   r    r   r   r   r      s    .G  $@,H%331
	 G<&80:.@	6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      s    	 ( 'kV kr   