§
    eÎj?   ã                   óf   — d Z ddlmZmZmZmZ ddlZddlZg d¢Z	d„ Z
d„ Zdd	„Zdd„Zdd„Zdd„ZdS )zBAffine transforms, both in general and specific, named transforms.é    )ÚcosÚpiÚsinÚtanN)Úaffine_transformÚrotateÚscaleÚskewÚ	translatec                 óV  ‡‡‡‡‡‡‡	‡
‡‡‡‡‡— t          |¦  «        dk    r!dŠ|\  ŠŠŠŠŠŠ| j        rdŠdŠdxŠxŠxŠ	xŠ
Šn=t          |¦  «        dk    rdŠ|\  ŠŠŠŠŠŠŠ	Š
ŠŠŠŠ| j        sdŠnt          d¦  «        ‚ˆˆˆˆˆˆˆ	ˆ
ˆˆˆˆˆfd„}t          j        | |‰dk    ¬	¦  «        S )
a$  Return a transformed geometry using an affine transformation matrix.

    The coefficient matrix is provided as a list or tuple with 6 or 12 items
    for 2D or 3D transformations, respectively.

    For 2D affine transformations, the 6 parameter matrix is::

        [a, b, d, e, xoff, yoff]

    which represents the augmented matrix::

        [x']   / a  b xoff \ [x]
        [y'] = | d  e yoff | [y]
        [1 ]   \ 0  0   1  / [1]

    or the equations for the transformed coordinates::

        x' = a * x + b * y + xoff
        y' = d * x + e * y + yoff

    For 3D affine transformations, the 12 parameter matrix is::

        [a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]

    which represents the augmented matrix::

        [x']   / a  b  c xoff \ [x]
        [y'] = | d  e  f yoff | [y]
        [z']   | g  h  i zoff | [z]
        [1 ]   \ 0  0  0   1  / [1]

    or the equations for the transformed coordinates::

        x' = a * x + b * y + c * z + xoff
        y' = d * x + e * y + f * z + yoff
        z' = g * x + h * y + i * z + zoff
    é   é   é   ç      ð?ç        é   z,'matrix' expects either 6 or 12 coefficientsc                 ój  •— ‰dk    rB| j         \  }}‰|z  ‰	|z  z   ‰z   }‰|z  ‰|z  z   ‰z   }t          j        ||g¦  «        j         }ni‰dk    rc| j         \  }}}‰|z  ‰	|z  z   ‰
