3
|ўQ                 @   s,   d Z ddlmZmZmZ G dd deZdS )z
    cairocffi.matrix
    ~~~~~~~~~~~~~~~~

    Transformation matrices.

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

   )fficairo_check_statusc               @   s   e Zd ZdZd/ddZedd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd ZeZdd Zd0ddZdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zed)Zed*Zed+Zed,Zed-Zed.Z[dS )1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             C   s(   t jd| _tj| j|||||| d S )Nzcairo_matrix_t *)r   new_pointerr   Zcairo_matrix_init)selfxxyxxyyyx0y0 r   P/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/cairocffi/matrix.py__init__(   s    zMatrix.__init__c             C   s   |  }t j|j| |S )a  Return a new :class:`Matrix` for a transformation
        that rotates by :obj:`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   Zcairo_matrix_init_rotater   )clsradiansresultr   r   r   init_rotate,   s    zMatrix.init_rotatec             C   s"   | 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	   ptrr   r   r   as_tuple?   s    zMatrix.as_tuplec             C   s   t | | j  S )z!Return a new copy of this matrix.)typer   )r	   r   r   r   copyH   s    zMatrix.copyc             C   s   t | jd| S )Nr
   r   r   r   r   r   )r
   r   r   r   r   r   )getattrr   )r	   indexr   r   r   __getitem__L   s    zMatrix.__getitem__c             C   s   t | j S )N)iterr   )r	   r   r   r   __iter__P   s    zMatrix.__iter__c             C   s   | j  |j  kS )N)r   )r	   otherr   r   r   __eq__S   s    zMatrix.__eq__c             C   s   | j  |j  kS )N)r   )r	   r    r   r   r   __ne__V   s    zMatrix.__ne__c             C   s   t | }d|jf| j   S )Nz%s(%g, %g, %g, %g, %g, %g))r   __name__r   )r	   class_r   r   r   __repr__Y   s    zMatrix.__repr__c             C   s   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   Zcairo_matrix_multiplyr   )r	   r    resr   r   r   multiply^   s    zMatrix.multiplyc             C   s   t j| j|| dS )a  Applies a translation by :obj:`tx`, :obj:`ty`
        to the transformation in this matrix.

        The effect of the new transformation is to
        first translate the coordinates by :obj:`tx` and :obj:`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   Zcairo_matrix_translater   )r	   Ztxtyr   r   r   	translatek   s    zMatrix.translateNc             C   s    |dkr|}t j| j|| dS )a_  Applies scaling by :obj:`sx`, :obj:`sy`
        to the transformation in this matrix.

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

        If :obj:`sy` is omitted, it is the same as :obj:`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   Zcairo_matrix_scaler   )r	   ZsxZsyr   r   r   scale~   s    zMatrix.scalec             C   s   t j| j| dS )a  Applies a rotation by :obj:`radians`
        to the transformation in this matrix.

        The effect of the new transformation is to
        first rotate the coordinates by :obj:`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   Zcairo_matrix_rotater   )r	   r   r   r   r   rotate   s    zMatrix.rotatec             C   s   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   Zcairo_matrix_invertr   )r	   r   r   r   invert   s    zMatrix.invertc             C   s   | 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   r,   )r	   Zmatrixr   r   r   inverted   s    zMatrix.invertedc             C   s0   t jd||g}tj| j|d |d  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.

        z	double[2]r   r   )r   r   r   Zcairo_matrix_transform_pointr   tuple)r	   xyr   r   r   r   transform_point   s    
zMatrix.transform_pointc             C   s0   t jd||g}tj| j|d |d  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.

        z	double[2]r   r   )r   r   r   Zcairo_matrix_transform_distancer   r.   )r	   ZdxZdyr   r   r   r   transform_distance   s    zMatrix.transform_distancec                s   t  fdd fddddS )Nc                s   t | j S )N)r   r   )r	   )namer   r   <lambda>   s    z,Matrix._component_property.<locals>.<lambda>c                s   t | j |S )N)setattrr   )r	   value)r3   r   r   r4      s    z8Read-write attribute access to a single float component.)doc)property)r3   r   )r3   r   _component_property   s    

zMatrix._component_propertyr
   r   r   r   r   r   )r   r   r   r   r   r   )N)r#   
__module____qualname____doc__r   classmethodr   r   r   r   r   r!   r"   r%   r'   __mul__r)   r*   r+   r,   r-   r1   r2   r9   r
   r   r   r   r   r   r   r   r   r   r      s6   
	
r   N)r<    r   r   r   objectr   r   r   r   r   <module>   s   