|z  z   ‰z   }‰|z  ‰|z  z   ‰|z  z   ‰z   }‰|z  ‰|z  z   ‰|z  z   ‰z   }t          j        |||g¦  «        j         }|S )Nr   r   )ÚTÚnpÚstack)ÚcoordsÚxÚyÚxpÚypÚresultÚzÚzpÚaÚbÚcÚdÚeÚfÚgÚhÚiÚndimÚxoffÚyoffÚzoffs           €€€€€€€€€€€€€ú`/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/shapely/affinity.pyÚ_affine_coordsz(affine_transform.<locals>._affine_coordsH   sí   ø€ ð
 �1Š9ˆ9Ø”8‰DˆAˆqØ�Q‘˜˜Q™‘ Ñ%ˆBØ�Q‘˜˜Q™‘ Ñ%ˆBÝ”X˜r 2˜hÑ'Ô'Ô)ˆFˆFØ�QŠYˆYØ”h‰GˆAˆq�!Ø�Q‘˜˜Q™‘  Q¡Ñ&¨Ñ-ˆBØ�Q‘˜˜Q™‘  Q¡Ñ&¨Ñ-ˆBØ�Q‘˜˜Q™‘  Q¡Ñ&¨Ñ-ˆBÝ”X˜r 2 r˜lÑ+Ô+Ô-ˆFØˆó    )Ú	include_z)ÚlenÚhas_zÚ
ValueErrorÚshapelyÚ	transform)ÚgeomÚmatrixr-   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   s      @@@@@@@@@@@@@r,   r   r      s.  øøøøøøøøøøøøø€ õL ˆ6�{„{�aÒÐØˆØ!'Ñˆˆ1ˆa��D˜$ØŒ:ð 	'ØˆDØˆAØ#&Ð&ˆAÐ&�Ð&�AÐ&˜˜DøÝ	ˆV‰Œ˜Ò	Ð	ØˆØ6<Ñ3ˆˆ1ˆa��A�q˜!˜Q  4¨¨tØŒzð 	ØˆDøåÐGÑHÔHÐHðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð õ$ Ô˜T >¸TÀQºYÐGÑGÔGÐGr.   c                 ó¢  — |dk    r| j         \  }}}}||z   dz  ||z   dz  f}nc|dk    r| j        j        d         }nJt          |t          ¦  «        rt          d|›d�¦  «        ‚t          |dd¦  «        d	k    r|j        d         }t          |¦  «        d
vrt          d¦  «        ‚|dk    r
|dd…         S t          |¦  «        dk    r|dz   S |S )a5  Return interpreted coordinate tuple for origin parameter.

    This is a helper function for other transform functions.

    The point of origin can be a keyword 'center' for the 2D bounding box
    center, 'centroid' for the geometry's 2D centroid, a Point object or a
    coordinate tuple (x0, y0, z0).
    Úcenterg       @Úcentroidr   z'origin' keyword z is not recognizedÚ	geom_typeNÚPoint)r   r   z8Expected number of items in 'origin' to be either 2 or 3r   )r   )Úboundsr9   r   Ú
isinstanceÚstrr2   Úgetattrr0   )r5   Úoriginr(   ÚminxÚminyÚmaxxÚmaxys          r,   Úinterpret_originrE   ]   s  € ð �ÒÐà!%¤Ñˆˆd�D˜$Ø˜$‘; #Ñ%¨¨t©°sÑ':Ð;ˆˆØ	�:Ò	Ð	Ø”Ô% aÔ(ˆˆÝ	�F�CÑ	 Ô	 ð "ÝÐI¨VÐIÐIÐIÑJÔJÐJÝ	�˜ dÑ	+Ô	+¨wÒ	6Ð	6Ø”˜qÔ!ˆõ ˆ6�{„{˜&Ð Ð ÝÐSÑTÔTÐTØˆq‚y€yØ�a˜�cŒ{Ðåˆv‰;Œ;˜!ÒÐØ˜F‘?Ð"àˆMr.   r8   Fc                 óX  — | j         r| S |s|t          z  dz  }t          |¦  «        }t          |¦  «        }t	          |¦  «        dk     rd}t	          |¦  «        dk     rd}t          | |d¦  «        \  }}|| d||dddd|||z  z
  ||z  z   |||z  z
  ||z  z
  df}t          | |¦  «        S )aå  Return a rotated geometry on a 2D plane.

    The angle of rotation can be specified in either degrees (default) or
    radians by setting ``use_radians=True``. Positive angles are
    counter-clockwise and negative are clockwise rotations.

    The point of origin can be a keyword 'center' for the bounding box
    center (default), 'centroid' for the geometry's centroid, a Point object
    or a coordinate tuple (x0, y0).

    The affine transformation matrix for 2D rotation is:

      / cos(r) -sin(r) xoff \
      | sin(r)  cos(r) yoff |
      \   0       0      1  /

    where the offsets are calculated from the origin Point(x0, y0):

        xoff = x0 - x0 * cos(r) + y0 * sin(r)
        yoff = y0 - x0 * sin(r) - y0 * cos(r)
    ç     €f@çVçž¯²<r   r   r   )Úis_emptyr   r   r   ÚabsrE   r   )	r5   Úangler@   Úuse_radiansÚcospÚsinpÚx0Úy0r6   s	            r,   r   r   ~   sÜ   € ð, „}ð ØˆØð #Ø�‘
˜UÑ"ˆÝˆu‰:Œ:€DÝˆu‰:Œ:€DÝ
ˆ4�y„y�7ÒÐØˆÝ
ˆ4�y„y�7ÒÐØˆÝ˜d F¨AÑ.Ô.�F€Bˆð �T�E˜3Ø�D˜#Ø�3˜Ø�2˜‘9‰n˜r D™yÑ(¨"¨r°D©y©.¸2À¹9Ñ*DÀcðK€Fõ
 ˜D &Ñ)Ô)Ð)r.   r   c                 óž   — | j         r| S t          | |d¦  «        \  }}}|ddd|ddd||||z  z
  |||z  z
  |||z  z
  f}t          | |¦  «        S )a¶  Return a scaled geometry, scaled by factors along each dimension.

    The point of origin can be a keyword 'center' for the 2D bounding box
    center (default), 'centroid' for the geometry's 2D centroid, a Point
    object or a coordinate tuple (x0, y0, z0).

    Negative scale factors will mirror or reflect coordinates.

    The general 3D affine transformation matrix for scaling is:

        / xfact  0    0   xoff \
        |   0  yfact  0   yoff |
        |   0    0  zfact zoff |
        \   0    0    0     1  /

    where the offsets are calculated from the origin Point(x0, y0, z0):

        xoff = x0 - x0 * xfact
        yoff = y0 - y0 * yfact
        zoff = z0 - z0 * zfact
    r   r   )rI   rE   r   )	r5   ÚxfactÚyfactÚzfactr@   rO   rP   Úz0r6   s	            r,   r	   r	   ©   sz   € ð, „}ð ØˆÝ! $¨°Ñ2Ô2�J€BˆˆBð �S˜#Ø�5˜#Ø�3˜Ø�2˜‘:‰o˜r B¨¡J™°°R¸%±Z±ðA€Fõ
 ˜D &Ñ)Ô)Ð)r.   r   c                 óP  — | j         r| S |s|t          z  dz  }|t          z  dz  }t          |¦  «        }t          |¦  «        }t          |¦  «        dk     rd}t          |¦  «        dk     rd}t	          | |d¦  «        \  }}d|d|ddddd| |z  | |z  df}	t          | |	¦  «        S )a—  Return a skewed geometry, sheared by angles along x and y dimensions.

    The shear angle can be specified in either degrees (default) or radians
    by setting ``use_radians=True``.

    The point of origin can be a keyword 'center' for the bounding box
    center (default), 'centroid' for the geometry's centroid, a Point object
    or a coordinate tuple (x0, y0).

    The general 2D affine transformation matrix for skewing is:

        /   1    tan(xs) xoff \
        | tan(ys)  1     yoff |
        \   0      0       1  /

    where the offsets are calculated from the origin Point(x0, y0):

        xoff = -y0 * tan(xs)
        yoff = -x0 * tan(ys)
    rG   rH   r   r   r   )rI   r   r   rJ   rE   r   )
r5   ÚxsÚysr@   rL   ÚtanxÚtanyrO   rP   r6   s
             r,   r
   r
   Ì   sÏ   € ð* „}ð ØˆØð Ø•"‰W�u‰_ˆØ•"‰W�u‰_ˆÝˆr‰7Œ7€DÝˆr‰7Œ7€DÝ
ˆ4�y„y�7ÒÐØˆÝ
ˆ4�y„y�7ÒÐØˆÝ˜d F¨AÑ.Ô.�F€Bˆð �4˜Ø�C˜Ø�3˜Øˆc�D‰j˜2˜# ™* cð+€Fõ
 ˜D &Ñ)Ô)Ð)r.   c                 óP   — | j         r| S ddddddddd|||f}t          | |¦  «        S )zôReturn a translated geometry shifted by offsets along each dimension.

    The general 3D affine transformation matrix for translation is:

        / 1  0  0 xoff \
        | 0  1  0 yoff |
        | 0  0  1 zoff |
        \ 0  0  0   1  /
    r   r   )rI   r   )r5   r)   r*   r+   r6   s        r,   r   r   ÷   sJ   € ð „}ð Øˆð �3˜Ø�3˜Ø�3˜Ø�D˜$ð €Fõ
 ˜D &Ñ)Ô)Ð)r.   )r8   F)r   r   r   r8   )r   r   r8   F)r   r   r   )Ú__doc__Úmathr   r   r   r   Únumpyr   r3   Ú__all__r   rE   r   r	   r
   r   © r.   r,   ú<module>ra      sÒ   ðØ HÐ Hà "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð à €€€à
FÐ
FÐ
F€ðNHð NHð NHðbð ð ðB(*ð (*ð (*ð (*ðV *ð  *ð  *ð  *ðF(*ð (*ð (*ð (*ðV*ð *ð *ð *ð *ð *r.   