§
    ¢”j¸°  ã                   ó>  — d Z ddlmZmZmZ ddlmZ ddlZddlm	Z	 	 ddl
Z
n# eef$ r	 ddlm
Z
 Y nw xY we
j        ZdZ e	dg d	¢¦  «        Zg d
¢ZdWd„Zd„ Z e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        ¬¦  «         e
j        e
j        e
j        e
j        ¬¦  «        d„ ¦   «         ¦   «         ¦   «         Z e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        ¬¦  «         e
j        e
j        e
j        ¬¦  «        dWd„¦   «         ¦   «         ¦   «         ZdZdZe
j        e
j         e
j        e
j        ¦  «         e
j        e
j        e
j        ¬¦  «        d„ ¦   «         ¦   «         ¦   «         ¦   «         Ze
j        e
j         e
j        e
j        ¦  «         e
j        e
j        ¬¦  «        d„ ¦   «         ¦   «         ¦   «         ¦   «         Z d„ Z! e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬¦  «         e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬¦  «        d„ ¦   «         ¦   «         ¦   «         Z"d„ Z# e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        ¬¦  «         e
j        e
j        e
j        e
j        ¬ ¦  «        d!„ ¦   «         ¦   «         ¦   «         Z$d"„ Z%d#„ Z& e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        ¬¦  «         e
j        e
j        e
j        e
j        e
j        e
j        ¬$¦  «        d%„ ¦   «         ¦   «         ¦   «         Z'd&„ Z(d'„ Z)d(„ Z*d)„ Z+d*„ Z,d+„ Z- e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬,¦  «        d-„ ¦   «         Z. e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬.¦  «         e
j        e
j        e
j        e
j        e
j        ¬/¦  «        d0„ ¦   «         ¦   «         ¦   «         Z/d1„ Z0d2„ Z1 e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬3¦  «        d4„ ¦   «         Z2dd5lm3Z3m4Z4m5Z5m6Z6 e3fd6„Z7d7„ Z8d8„ Z9d9„ Z:e
j        e
j         e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬:¦  «        d;„ ¦   «         ¦   «         ¦   «         Z;d<„ Z<d=„ Z=e
j        e
j         e
j        e
j        e
j        e
j        e
j        e
j        e
j        e
j        ¬>¦  «        d?„ ¦   «         ¦   «         ¦   «         Z>d@„ Z?dA„ Z@dB„ ZA e
j        e
j        ¦  «         e
j        e
j        e
j        e
j        e
j        e
j        ¬C¦  «         e
j        e
j        e
j        e
j        ¬D¦  «        dE„ ¦   «         ¦   «         ¦   «         ZBdF„ ZCdG„ ZDdH„ ZEdI„ ZFdJ„ ZGdK„ ZHdL„ ZIdM„ ZJdN„ ZK	 dXdP„ZLdQ„ ZMdR„ ZNdS„ ZOdT„ ZPdU„ ZQeRdVk    r,ddlSZSddlTZT eSjU         eTjV        ¦   «         jW        ¦  «         dS dS )YzNfontTools.misc.bezierTools.py -- tools for working with Bezier path segments.
é    )Ú
calcBoundsÚsectRectÚrectArea)ÚIdentityN)Ú
namedtuple)Úcythong•Ö&è.>ÚIntersection©ÚptÚt1Út2)ÚapproximateCubicArcLengthÚapproximateCubicArcLengthCÚapproximateQuadraticArcLengthÚapproximateQuadraticArcLengthCÚcalcCubicArcLengthÚcalcCubicArcLengthCÚcalcQuadraticArcLengthÚcalcQuadraticArcLengthCÚcalcCubicBoundsÚcalcQuadraticBoundsÚ	splitLineÚsplitQuadraticÚ
splitCubicÚsplitQuadraticAtTÚsplitCubicAtTÚsplitCubicAtTCÚsplitCubicIntoTwoAtTCÚsolveQuadraticÚ
solveCubicÚquadraticPointAtTÚcubicPointAtTÚcubicPointAtTCÚlinePointAtTÚsegmentPointAtTÚlineLineIntersectionsÚcurveLineIntersectionsÚcurveCurveIntersectionsÚsegmentSegmentIntersectionsç{®Gázt?c                 ó`   — t          t          | Ž t          |Ž t          |Ž t          |Ž |¦  «        S )aÄ  Calculates the arc length for a cubic Bezier segment.

    Whereas :func:`approximateCubicArcLength` approximates the length, this
    function calculates it by "measuring", recursively dividing the curve
    until the divided segments are shorter than ``tolerance``.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
        tolerance: Controls the precision of the calcuation.

    Returns:
        Arc length value.
    )r   Úcomplex)Úpt1Úpt2Úpt3Úpt4Ú	tolerances        úi/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/fontTools/misc/bezierTools.pyr   r   8   s1   € õ Ý�ˆ•w �}¥g¨s mµW¸c°]ÀIñô ð ó    c                 ó|   — | d||z   z  z   |z   dz  }||z   |z
  | z
  dz  }| | |z   dz  ||z
  |f|||z   ||z   dz  |ffS )Né   g      À?ç      à?© )Úp0Úp1Úp2Úp3ÚmidÚderiv3s         r2   Ú_split_cubic_into_twor>   K   so   € Ø��R˜"‘W‘Ñ Ñ" eÑ
+€CØ�2‰g˜‰l˜RÑ 5Ñ(€Fà	ˆb�2‰g˜‰_˜c F™l¨CÐ0Ø	ˆc�F‰l˜R "™W¨™O¨RÐ0ðð r3   )r8   r9   r:   r;   )ÚmultÚarchÚboxc                 ó(  — t          ||z
  ¦  «        }t          ||z
  ¦  «        t          ||z
  ¦  «        z   t          ||z
  ¦  «        z   }|| z  t          z   |k    r||z   dz  S t          ||||¦  «        \  }}t          | g|¢R Ž t          | g|¢R Ž z   S ©Nr6   )ÚabsÚEPSILONr>   Ú_calcCubicArcLengthCRecurse)	r?   r8   r9   r:   r;   r@   rA   ÚoneÚtwos	            r2   rF   rF   T   s´   € õ ˆr�B‰w‰<Œ<€DÝ
ˆb�2‰g‰,Œ,�˜R "™W™œÑ
%­¨B°©G©¬Ñ
4€CØˆd�{•WÑ Ò#Ð#Ø�s‘
˜cÑ!Ð!å(¨¨R°°RÑ8Ô8‰ˆˆSÝ*¨4Ð6°#Ð6Ð6Ð6Õ9TØð:
Øð:
ð :
ð :
ñ 
ð 	
r3   ©r-   r.   r/   r0   )r1   r?   c                 ó8   — dd|z  z   }t          || |||¦  «        S )zôCalculates the arc length for a cubic Bezier segment.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
        tolerance: Controls the precision of the calcuation.

    Returns:
        Arc length value.
    ç      ð?g      ø?)rF   )r-   r.   r/   r0   r1   r?   s         r2   r   r   h   s(   € ð* ��y‘Ñ €DÝ& t¨S°#°s¸CÑ@Ô@Ð@r3   é   g»½×Ùß|Û=©Úv1Úv2c                 ó:   — | |                      ¦   «         z  j        S ©N)Ú	conjugateÚrealrM   s     r2   Ú_dotrT   …   s   € ð
 �—’‘”ÑÔ%Ð%r3   ©Úxc                 ór   — | t          j        | dz  dz   ¦  «        z  dz  t          j        | ¦  «        dz  z   S )Né   é   )ÚmathÚsqrtÚasinhrU   s    r2   Ú_intSecAtanr]   �   s8   € ð �tŒy˜˜A™ ™Ñ"Ô"Ñ" QÑ&­¬°A©¬¸Ñ):Ñ:Ð:r3   c                 óN   — t          t          | Ž t          |Ž t          |Ž ¦  «        S )až  Calculates the arc length for a quadratic Bezier segment.

    Args:
        pt1: Start point of the Bezier as 2D tuple.
        pt2: Handle point of the Bezier as 2D tuple.
        pt3: End point of the Bezier as 2D tuple.

    Returns:
        Arc length value.

    Example::

        >>> calcQuadraticArcLength((0, 0), (0, 0), (0, 0)) # empty segment
        0.0
        >>> calcQuadraticArcLength((0, 0), (50, 0), (80, 0)) # collinear points
        80.0
        >>> calcQuadraticArcLength((0, 0), (0, 50), (0, 80)) # collinear points vertical
        80.0
        >>> calcQuadraticArcLength((0, 0), (50, 20), (100, 40)) # collinear points
        107.70329614269008
        >>> calcQuadraticArcLength((0, 0), (0, 100), (100, 0))
        154.02976155645263
        >>> calcQuadraticArcLength((0, 0), (0, 50), (100, 0))
        120.21581243984076
        >>> calcQuadraticArcLength((0, 0), (50, -10), (80, 50))
        102.53273816445825
        >>> calcQuadraticArcLength((0, 0), (40, 0), (-40, 0)) # collinear points, control point outside
        66.66666666666667
        >>> calcQuadraticArcLength((0, 0), (40, 0), (0, 0)) # collinear points, looping back
        40.0
    )r   r,   ©r-   r.   r/   s      r2   r   r   —   s#   € õ@ #¥7¨C =µ'¸3°-ÅÈ#ÀÑOÔOÐOr3   )r-   r.   r/   Úd0Úd1ÚdÚn)ÚscaleÚorigDistÚaÚbÚx0Úx1ÚLenc                 ó8  — || z
  }||z
  }||z
  }|dz  }t          |¦  «        }|dk    rt          || z
  ¦  «        S t          ||¦  «        }t          |¦  «        t          k     rUt          ||¦  «        dk    rt          || z
  ¦  «        S t          |¦  «        t          |¦  «        }
}	|	|	z  |
|
z  z   |	|
z   z  S t          ||¦  «        |z  }t          ||¦  «        |z  }t          dt          |¦  «        t          |¦  «        z
  z  |z  |||z
  z  z  ¦  «        }|S )a$  Calculates the arc length for a quadratic Bezier segment.

    Args:
        pt1: Start point of the Bezier as a complex number.
        pt2: Handle point of the Bezier as a complex number.
        pt3: End point of the Bezier as a complex number.

    Returns:
        Arc length value.
    y              ð?ç        r   rX   )rD   rT   Úepsilonr]   )r-   r.   r/   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   s                 r2   r   r   º   s  € ð@ 
ˆs‰€BØ	ˆs‰€BØ
ˆR‰€AØ	ˆB‰€AÝ�‰FŒF€EØ�‚|€|Ý�3˜‘9‰~Œ~ÐÝ�A�r‰{Œ{€HÝ
ˆ8�}„}•wÒÐÝ��B‰<Œ<˜1ÒÐÝ�s˜S‘y‘>”>Ð!Ý�2‰wŒw�˜B™œˆ1ˆØ�A‘˜˜A™‘ ! a¡%Ñ(Ð(Ý	ˆa�‰Œ�xÑ	€BÝ	ˆa�‰Œ�xÑ	€BÝ
ˆa•;˜r‘?”?¥[°¡_¤_Ñ4Ñ5¸Ñ@ÀEÈRÐRTÉWÑDUÑVÑ
WÔ
W€CØ€Jr3   c                 óN   — t          t          | Ž t          |Ž t          |Ž ¦  «        S )a«  Calculates the arc length for a quadratic Bezier segment.

    Uses Gauss-Legendre quadrature for a branch-free approximation.
    See :func:`calcQuadraticArcLength` for a slower but more accurate result.

    Args:
        pt1: Start point of the Bezier as 2D tuple.
        pt2: Handle point of the Bezier as 2D tuple.
        pt3: End point of the Bezier as 2D tuple.

    Returns:
        Approximate arc length value.
    )r   r,   r_   s      r2   r   r   í   s#   € õ *­'°3¨-½À#¸ÍÐQTÈÑVÔVÐVr3   r_   )Úv0rN   rO   c                 ó´   — t          d| z  d|z  z   d|z  z   ¦  «        }t          || z
  ¦  «        dz  }t          d| z  d|z  z
  d|z  z   ¦  «        }||z   |z   S )aÃ  Calculates the arc length for a quadratic Bezier segment.

    Uses Gauss-Legendre quadrature for a branch-free approximation.
    See :func:`calcQuadraticArcLength` for a slower but more accurate result.

    Args:
        pt1: Start point of the Bezier as a complex number.
        pt2: Handle point of the Bezier as a complex number.
        pt3: End point of the Bezier as a complex number.

    Returns:
        Approximate arc length value.
    gÌ”xùbŒß¿g¾ðb�ŠÛ?gF�V¨W°?gÇqÇqÜ?gF�V¨W°¿gÌ”xùbŒß?©rD   )r-   r.   r/   ro   rN   rO   s         r2   r   r   þ   sˆ   € õB 
Ø˜SÑ Ð#4°sÑ#:Ñ:Ð=OÐRUÑ=UÑUñ
ô 
€Bõ 
ˆS�3‰Y‰ŒÐ,Ñ	,€BÝ	Ø˜cÑ!Ð$5¸Ñ$;Ñ;Ð>OÐRUÑ>UÑUñ
ô 
€Bð �‰7�R‰<Ðr3   c                 ó,  ‡‡‡	‡
‡‡— t          | ||¦  «        \  \  ŠŠ\  Š	Š
\  ŠŠ‰dz  }‰dz  }g }|dk    r|                     ‰	 |z  ¦  «         |dk    r|                     ‰
 |z  ¦  «         ˆˆˆ	ˆ
ˆˆfd„|D ¦   «         | |gz   }t          |¦  «        S )a  Calculates the bounding rectangle for a quadratic Bezier segment.

    Args:
        pt1: Start point of the Bezier as a 2D tuple.
        pt2: Handle point of the Bezier as a 2D tuple.
        pt3: End point of the Bezier as a 2D tuple.

    Returns:
        A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.

    Example::

        >>> calcQuadraticBounds((0, 0), (50, 100), (100, 0))
        (0, 0, 100, 50.0)
        >>> calcQuadraticBounds((0, 0), (100, 0), (100, 100))
        (0.0, 0.0, 100, 100)
    ç       @r   c                 ót   •— g | ]4}d |cxk    rdk     ¯n n"‰|z  |z  ‰|z  z   ‰z   ‰|z  |z  ‰|z  z   ‰z   f‘Œ5S ©r   rY   r7   )Ú.0ÚtÚaxÚayÚbxÚbyÚcxÚcys     €€€€€€r2   ú
<listcomp>z'calcQuadraticBounds.<locals>.<listcomp>D  sk   ø€ ð ð ð àØ�ˆ:ˆ:Š:ˆ:�AŠ:ˆ:ˆ:ˆ:ˆ:ð 
ˆa‰�!‰�b˜1‘fÑ	˜rÑ	! 2¨¡6¨A¡:°°Q±Ñ#6¸Ñ#;Ð<àˆ:ˆ:r3   )ÚcalcQuadraticParametersÚappendr   )r-   r.   r/   Úax2Úay2ÚrootsÚpointsrx   ry   rz   r{   r|   r}   s          @@@@@@r2   r   r   *  sæ   øøøøøø€ õ$ $;¸3ÀÀSÑ#IÔ#IÑ �H€Rˆ‰hˆr�2™˜˜RØ
ˆs‰(€CØ
ˆs‰(€CØ€EØ
ˆa‚x€xØ�Š�b�S˜3‘YÑÔÐØ
ˆa‚x€xØ�Š�b�S˜3‘YÑÔÐðð ð ð ð ð ð ð ð àðñ ô ð 
ˆcˆ
ñ	€Fõ
 �fÑÔÐr3   c                 ó^   — t          t          | Ž t          |Ž t          |Ž t          |Ž ¦  «        S )a®  Approximates the arc length for a cubic Bezier segment.

    Uses Gauss-Lobatto quadrature with n=5 points to approximate arc length.
    See :func:`calcCubicArcLength` for a slower but more accurate result.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.

    Returns:
        Arc length value.

    Example::

        >>> approximateCubicArcLength((0, 0), (25, 100), (75, 100), (100, 0))
        190.04332968932817
        >>> approximateCubicArcLength((0, 0), (50, 0), (100, 50), (100, 100))
        154.8852074945903
        >>> approximateCubicArcLength((0, 0), (50, 0), (100, 0), (150, 0)) # line; exact result should be 150.
        149.99999999999991
        >>> approximateCubicArcLength((0, 0), (50, 0), (100, 0), (-50, 0)) # cusp; exact result should be 150.
        136.9267662156362
        >>> approximateCubicArcLength((0, 0), (50, 0), (100, -50), (-50, 0)) # cusp
        154.80848416537057
    )r   r,   rI   s       r2   r   r   L  s/   € õ2 &Ý�ˆ•w �}¥g¨s mµW¸c°]ñô ð r3   )ro   rN   rO   Úv3Úv4c                 ó8  — t          || z
  ¦  «        dz  }t          d| z  d|z  z   d|z  z   d|z  z   ¦  «        }t          || z
  |z   |z
  ¦  «        dz  }t          d| z  d|z  z
  d|z  z
  d|z  z   ¦  «        }t          ||z
  ¦  «        dz  }||z   |z   |z   |z   S )	z¹Approximates the arc length for a cubic Bezier segment.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.

    Returns:
        Arc length value.
    g333333Ã?g�c’‰1ãá¿g8Ø5$t×Ô?guÁ|Yù¿Ê?gæâ#$ï˜?gÑ?gæâ#$ï˜¿g�c’‰1ãá?rq   )	r-   r.   r/   r0   ro   rN   rO   r†   r‡   s	            r2   r   r   j  sè   € õ> 
ˆS�3‰Y‰Œ˜$Ñ	€BÝ	Ø˜SÑ Ø
˜cÑ
!ñ	"à
˜cÑ
!ñ	"ð ˜cÑ
!ñ	"ñ
ô 
€Bõ 
ˆS�3‰Y˜‰_˜sÑ"Ñ	#Ô	#Ð&9Ñ	9€BÝ	Ø˜SÑ Ø
˜cÑ
!ñ	"à
˜cÑ
!ñ	"ð ˜cÑ
!ñ	"ñ
ô 
€Bõ 
ˆS�3‰Y‰Œ˜$Ñ	€Bà�‰7�R‰<˜"Ñ˜rÑ!Ð!r3   c                 óH  ‡‡‡‡‡‡‡‡— t          | |||¦  «        \  \  ŠŠ\  ŠŠ\  ŠŠ\  ŠŠ‰dz  }‰dz  }‰dz  }‰dz  }d„ t          ||‰¦  «        D ¦   «         }d„ t          ||‰¦  «        D ¦   «         }	||	z   }
ˆˆˆˆˆˆˆˆfd„|
D ¦   «         | |gz   }t          |¦  «        S )aX  Calculates the bounding rectangle for a quadratic Bezier segment.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.

    Returns:
        A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.

    Example::

        >>> calcCubicBounds((0, 0), (25, 100), (75, 100), (100, 0))
        (0, 0, 100, 75.0)
        >>> calcCubicBounds((0, 0), (50, 0), (100, 50), (100, 100))
        (0.0, 0.0, 100, 100)
        >>> print("%f %f %f %f" % calcCubicBounds((50, 0), (0, 100), (100, 100), (50, 0)))
        35.566243 0.000000 64.433757 75.000000
    ç      @rs   c                 ó2   — g | ]}d |cxk    rdk     ¯n n|‘ŒS ru   r7   ©rv   rw   s     r2   r~   z#calcCubicBounds.<locals>.<listcomp>´  ó-   € ÐDÐDÐD�A¸¸a¸¸º¸À!º¸¸¸¸ˆa¸¸¸r3   c                 ó2   — g | ]}d |cxk    rdk     ¯n n|‘ŒS ru   r7   rŒ   s     r2   r~   z#calcCubicBounds.<locals>.<listcomp>µ  r�   r3   c                 ó„   •— g | ]<}‰|z  |z  |z  ‰|z  |z  z   ‰|z  z   ‰z   ‰|z  |z  |z  ‰|z  |z  z   ‰|z  z   ‰	z   f‘Œ=S r7   r7   )
rv   rw   rx   ry   rz   r{   r|   r}   ÚdxÚdys
     €€€€€€€€r2   r~   z#calcCubicBounds.<locals>.<listcomp>¸  s�   ø€ ð ð ð ð
 ð �‰F�Q‰J˜‰N˜R !™V a™ZÑ'¨"¨q©&Ñ0°2Ñ5Ø�‰F�Q‰J˜‰N˜R !™V a™ZÑ'¨"¨q©&Ñ0°2Ñ5ð	
ðð ð r3   )ÚcalcCubicParametersr   r   )r-   r.   r/   r0   Úax3Úay3Úbx2Úby2ÚxRootsÚyRootsrƒ   r„   rx   ry   rz   r{   r|   r}   r�   r‘   s               @@@@@@@@r2   r   r   œ  s  øøøøøøøø€ õ$ .AÀÀcÈ3ÐPSÑ-TÔ-TÑ*�H€Rˆ‰hˆr�2™˜˜R¡( 2 rà
ˆs‰(€CØ
ˆs‰(€CØ
ˆs‰(€CØ
ˆs‰(€CØDÐD�¨¨S°"Ñ5Ô5ÐDÑDÔD€FØDÐD�¨¨S°"Ñ5Ô5ÐDÑDÔD€FØ�V‰O€Eðð ð ð ð ð ð ð ð ð ð ð
 ðñ ô ð 
ˆcˆ
ñ€Fõ �fÑÔÐr3   c                 óÖ   — | \  }}|\  }}||z
  }||z
  }	|}
|}||	f|         }|dk    r| |fgS ||
|f|         z
  |z  }d|cxk    rdk     rn n||z  |
z   |	|z  |z   f}| |f||fgS | |fgS )a  Split a line at a given coordinate.

    Args:
        pt1: Start point of line as 2D tuple.
        pt2: End point of line as 2D tuple.
        where: Position at which to split the line.
        isHorizontal: Direction of the ray splitting the line. If true,
            ``where`` is interpreted as a Y coordinate; if false, then
            ``where`` is interpreted as an X coordinate.

    Returns:
        A list of two line segments (each line segment being two 2D tuples)
        if the line was successfully split, or a list containing the original
        line.

    Example::

        >>> printSegments(splitLine((0, 0), (100, 100), 50, True))
        ((0, 0), (50, 50))
        ((50, 50), (100, 100))
        >>> printSegments(splitLine((0, 0), (100, 100), 100, True))
        ((0, 0), (100, 100))
        >>> printSegments(splitLine((0, 0), (100, 100), 0, True))
        ((0, 0), (0, 0))
        ((0, 0), (100, 100))
        >>> printSegments(splitLine((0, 0), (100, 100), 0, False))
        ((0, 0), (0, 0))
        ((0, 0), (100, 100))
        >>> printSegments(splitLine((100, 0), (0, 0), 50, False))
        ((100, 0), (50, 0))
        ((50, 0), (0, 0))
        >>> printSegments(splitLine((0, 100), (0, 0), 50, True))
        ((0, 100), (0, 50))
        ((0, 50), (0, 0))
    r   rY   r7   )r-   r.   ÚwhereÚisHorizontalÚpt1xÚpt1yÚpt2xÚpt2yrx   ry   rz   r{   rf   rw   ÚmidPts                  r2   r   r   Â  sÀ   € ðH �J€Dˆ$Ø�J€Dˆ$à	�‰€BØ	�‰€Bà	€BØ	€Bà	ˆRˆ�Ô€AàˆA‚v€vØ�c�
ˆ|ÐØ	�"�b�˜,Ô'Ñ	'¨1Ñ,€AØˆA€z€z‚z€z�‚z€z€z€z€zØ�Q‘˜‘˜R !™V b™[Ð(ˆØ�e�˜u c˜lÐ+Ð+à�c�
ˆ|Ðr3   c                 óØ   — t          | ||¦  «        \  }}}t          ||         ||         ||         |z
  ¦  «        }t          d„ |D ¦   «         ¦  «        }|s| ||fgS t          |||g|¢R Ž S )a  Split a quadratic Bezier curve at a given coordinate.

    Args:
        pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
        where: Position at which to split the curve.
        isHorizontal: Direction of the ray splitting the curve. If true,
            ``where`` is interpreted as a Y coordinate; if false, then
            ``where`` is interpreted as an X coordinate.

    Returns:
        A list of two curve segments (each curve segment being three 2D tuples)
        if the curve was successfully split, or a list containing the original
        curve.

    Example::

        >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 150, False))
        ((0, 0), (50, 100), (100, 0))
        >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 50, False))
        ((0, 0), (25, 50), (50, 50))
        ((50, 50), (75, 50), (100, 0))
        >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 25, False))
        ((0, 0), (12.5, 25), (25, 37.5))
        ((25, 37.5), (62.5, 75), (100, 0))
        >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 25, True))
        ((0, 0), (7.32233, 14.6447), (14.6447, 25))
        ((14.6447, 25), (50, 75), (85.3553, 25))
        ((85.3553, 25), (92.6777, 14.6447), (100, -7.10543e-15))
        >>> # XXX I'm not at all sure if the following behavior is desirable:
        >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 50, True))
        ((0, 0), (25, 50), (50, 50))
        ((50, 50), (50, 50), (50, 50))
        ((50, 50), (75, 50), (100, 0))
    c              3   ó:   K  — | ]}d |cxk    rdk     ¯n n|V — ŒdS ©r   rY   Nr7   rŒ   s     r2   ú	<genexpr>z!splitQuadratic.<locals>.<genexpr>"  ó6   è è € Ð:Ð:˜Q¨q°A¨z¨zªz¨z¸ªz¨z¨z¨z¨z�q¨z¨z¨z¨zÐ:Ð:r3   )r   r   ÚsortedÚ_splitQuadraticAtT)	r-   r.   r/   rš   r›   rf   rg   ÚcÚ	solutionss	            r2   r   r   û  s’   € õF & c¨3°Ñ4Ô4�G€A€qˆ!ÝØ	ˆ,Œ˜˜<œ¨!¨L¬/¸EÑ*Añô €Iõ Ð:Ð: )Ð:Ñ:Ô:Ñ:Ô:€IØð !Ø�c˜3�Ð Ð Ý˜a  AÐ2¨	Ð2Ð2Ð2Ð2r3   c                 óî   — t          | |||¦  «        \  }}}}	t          ||         ||         ||         |	|         |z
  ¦  «        }
t          d„ |
D ¦   «         ¦  «        }
|
s| |||fgS t          ||||	g|
¢R Ž S )aÞ  Split a cubic Bezier curve at a given coordinate.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
        where: Position at which to split the curve.
        isHorizontal: Direction of the ray splitting the curve. If true,
            ``where`` is interpreted as a Y coordinate; if false, then
            ``where`` is interpreted as an X coordinate.

    Returns:
        A list of two curve segments (each curve segment being four 2D tuples)
        if the curve was successfully split, or a list containing the original
        curve.

    Example::

        >>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 150, False))
        ((0, 0), (25, 100), (75, 100), (100, 0))
        >>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 50, False))
        ((0, 0), (12.5, 50), (31.25, 75), (50, 75))
        ((50, 75), (68.75, 75), (87.5, 50), (100, 0))
        >>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 25, True))
        ((0, 0), (2.29379, 9.17517), (4.79804, 17.5085), (7.47414, 25))
        ((7.47414, 25), (31.2886, 91.6667), (68.7114, 91.6667), (92.5259, 25))
        ((92.5259, 25), (95.202, 17.5085), (97.7062, 9.17517), (100, 1.77636e-15))
    c              3   ó:   K  — | ]}d |cxk    rdk     ¯n n|V — ŒdS r£   r7   rŒ   s     r2   r¤   zsplitCubic.<locals>.<genexpr>G  r¥   r3   )r’   r    r¦   Ú_splitCubicAtT)r-   r.   r/   r0   rš   r›   rf   rg   r¨   rb   r©   s              r2   r   r   (  s    € õ6 % S¨#¨s°CÑ8Ô8�J€A€qˆ!ˆQÝØ	ˆ,Œ˜˜<œ¨!¨L¬/¸1¸\¼?ÈUÑ;Rñô €Iõ Ð:Ð: )Ð:Ñ:Ô:Ñ:Ô:€IØð &Ø�c˜3 Ð$Ð%Ð%Ý˜!˜Q  1Ð1 yÐ1Ð1Ð1Ð1r3   c                 óJ   — t          | ||¦  «        \  }}}t          |||g|¢R Ž S )a•  Split a quadratic Bezier curve at one or more values of t.

    Args:
        pt1,pt2,pt3: Control points of the Bezier as 2D tuples.
        *ts: Positions at which to split the curve.

    Returns:
        A list of curve segments (each curve segment being three 2D tuples).

    Examples::

        >>> printSegments(splitQuadraticAtT((0, 0), (50, 100), (100, 0), 0.5))
        ((0, 0), (25, 50), (50, 50))
        ((50, 50), (75, 50), (100, 0))
        >>> printSegments(splitQuadraticAtT((0, 0), (50, 100), (100, 0), 0.5, 0.75))
        ((0, 0), (25, 50), (50, 50))
        ((50, 50), (62.5, 50), (75, 37.5))
        ((75, 37.5), (87.5, 25), (100, 0))
    )r   r§   )r-   r.   r/   Útsrf   rg   r¨   s          r2   r   r   M  s5   € õ( & c¨3°Ñ4Ô4�G€A€qˆ!Ý˜a  AÐ+¨Ð+Ð+Ð+Ð+r3   c                 ó²   — t          | |||¦  «        \  }}}}t          ||||g|¢R Ž }	| g|	d         dd…         ¢R |	d<   g |	d         dd…         ¢|‘R |	d<   |	S )a   Split a cubic Bezier curve at one or more values of t.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as 2D tuples.
        *ts: Positions at which to split the curve.

    Returns:
        A list of curve segments (each curve segment being four 2D tuples).

    Examples::

        >>> printSegments(splitCubicAtT((0, 0), (25, 100), (75, 100), (100, 0), 0.5))
        ((0, 0), (12.5, 50), (31.25, 75), (50, 75))
        ((50, 75), (68.75, 75), (87.5, 50), (100, 0))
        >>> printSegments(splitCubicAtT((0, 0), (25, 100), (75, 100), (100, 0), 0.5, 0.75))
        ((0, 0), (12.5, 50), (31.25, 75), (50, 75))
        ((50, 75), (59.375, 75), (68.75, 68.75), (77.3438, 56.25))
        ((77.3438, 56.25), (85.9375, 43.75), (93.75, 25), (100, 0))
    r   rY   Néÿÿÿÿ)r’   r¬   )
r-   r.   r/   r0   r®   rf   rg   r¨   rb   Úsplits
             r2   r   r   e  sƒ   € õ( % S¨#¨s°CÑ8Ô8�J€A€qˆ!ˆQÝ˜1˜a  AÐ+¨Ð+Ð+Ð+€Eð
 Ð#�e˜A”h˜q˜r˜r”lÐ#Ð#€Eˆ!�HØ&�%˜”)˜C˜R˜C”.Ð& #Ð&Ð&€Eˆ"�IØ€Lr3   )r-   r.   r/   r0   rf   rg   r¨   rb   c              '   ód   K  — t          | |||¦  «        \  }}}}t          ||||g|¢R Ž E d{V —† dS )a  Split a cubic Bezier curve at one or more values of t.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers..
        *ts: Positions at which to split the curve.

    Yields:
        Curve segments (each curve segment being four complex numbers).
    N)ÚcalcCubicParametersCÚ_splitCubicAtTC)	r-   r.   r/   r0   r®   rf   rg   r¨   rb   s	            r2   r   r   „  sW   è è € õ( & c¨3°°SÑ9Ô9�J€A€qˆ!ˆQÝ˜q ! Q¨Ð/¨BÐ/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/r3   )rw   r-   r.   r/   r0   ÚpointAtTÚoff1Úoff2)r   Ú_1_tÚ_1_t_2Ú_2_t_1_tc                 ó  — ||z  }d|z
  }||z  }d|z  |z  }||z  | z  d||z  |z  ||z  |z  z   z  z   ||z  |z  z   }	|| z  ||z  z   ||z  z   }
||z  ||z  z   ||z  z   }| || z
  |z  z   }|||z
  |z  z   }| ||
|	f|	|||ffS )a  Split a cubic Bezier curve at t.

    Args:
        pt1,pt2,pt3,pt4: Control points of the Bezier as complex numbers.
        t: Position at which to split the curve.

    Returns:
        A tuple of two curve segments (each curve segment being four complex numbers).
    rY   rX   r5   r7   )r-   r.   r/   r0   rw   r   r¸   r¹   rº   rµ   r¶   r·   s               r2   r   r   œ  så   € ð0 
ˆQ‰€BØˆq‰5€DØ�D‰[€FØ�1‰u�t‰|€Hà�‰˜Ñ˜a 6¨A¡:°Ñ#3°d¸R±iÀ#±oÑ#EÑFÑFÈÈaÉÐRUÉÑUð ð �C‰<˜( S™.Ñ(¨2°©8Ñ3€DØ�C‰<˜( S™.Ñ(¨2°©8Ñ3€Dà
��s‘˜a‘Ñ
€CØ
��s‘˜dÑ"Ñ
"€Cà�#�t˜XÐ&¨°4¸¸cÐ(BÐCÐCr3   c                 ó  — t          |¦  «        }g }|                     dd¦  «         |                     d¦  «         | \  }}|\  }}|\  }	}
t          t	          |¦  «        dz
  ¦  «        D ]™}||         }||dz            }||z
  }||z  }||z  }||z  }d|z  |z  |z   |z  }d|z  |z  |z   |z  }||z  }||z  ||z  z   |	z   }||z  ||z  z   |
z   }t          ||f||f||f¦  «        \  }}}|                     |||f¦  «         Œš|S )Nr   rl   rK   rY   rX   )ÚlistÚinsertr€   ÚrangeÚlenÚcalcQuadraticPoints)rf   rg   r¨   r®   Úsegmentsrx   ry   rz   r{   r|   r}   Úir   r   ÚdeltaÚdelta_2Úa1xÚa1yÚb1xÚb1yÚt1_2Úc1xÚc1yr-   r.   r/   s                             r2   r§   r§   Ä  sS  € Ý	ˆb‰Œ€BØ€HØ‡I‚Iˆa�ÑÔÐØ‡I‚Iˆc�N„N€NØ�F€BˆØ�F€BˆØ�F€BˆÝ•3�r‘7”7˜Q‘;ÑÔð )ð )ˆØ�ŒUˆØ��A‘ŒYˆØ�R‘ˆà˜%‘-ˆØ�7‰lˆØ�7‰lˆØ�2‰v˜‰{˜RÑ 5Ñ(ˆØ�2‰v˜‰{˜RÑ 5Ñ(ˆØ�B‰wˆØ�4‰i˜"˜r™'Ñ! BÑ&ˆØ�4‰i˜"˜r™'Ñ! BÑ&ˆå+¨S°#¨J¸¸c¸
ÀSÈ#ÀJÑOÔO‰ˆˆS�#Ø�Š˜˜c 3˜Ñ(Ô(Ð(Ð(Ø€Or3   c                 óª  — t          |¦  «        }|                     dd¦  «         |                     d¦  «         g }| \  }}|\  }}	|\  }
}|\  }}t          t	          |¦  «        dz
  ¦  «        D ]â}||         }||dz            }||z
  }||z  }||z  }||z  }||z  }||z  }||z  }d|z  |z  |z   |z  }d|z  |z  |	z   |z  }d|z  |z  |
z   d|z  |z  z   |z  }d|	z  |z  |z   d|z  |z  z   |z  }||z  ||z  z   |
|z  z   |z   }||z  |	|z  z   ||z  z   |z   }t          ||f||f||f||f¦  «        \  }}} }!|                     ||| |!f¦  «         Œã|S ©Nr   rl   rK   rY   r5   rX   )r½   r¾   r€   r¿   rÀ   ÚcalcCubicPoints)"rf   rg   r¨   rb   r®   rÂ   rx   ry   rz   r{   r|   r}   r�   r‘   rÃ   r   r   rÄ   rÅ   Údelta_3rÊ   Út1_3rÆ   rÇ   rÈ   rÉ   rË   rÌ   Úd1xÚd1yr-   r.   r/   r0   s"                                     r2   r¬   r¬   ß  sÝ  € Ý	ˆb‰Œ€BØ‡I‚Iˆa�ÑÔÐØ‡I‚Iˆc�N„N€NØ€HØ�F€BˆØ�F€BˆØ�F€BˆØ�F€BˆÝ•3�r‘7”7˜Q‘;ÑÔð .ð .ˆØ�ŒUˆØ��A‘ŒYˆØ�R‘ˆà˜%‘-ˆØ˜'‘/ˆØ�B‰wˆØ�D‰yˆð �7‰lˆØ�7‰lˆØ�2‰v˜‰{˜RÑ 7Ñ*ˆØ�2‰v˜‰{˜RÑ 7Ñ*ˆØ�2‰v˜‰{˜RÑ ! b¡&¨4¡-Ñ/°5Ñ8ˆØ�2‰v˜‰{˜RÑ ! b¡&¨4¡-Ñ/°5Ñ8ˆØ�4‰i˜"˜t™)Ñ# b¨2¡gÑ-°Ñ2ˆØ�4‰i˜"˜t™)Ñ# b¨2¡gÑ-°Ñ2ˆÝ,Ø�#ˆJ˜˜c˜
 S¨# J°°c°
ñ
ô 
ÑˆˆS�#�sð 	�Š˜˜c 3¨Ð,Ñ-Ô-Ð-Ð-Ø€Or3   )rf   rg   r¨   rb   r   r   rÄ   rÅ   rÐ   Úa1Úb1Úc1ra   c              '   óÔ  K  — t          |¦  «        }|                     dd¦  «         |                     d¦  «         t          t	          |¦  «        dz
  ¦  «        D ]‹}||         }||dz            }||z
  }||z  }	||	z  }
||z  }||z  }| |
z  }d| z  |z  |z   |	z  }d|z  |z  |z   d| z  |z  z   |z  }| |z  ||z  z   ||z  z   |z   }t          ||||¦  «        \  }}}}||||fV — ŒŒd S rÎ   )r½   r¾   r€   r¿   rÀ   ÚcalcCubicPointsC)rf   rg   r¨   rb   r®   rÃ   r   r   rÄ   rÅ   rÐ   rÊ   rÑ   rÔ   rÕ   rÖ   ra   r-   r.   r/   r0   s                        r2   r´   r´     s<  è è € õ  
ˆb‰Œ€BØ‡I‚Iˆa�ÑÔÐØ‡I‚Iˆc�N„N€NÝ•3�r‘7”7˜Q‘;ÑÔð #ð #ˆØ�ŒUˆØ��A‘ŒYˆØ�R‘ˆà˜%‘-ˆØ˜'‘/ˆØ�B‰wˆØ�D‰yˆð �‰[ˆØ�!‰e�b‰j˜1‰n Ñ'ˆØ�!‰e�b‰j˜1‰n˜q 1™u t™|Ñ+¨uÑ4ˆØ�‰X˜˜D™Ñ  1 r¡6Ñ)¨AÑ-ˆÝ-¨b°"°b¸"Ñ=Ô=ÑˆˆS�#�sØ�C˜˜cÐ"Ð"Ð"Ð"Ð"ð!#ð #r3   )r[   ÚacosÚcosÚpic                 óð   — t          | ¦  «        t          k     r#t          |¦  «        t          k     rg }nB| |z  g}n:||z  d| z  |z  z
  }|dk    r$ ||¦  «        }| |z   dz  | z  | |z
  dz  | z  g}ng }|S )uK  Solve a quadratic equation.

    Solves *a*x*x + b*x + c = 0* where a, b and c are real.

    Args:
        a: coefficient of *xÂ²*
        b: coefficient of *x*
        c: constant term

    Returns:
        A list of roots. Note that the returned list is neither guaranteed to
        be sorted nor to contain unique values!
    ç      @rl   rs   ©rD   rm   )rf   rg   r¨   r[   rƒ   ÚDDÚrDDs          r2   r   r   /  s¤   € õ ˆ1�v„v•ÒÐÝˆq‰6Œ6•GÒÐàˆEˆEð �R˜!‘V�HˆEˆEð �‰U�S˜1‘W˜q‘[Ñ ˆØ�Š9ˆ9Ø�$�r‘(”(ˆCØ�b˜3‘h #Ñ%¨Ñ)¨Q¨B°©H¸Ñ+;¸aÑ+?Ð@ˆEˆEð ˆEØ€Lr3   c           
      ó   — t          | ¦  «        t          k     rt          |||¦  «        S t          | ¦  «        } || z  }|| z  }|| z  }||z  d|z  z
  dz  }d|z  |z  |z  d|z  |z  z
  d|z  z   dz  }||z  }	||z  |z  }
|	t          k     rdn|	}	t          |
¦  «        t          k     rdn|
}
|	|
z
  }|	dk    r$|
dk    rt	          | dz  t
          ¦  «        }|||gS |t          dz  k    �rËt          t          t          |t          |
¦  «        z  d	¦  «        d
¦  «        ¦  «        }dt          |¦  «        z  }|dz  }|t          |dz  ¦  «        z  |z
  }|t          |dt          z  z   dz  ¦  «        z  |z
  }|t          |dt          z  z   dz  ¦  «        z  |z
  }t          |||g¦  «        \  }}}||z
  t          k     r1||z
  t          k     r#t	          ||z   |z   dz  t
          ¦  «        x}x}}nÁ||z
  t          k     r3t	          ||z   dz  t
          ¦  «        x}}t	          |t
          ¦  «        }n€||z
  t          k     r3t	          |t
          ¦  «        }t	          ||z   dz  t
          ¦  «        x}}n?t	          |t
          ¦  «        }t	          |t
          ¦  «        }t	          |t
          ¦  «        }|||gS t          t          |¦  «        t          |¦  «        z   d¦  «        }|||z  z   }|dk    r| }t	          ||dz  z
  t
          ¦  «        }|gS )ut  Solve a cubic equation.

    Solves *a*x*x*x + b*x*x + c*x + d = 0* where a, b, c and d are real.

    Args:
        a: coefficient of *xÂ³*
        b: coefficient of *xÂ²*
        c: coefficient of *x*
        d: constant term

    Returns:
        A list of roots. Note that the returned list is neither guaranteed to
        be sorted nor to contain unique values!

    Examples::

        >>> solveCubic(1, 1, -6, 0)
        [-3.0, -0.0, 2.0]
        >>> solveCubic(-10.0, -9.0, 48.0, -29.0)
        [-2.9, 1.0, 1.0]
        >>> solveCubic(-9.875, -9.0, 47.625, -28.75)
        [-2.911392, 1.0, 1.0]
        >>> solveCubic(1.0, -4.5, 6.75, -3.375)
        [1.5, 1.5, 1.5]
        >>> solveCubic(-12.0, 18.0, -9.0, 1.50023651123)
        [0.5, 0.5, 0.5]
        >>> solveCubic(
        ...     9.0, 0.0, 0.0, -7.62939453125e-05
        ... ) == [-0.0, -0.0, -0.0]
        True
    rŠ   g      "@rs   g      ;@g      K@r   rl   r6   rK   g      ð¿g       ÀrÝ   çUUUUUUÕ?)rD   rm   r   ÚfloatÚroundÚepsilonDigitsrÙ   ÚmaxÚminr[   rÚ   rÛ   r¦   Úpow)rf   rg   r¨   rb   rÔ   Úa2Úa3ÚQÚRÚR2ÚQ3ÚR2_Q3rV   ÚthetaÚrQ2Úa1_3rh   ri   Úx2s                      r2   r    r    P  s0  € õL ˆ1�v„v•ÒÐõ ˜a  AÑ&Ô&Ð&Ýˆa‰Œ€AØ	
ˆQ‰€BØ	
ˆQ‰€BØ	
ˆQ‰€Bà	ˆb‰�3˜‘8Ñ	˜sÑ"€AØ	ˆr‰�B‰˜Ñ	˜c B™h¨™mÑ	+¨d°R©iÑ	7¸4Ñ?€Aà	
ˆQ‰€BØ	
ˆQ‰�‰€BØ•7Šlˆlˆˆ €BÝ�"‰gŒg�ÒÐˆˆ R€Bà�‰G€Eà	ˆS‚y€y�R˜3’Y�YÝ�2�#˜‘)�]Ñ+Ô+ˆØ�1�aˆyÐØ	•'˜C‘-Ò	Ñ	å•S�˜Q¥ b¡¤™\¨3Ñ/Ô/°Ñ6Ô6Ñ7Ô7ˆØ•T˜!‘W”W‰nˆØ�C‰xˆØ•3�u˜s‘{Ñ#Ô#Ñ# dÑ*ˆØ•3˜ ¥b¡Ñ(¨CÑ/Ñ0Ô0Ñ0°4Ñ7ˆØ•3˜ ¥b¡Ñ(¨CÑ/Ñ0Ô0Ñ0°4Ñ7ˆÝ˜R  R˜LÑ)Ô)‰
ˆˆB�à�‰7•WÒÐ  b¡­7Ò!2Ð!2Ý  " r¡'¨B¡,°#Ñ!5µ}ÑEÔEÐEˆBÐE��b�bØ�"‰W•wÒÐÝ˜R "™W¨™O­]Ñ;Ô;Ð;ˆB�Ý�r�=Ñ)Ô)ˆBˆBØ�"‰W•wÒÐÝ�r�=Ñ)Ô)ˆBÝ˜R "™W¨™O­]Ñ;Ô;Ð;ˆB��å�r�=Ñ)Ô)ˆBÝ�r�=Ñ)Ô)ˆBÝ�r�=Ñ)Ô)ˆBØ�B˜ˆ|Ðå•�U‘”�c !™fœfÑ$ gÑ.Ô.ˆØ��A‘‰IˆØ�Š8ˆ8Ø�ˆAÝ�!�b˜3‘h‘,¥Ñ.Ô.ˆØˆsˆ
r3   c                 óv   — |\  }}|\  }}| \  }}||z
  dz  }	||z
  dz  }
||z
  |	z
  }||z
  |
z
  }||f|	|
f||ffS )Nrs   r7   )r-   r.   r/   ró   Úy2Úx3Úy3r|   r}   rz   r{   rx   ry   s                r2   r   r   ±  sj   € Ø�F€BˆØ�F€BˆØ�F€BˆØ
ˆr‰'�S‰€BØ
ˆr‰'�S‰€BØ	ˆb‰�2‰€BØ	ˆb‰�2‰€BØ�ˆ8�b˜"�X  B˜xÐ'Ð'r3   c                 ó¾   — |\  }}|\  }}|\  }}	| \  }
}||
z
  dz  }||z
  dz  }||z
  dz  |z
  }||z
  dz  |z
  }||
z
  |z
  |z
  }|	|z
  |z
  |z
  }||f||f||f|
|ffS ©NrŠ   r7   )r-   r.   r/   r0   ró   rõ   rö   r÷   Úx4Úy4r�   r‘   r|   r}   rz   r{   rx   ry   s                     r2   r’   r’   ¼  s§   € Ø�F€BˆØ�F€BˆØ�F€BˆØ�F€BˆØ
ˆr‰'�S‰€BØ
ˆr‰'�S‰€BØ
ˆr‰'�S‰˜2Ñ	€BØ
ˆr‰'�S‰˜2Ñ	€BØ	ˆb‰�2‰˜Ñ	€BØ	ˆb‰�2‰˜Ñ	€BØ�ˆ8�b˜"�X  B˜x¨"¨b¨Ð1Ð1r3   )r-   r.   r/   r0   rf   rg   r¨   c                 óJ   — || z
  dz  }||z
  dz  |z
  }|| z
  |z
  |z
  }|||| fS rù   r7   )r-   r.   r/   r0   r¨   rg   rf   s          r2   r³   r³   Ê  sE   € ð 
ˆs‰�cÑ€AØ	ˆs‰�cÑ˜AÑ€AØˆc‰	�A‰˜Ñ€AØˆq�!�Sˆ>Ðr3   c                 ó~   — | \  }}|\  }}|\  }}|}	|}
|dz  |z   }|dz  |z   }||z   |z   }||z   |z   }|	|
f||f||ffS rC   r7   )rf   rg   r¨   rx   ry   rz   r{   r|   r}   ri   Úy1ró   rõ   rö   r÷   s                  r2   rÁ   rÁ   Ü  st   € Ø�F€BˆØ�F€BˆØ�F€BˆØ	€BØ	€BØ
ˆs‰(�b‰€BØ
ˆs‰(�b‰€BØ	ˆb‰�2‰€BØ	ˆb‰�2‰€BØ�ˆ8�b˜"�X  B˜xÐ'Ð'r3   c                 óÆ   — | \  }}|\  }}|\  }}	|\  }
}|
}|}|dz  |
z   }|	dz  |z   }||z   dz  |z   }||	z   dz  |z   }||
z   |z   |z   }||z   |	z   |z   }||f||f||f||ffS rù   r7   )rf   rg   r¨   rb   rx   ry   rz   r{   r|   r}   r�   r‘   ri   rþ   ró   rõ   rö   r÷   rú   rû   s                       r2   rÏ   rÏ   é  s±   € Ø�F€BˆØ�F€BˆØ�F€BˆØ�F€BˆØ	€BØ	€BØ
ˆs‰(�b‰€BØ
ˆs‰(�b‰€BØ
ˆr‰'�S‰˜2Ñ	€BØ
ˆr‰'�S‰˜2Ñ	€BØ	ˆb‰�2‰˜Ñ	€BØ	ˆb‰�2‰˜Ñ	€BØ�ˆ8�b˜"�X  B˜x¨"¨b¨Ð1Ð1r3   ©rf   rg   r¨   rb   r:   r;   Úp4c                 óJ   — |dz  |z   }||z   dz  |z   }| |z   |z   |z   }||||fS )Nrâ   r7   r   s          r2   rØ   rØ   ù  sC   € ð 
ˆe‰�q‰€BØ
ˆa‰%�EÑ	˜RÑ	€BØ	
ˆQ‰�‰�Q‰€BØˆr�2�rˆ?Ðr3   c                 ój   — | d         d|z
  z  |d         |z  z   | d         d|z
  z  |d         |z  z   fS )zÖFinds the point at time `t` on a line.

    Args:
        pt1, pt2: Coordinates of the line as 2D tuples.
        t: The time along the line.

    Returns:
        A 2D tuple with the coordinates of the point.
    r   rY   r7   )r-   r.   rw   s      r2   r$   r$     sC   € ð �ŒV�q˜1‘uÑ  A¤¨¡
Ñ*¨c°!¬f¸¸A¹Ñ.>ÀÀQÄÈ!ÁÑ.KÐMÐMr3   c                 óê   — d|z
  d|z
  z  | d         z  dd|z
  z  |z  |d         z  z   ||z  |d         z  z   }d|z
  d|z
  z  | d         z  dd|z
  z  |z  |d         z  z   ||z  |d         z  z   }||fS )zèFinds the point at time `t` on a quadratic curve.

    Args:
        pt1, pt2, pt3: Coordinates of the curve as 2D tuples.
        t: The time along the curve.

    Returns:
        A 2D tuple with the coordinates of the point.
    rY   r   rX   r7   )r-   r.   r/   rw   rV   Úys         r2   r!   r!     s™   € ð 
ˆQ‰�1�q‘5Ñ˜C œFÑ" Q¨!¨a©%¡[°1¡_°s¸1´vÑ%=Ñ=ÀÀAÁÈÈAÌÁÑN€AØ	
ˆQ‰�1�q‘5Ñ˜C œFÑ" Q¨!¨a©%¡[°1¡_°s¸1´vÑ%=Ñ=ÀÀAÁÈÈAÌÁÑN€AØˆqˆ6€Mr3   c                 ó   — ||z  }d|z
  }||z  }||z  | d         z  d||z  |d         z  ||z  |d         z  z   z  z   ||z  |d         z  z   }||z  | d         z  d||z  |d         z  ||z  |d         z  z   z  z   ||z  |d         z  z   }	||	fS )zéFinds the point at time `t` on a cubic curve.

    Args:
        pt1, pt2, pt3, pt4: Coordinates of the curve as 2D tuples.
        t: The time along the curve.

    Returns:
        A 2D tuple with the coordinates of the point.
    rY   r   r5   r7   )
r-   r.   r/   r0   rw   r   r¸   r¹   rV   r  s
             r2   r"   r"   ,  sÖ   € ð 
ˆQ‰€BØˆq‰5€DØ�D‰[€Fà�‰˜˜AœÑØ
ˆv˜‰z˜C œFÑ" T¨B¡Y°°Q´Ñ%7Ñ7Ñ
8ñ	9à
ˆq‰&�3�q”6‰/ñ	ð ð 	�‰˜˜AœÑØ
ˆv˜‰z˜C œFÑ" T¨B¡Y°°Q´Ñ%7Ñ7Ñ
8ñ	9à
ˆq‰&�3�q”6‰/ñ	ð ð
 ˆqˆ6€Mr3   )rw   r-   r.   r/   r0   )r   r¸   r¹   c                 ól   — ||z  }d|z
  }||z  }||z  | z  d||z  |z  ||z  |z  z   z  z   ||z  |z  z   S )zõFinds the point at time `t` on a cubic curve.

    Args:
        pt1, pt2, pt3, pt4: Coordinates of the curve as complex numbers.
        t: The time along the curve.

    Returns:
        A complex number with the coordinates of the point.
    rY   r5   r7   )r-   r.   r/   r0   rw   r   r¸   r¹   s           r2   r#   r#   F  s]   € ð& 
ˆQ‰€BØˆq‰5€DØ�D‰[€FØ�D‰=˜3Ñ  f¨q¡j°3Ñ&6¸À¹ÀS¹Ñ&HÑ!IÑIÈBÐQRÉFÐUXÉLÑXÐXr3   c                 óæ   — t          | ¦  «        dk    rt          g | ¢|‘R Ž S t          | ¦  «        dk    rt          g | ¢|‘R Ž S t          | ¦  «        dk    rt          g | ¢|‘R Ž S t	          d¦  «        ‚©NrX   r5   é   úUnknown curve degree)rÀ   r$   r!   r"   Ú
ValueError)Úsegrw   s     r2   r%   r%   _  s‰   € Ý
ˆ3�x„x�1‚}€}ÝÐ$˜SÐ$ !Ð$Ð$Ð$Ð$Ý	ˆS‰Œ�QŠˆÝ Ð) #Ð) qÐ)Ð)Ð)Ð)Ý	ˆS‰Œ�QŠˆÝÐ%˜cÐ% 1Ð%Ð%Ð%Ð%Ý
Ð+Ñ
,Ô
,Ð,r3   c                 ó  — | \  }}|\  }}|\  }}t          ||z
  ¦  «        t          k     rt          ||z
  ¦  «        t          k     rdS t          ||z
  ¦  «        t          ||z
  ¦  «        k    r||z
  ||z
  z  S ||z
  ||z
  z  S )Nr°   rÞ   )	ÚsÚer   ÚsxÚsyÚexÚeyÚpxÚpys	            r2   Ú_line_t_of_ptr  n  s�   € Ø�F€BˆØ�F€BˆØ�F€BˆÝ
ˆ2�‰7�|„|•gÒÐ¥# b¨2¡g¡,¤,µÒ"8Ð"8àˆrå
ˆ2�‰7�|„|•c˜"˜r™'‘l”lÒ"Ð"Ø�R‘˜B ™GÑ$Ð$à�R‘˜B ™GÑ$Ð$r3   c                 ó¨   — | d         |d         z
  |d         |d         z
  z  }| d         |d         z
  |d         |d         z
  z  }|dk    o|dk     S )Nr   rY   rl   r7   )rf   rg   ÚoriginÚxDiffÚyDiffs        r2   Ú'_both_points_are_on_same_side_of_originr  |  s`   € ØˆqŒT�F˜1”IÑ ! A¤$¨°¬Ñ"2Ñ3€EØˆqŒT�F˜1”IÑ ! A¤$¨°¬Ñ"2Ñ3€EØ˜’Ð- ¨#¢Ð.Ð.r3   c           	      ó¶  — | \  }}|\  }}|\  }}	|\  }
}t          j        ||
¦  «        r,t          j        ||¦  «        rt          j        ||¦  «        sg S t          j        |	|¦  «        r,t          j        ||¦  «        rt          j        ||	¦  «        sg S t          j        ||
¦  «        rt          j        |	|¦  «        rg S t          j        ||¦  «        rt          j        ||¦  «        rg S t          j        ||¦  «        rM|}||	z
  |
|z
  z  }|||z
  z  |	z   }||f}t          |t          | ||¦  «        t          |||¦  «        ¬¦  «        gS t          j        ||
¦  «        rM|}||z
  ||z
  z  }|||z
  z  |z   }||f}t          |t          | ||¦  «        t          |||¦  «        ¬¦  «        gS ||z
  ||z
  z  }||	z
  |
|z
  z  }t          j        ||¦  «        rg S ||z  |z
  ||z  z
  |	z   ||z
  z  }|||z
  z  |z   }||f}t	          ||| ¦  «        rBt	          |||¦  «        r1t          |t          | ||¦  «        t          |||¦  «        ¬¦  «        gS g S )aí  Finds intersections between two line segments.

    Args:
        s1, e1: Coordinates of the first line as 2D tuples.
        s2, e2: Coordinates of the second line as 2D tuples.

    Returns:
        A list of ``Intersection`` objects, each object having ``pt``, ``t1``
        and ``t2`` attributes containing the intersection point, time on first
        segment and time on second segment respectively.

    Examples::

        >>> a = lineLineIntersections( (310,389), (453, 222), (289, 251), (447, 367))
        >>> len(a)
        1
        >>> intersection = a[0]
        >>> intersection.pt
        (374.44882952482897, 313.73458370177315)
        >>> (intersection.t1, intersection.t2)
        (0.45069111555824465, 0.5408153767394238)
    r
   )rZ   Úiscloser	   r  r  )Ús1Úe1Ús2Úe2Ús1xÚs1yÚe1xÚe1yÚs2xÚs2yÚe2xÚe2yrV   Úslope34r  r   Úslope12s                    r2   r&   r&   ‚  s   € ð. �H€CˆØ�H€CˆØ�H€CˆØ�H€CˆåŒ�S˜#ÑÔðÝ#'¤<°°SÑ#9Ô#9ðÝBFÄ,ÈsÐTWÑBXÔBXðð ˆ	åŒ�S˜#ÑÔðÝ#'¤<°°SÑ#9Ô#9ðÝBFÄ,ÈsÐTWÑBXÔBXðð ˆ	Ý„|�C˜ÑÔð ¥$¤,¨s°CÑ"8Ô"8ð Øˆ	Ý„|�C˜ÑÔð ¥$¤,¨s°CÑ"8Ô"8ð Øˆ	Ý„|�C˜ÑÔð 	
ØˆØ˜‘9  s¡Ñ+ˆØ�q˜3‘wÑ #Ñ%ˆØ�ˆVˆåØ�-¨¨B°Ñ3Ô3½ÀbÈ"ÈbÑ8QÔ8Qðñ ô ð
ð 	
õ
 „|�C˜ÑÔð 	
ØˆØ˜‘9  s¡Ñ+ˆØ�q˜3‘wÑ #Ñ%ˆØ�ˆVˆåØ�-¨¨B°Ñ3Ô3½ÀbÈ"ÈbÑ8QÔ8Qðñ ô ð
ð 	
ð �S‰y˜S 3™YÑ'€GØ�S‰y˜S 3™YÑ'€GÝ„|�G˜WÑ%Ô%ð Øˆ	Ø	�3‰˜Ñ	˜w¨™}Ñ	,¨sÑ	2°wÀÑ7HÑI€AØ�1�s‘7Ñ˜cÑ!€AØ
ˆQˆ€BÝ.Ø
ˆB�ñô ð 
å
1°"°b¸"Ñ
=Ô
=ð
õ Ø�-¨¨B°Ñ3Ô3½ÀbÈ"ÈbÑ8QÔ8Qðñ ô ð
ð 	
ð
 €Ir3   c                 óö   — | d         }| d         }t          j        |d         |d         z
  |d         |d         z
  ¦  «        }t          j        | ¦  «                             |d          |d          ¦  «        S )Nr   r°   rY   )rZ   Úatan2r   ÚrotateÚ	translate)ÚsegmentÚstartÚendÚangles       r2   Ú_alignment_transformationr5  Ð  so   € ð �AŒJ€EØ
�"Œ+€CÝŒJ�s˜1”v  a¤Ñ(¨#¨a¬&°5¸´8Ñ*;Ñ<Ô<€EÝŒ?˜E˜6Ñ"Ô"×,Ò,¨e°A¬h¨Y¸¸q¼¸	ÑBÔBÐBr3   c                 ó¶  — t          |¦  «                             | ¦  «        }t          | ¦  «        dk    r1t          |Ž \  }}}t	          |d         |d         |d         ¦  «        }n[t          | ¦  «        dk    r9t          |Ž \  }}}}t          |d         |d         |d         |d         ¦  «        }nt          d¦  «        ‚t          d„ |D ¦   «         ¦  «        S )Nr5   rY   r
  r  c              3   ó:   K  — | ]}d |cxk    rdk    ¯n n|V — ŒdS )rl   rY   Nr7   ©rv   rÃ   s     r2   r¤   z._curve_line_intersections_t.<locals>.<genexpr>ä  s6   è è € Ð<Ð<˜¨c°Q¨m¨mªm¨m¸!ªm¨m¨m¨m¨m�!¨m¨m¨m¨mÐ<Ð<r3   )	r5  ÚtransformPointsrÀ   r   r   r’   r    r  r¦   )ÚcurveÚlineÚaligned_curverf   rg   r¨   Úintersectionsrb   s           r2   Ú_curve_line_intersections_tr>  Ú  sÍ   € Ý-¨dÑ3Ô3×CÒCÀEÑJÔJ€MÝ
ˆ5�z„z�Q‚€Ý)¨=Ð9‰ˆˆ1ˆaÝ& q¨¤t¨Q¨q¬T°1°Q´4Ñ8Ô8ˆˆÝ	ˆU‰Œ�qŠˆÝ(¨-Ð8‰
ˆˆ1ˆa�Ý" 1 Q¤4¨¨1¬¨q°¬t°Q°q´TÑ:Ô:ˆˆåÐ/Ñ0Ô0Ð0ÝÐ<Ð<˜]Ð<Ñ<Ô<Ñ<Ô<Ð<r3   c                 óP  — t          | ¦  «        dk    rt          }n*t          | ¦  «        dk    rt          }nt          d¦  «        ‚g }t	          | |¦  «        D ]M} |g | ¢|‘R Ž }t          g |¢|‘R Ž }t          g |¢|‘R Ž }|                     t          |||¬¦  «        ¦  «         ŒN|S )aæ  Finds intersections between a curve and a line.

    Args:
        curve: List of coordinates of the curve segment as 2D tuples.
        line: List of coordinates of the line segment as 2D tuples.

    Returns:
        A list of ``Intersection`` objects, each object having ``pt``, ``t1``
        and ``t2`` attributes containing the intersection point, time on first
        segment and time on second segment respectively.

    Examples::
        >>> curve = [ (100, 240), (30, 60), (210, 230), (160, 30) ]
        >>> line  = [ (25, 260), (230, 20) ]
        >>> intersections = curveLineIntersections(curve, line)
        >>> len(intersections)
        3
        >>> intersections[0].pt
        (84.9000930760723, 189.87306176459828)
    r5   r
  r  r
   )	rÀ   r!   r"   r  r>  r  r$   r€   r	   )r:  r;  ÚpointFinderr=  rw   r   Úline_ts          r2   r'   r'   ç  s×   € õ* ˆ5�z„z�Q‚€Ý'ˆˆÝ	ˆU‰Œ�qŠˆÝ#ˆˆåÐ/Ñ0Ô0Ð0Ø€MÝ(¨°Ñ5Ô5ð Cð CˆØˆ[Ð#˜%Ð# Ð#Ð#Ð#ˆõ Ð) Ð) bÐ)Ð)Ð)ˆÝÐ(˜4Ð( Ð(Ð(Ð(ˆØ×Ò�\¨R°A¸&ÐAÑAÔAÑBÔBÐBÐBØÐr3   c                 ó�   — t          | ¦  «        dk    r	t          | Ž S t          | ¦  «        dk    r	t          | Ž S t          d¦  «        ‚)Nr5   r
  r  )rÀ   r   r   r  )r¨   s    r2   Ú_curve_boundsrC    sE   € Ý
ˆ1�v„v�‚{€{Ý" AÐ&Ð&Ý	ˆQ‰Œ�1ŠˆÝ Ð"Ð"Ý
Ð+Ñ
,Ô
,Ð,r3   c                 ó  — t          | ¦  «        dk    r| \  }}t          |||¦  «        }||f||fgS t          | ¦  «        dk    rt          g | ¢|‘R Ž S t          | ¦  «        dk    rt          g | ¢|‘R Ž S t	          d¦  «        ‚r	  )rÀ   r$   r   r   r  )r¨   rw   r  r  Úmidpoints        r2   Ú_split_segment_at_trF    s�   € Ý
ˆ1�v„v�‚{€{Ø‰ˆˆ1Ý  1 aÑ(Ô(ˆØ�H� ¨!˜}Ð-Ð-Ý
ˆ1�v„v�‚{€{Ý Ð' !Ð' QÐ'Ð'Ð'Ð'Ý	ˆQ‰Œ�1ŠˆÝÐ#˜aÐ# Ð#Ð#Ð#Ð#Ý
Ð+Ñ
,Ô
,Ð,r3   çü©ñÒMbP?c           	      óÊ  ‡— t          | ¦  «        }t          |¦  «        }|sd}|sd}t          ||¦  «        \  }}|sg S d„ }	t          |¦  «        ‰k     r*t          |¦  «        ‰k     r |	|¦  «         |	|¦  «        fgS t          | d¦  «        \  }
}|d          |	|¦  «        f} |	|¦  «        |d         f}t          |d¦  «        \  }}|d          |	|¦  «        f} |	|¦  «        |d         f}g }|                     t          |
|‰||¬¦  «        ¦  «         |                     t          ||‰||¬¦  «        ¦  «         |                     t          |
|‰||¬¦  «        ¦  «         |                     t          ||‰||¬¦  «        ¦  «         ˆfd„}t          ¦   «         }g }|D ]<} ||¦  «        }||v rŒ|                     |¦  «         |                     |¦  «         Œ=|S )N)rl   rK   c                 ó*   — d| d         | d         z   z  S )Nr6   r   rY   r7   )Úrs    r2   rE  z._curve_curve_intersections_t.<locals>.midpoint1  s   € Ø�a˜”d˜Q˜qœT‘kÑ"Ð"r3   r6   r   rY   )Úrange1Úrange2c                 ód   •— t          | d         ‰z  ¦  «        t          | d         ‰z  ¦  «        fS )Nr   rY   )Úint)r®   Ú	precisions    €r2   ú<lambda>z._curve_curve_intersections_t.<locals>.<lambda>V  s.   ø€ �S  A¤¨Ñ!2Ñ3Ô3µS¸¸A¼ÀÑ9JÑ5KÔ5KÐL€ r3   )	rC  r   r   rF  ÚextendÚ_curve_curve_intersections_tÚsetÚaddr€   )Úcurve1Úcurve2rO  rK  rL  Úbounds1Úbounds2Ú
intersectsÚ_rE  Úc11Úc12Ú	c11_rangeÚ	c12_rangeÚc21Úc22Ú	c21_rangeÚ	c22_rangeÚfoundÚ
unique_keyÚseenÚunique_valuesr®   Úkeys     `                     r2   rR  rR  !  sƒ  ø€ õ ˜FÑ#Ô#€GÝ˜FÑ#Ô#€Gàð ØˆØð Øˆõ ˜W gÑ.Ô.�M€J�Øð Øˆ	ð#ð #ð #õ �ÑÔ˜9Ò$Ð$­°'Ñ):Ô):¸YÒ)FÐ)FØ�˜&Ñ!Ô! 8 8¨FÑ#3Ô#3Ð4Ð5Ð5å" 6¨3Ñ/Ô/�H€CˆØ˜”˜H˜H VÑ,Ô,Ð-€IØ�˜&Ñ!Ô! 6¨!¤9Ð-€Iå" 6¨3Ñ/Ô/�H€CˆØ˜”˜H˜H VÑ,Ô,Ð-€IØ�˜&Ñ!Ô! 6¨!¤9Ð-€Ià€EØ	‡L‚LÝ$Ø��i¨	¸)ð	
ñ 	
ô 	
ñô ð ð
 
‡L‚LÝ$Ø��i¨	¸)ð	
ñ 	
ô 	
ñô ð ð
 
‡L‚LÝ$Ø��i¨	¸)ð	
ñ 	
ô 	
ñô ð ð
 
‡L‚LÝ$Ø��i¨	¸)ð	
ñ 	
ô 	
ñô ð ð MÐLÐLÐL€JÝ‰5Œ5€DØ€Màð !ð !ˆØˆj˜‰nŒnˆØ�$ˆ;ˆ;ØØ�Š�‰ŒˆØ×Ò˜RÑ Ô Ð Ð àÐr3   c                 óx   — t          | ¦  «                             | ¦  «        }t          d„ |D ¦   «         ¦  «        S )Nc              3   óL   K  — | ]}t          j        |d          d¦  «        V — Œ dS )rY   rl   N)rZ   r  )rv   Úps     r2   r¤   z_is_linelike.<locals>.<genexpr>f  s2   è è € Ð:Ð:¨1�tŒ|˜A˜aœD #Ñ&Ô&Ð:Ð:Ð:Ð:Ð:Ð:r3   )r5  r9  Úall)r1  Ú	maybelines     r2   Ú_is_linelikerm  d  s:   € Ý)¨'Ñ2Ô2×BÒBÀ7ÑKÔK€IÝÐ:Ð:°	Ð:Ñ:Ô:Ñ:Ô:Ð:r3   c                 ón  ‡ — t          ‰ ¦  «        rY‰ d         ‰ d         f}t          |¦  «        r|d         |d         f}t          g |¢|¢R Ž S t          ||¦  «        }d„ |D ¦   «         S t          |¦  «        r |d         |d         f}t          ‰ |¦  «        S t          ‰ |¦  «        }ˆ fd„|D ¦   «         S )a  Finds intersections between a curve and a curve.

    Args:
        curve1: List of coordinates of the first curve segment as 2D tuples.
        curve2: List of coordinates of the second curve segment as 2D tuples.

    Returns:
        A list of ``Intersection`` objects, each object having ``pt``, ``t1``
        and ``t2`` attributes containing the intersection point, time on first
        segment and time on second segment respectively.

    Examples::
        >>> curve1 = [ (10,100), (90,30), (40,140), (220,220) ]
        >>> curve2 = [ (5,150), (180,20), (80,250), (210,190) ]
        >>> intersections = curveCurveIntersections(curve1, curve2)
        >>> len(intersections)
        3
        >>> intersections[0].pt
        (81.7831487395506, 109.88904552375288)
    r   r°   c                 óP   — g | ]#}t          |j        |j        |j        ¬ ¦  «        ‘Œ$S ©r
   ©r	   r   r   r   ©rv   rV   s     r2   r~   z+curveCurveIntersections.<locals>.<listcomp>‡  s-   € ÐJÐJÐJÀ•L A¤D¨Q¬T°a´dÐ;Ñ;Ô;ÐJÐJÐJr3   c           	      ót   •— g | ]4}t          t          ‰|d          ¦  «        |d          |d         ¬¦  «        ‘Œ5S )r   rY   r
   )r	   r%   )rv   r®   rU  s     €r2   r~   z+curveCurveIntersections.<locals>.<listcomp>�  sN   ø€ ð ð ð àõ 	�¨°°1´Ñ6Ô6¸2¸a¼5ÀRÈÄUÐKÑKÔKðð ð r3   )rm  r&   r'   rR  )rU  rV  Úline1Úline2ÚhitsÚintersection_tss   `     r2   r(   r(   i  sõ   ø€ õ* �FÑÔð 5Ø�q”	˜6 "œ:Ð%ˆÝ˜ÑÔð 	KØ˜1”I˜v bœzÐ)ˆEÝ(Ð8¨%Ð8°%Ð8Ð8Ð8Ð8å)¨&°%Ñ8Ô8ˆDð KÐJÀTÐJÑJÔJÐJÝ	�fÑ	Ô	ð 5Ø�q”	˜6 "œ:Ð%ˆÝ% f¨eÑ4Ô4Ð4å2°6¸6ÑBÔB€Oðð ð ð à!ðñ ô ð r3   c                 óŠ  — d}t          |¦  «        t          | ¦  «        k    r| |} }d}t          | ¦  «        dk    r5t          |¦  «        dk    rt          | |¦  «        }nUt          | |¦  «        }nDt          | ¦  «        dk    r"t          |¦  «        dk    rt          g | ¢|¢R Ž }nt	          d¦  «        ‚|s|S d„ |D ¦   «         S )a)  Finds intersections between two segments.

    Args:
        seg1: List of coordinates of the first segment as 2D tuples.
        seg2: List of coordinates of the second segment as 2D tuples.

    Returns:
        A list of ``Intersection`` objects, each object having ``pt``, ``t1``
        and ``t2`` attributes containing the intersection point, time on first
        segment and time on second segment respectively.

    Examples::
        >>> curve1 = [ (10,100), (90,30), (40,140), (220,220) ]
        >>> curve2 = [ (5,150), (180,20), (80,250), (210,190) ]
        >>> intersections = segmentSegmentIntersections(curve1, curve2)
        >>> len(intersections)
        3
        >>> intersections[0].pt
        (81.7831487395506, 109.88904552375288)
        >>> curve3 = [ (100, 240), (30, 60), (210, 230), (160, 30) ]
        >>> line  = [ (25, 260), (230, 20) ]
        >>> intersections = segmentSegmentIntersections(curve3, line)
        >>> len(intersections)
        3
        >>> intersections[0].pt
        (84.9000930760723, 189.87306176459828)

    FTrX   z4Couldn't work out which intersection function to usec                 óP   — g | ]#}t          |j        |j        |j        ¬ ¦  «        ‘Œ$S rp  rq  r8  s     r2   r~   z/segmentSegmentIntersections.<locals>.<listcomp>À  s-   € ÐKÐKÐK¸�L˜AœD Q¤T¨a¬dÐ3Ñ3Ô3ÐKÐKÐKr3   )rÀ   r(   r'   r&   r  )Úseg1Úseg2Úswappedr=  s       r2   r)   r)   “  sÖ   € ð< €GÝ
ˆ4�y„y•3�t‘9”9ÒÐØ˜4ˆdˆØˆÝ
ˆ4�y„y�1‚}€}Ýˆt‰9Œ9�qŠ=ˆ=Ý3°D¸$Ñ?Ô?ˆMˆMå2°4¸Ñ>Ô>ˆMˆMÝ	ˆT‰Œ�aŠˆ�C ™IœI¨šN˜NÝ-Ð;¨tÐ;°dÐ;Ð;Ð;ˆˆåÐOÑPÔPÐPØð ØÐØKÐK¸]ÐKÑKÔKÐKr3   c                 ó�   — 	 t          | ¦  «        }dd                     d„ |D ¦   «         ¦  «        z  S # t          $ r d| z  cY S w xY w)zw
    >>> _segmentrepr([1, [2, 3], [], [[2, [3, 4], [0.1, 2.2]]]])
    '(1, (2, 3), (), ((2, (3, 4), (0.1, 2.2))))'
    z(%s)z, c              3   ó4   K  — | ]}t          |¦  «        V — Œd S rQ   )Ú_segmentreprrr  s     r2   r¤   z_segmentrepr.<locals>.<genexpr>Í  s(   è è € Ð!>Ð!>°a¥,¨q¡/¤/Ð!>Ð!>Ð!>Ð!>Ð!>Ð!>r3   z%g)ÚiterÚjoinÚ	TypeError)ÚobjÚits     r2   r  r  Ã  sg   € ð
?Ý�#‰YŒYˆð ˜Ÿ	š	Ð!>Ð!>¸2Ð!>Ñ!>Ô!>Ñ>Ô>Ñ>Ð>øõ ð ð ð Ø�c‰zÐÐÐðøøøs   ‚3 ³AÁAc                 óH   — | D ]}t          t          |¦  «        ¦  «         ŒdS )zlHelper for the doctests, displaying each segment in a list of
    segments on a single line as a tuple.
    N)Úprintr  )rÂ   r1  s     r2   ÚprintSegmentsr‡  Ð  s6   € ð ð %ð %ˆÝ�l˜7Ñ#Ô#Ñ$Ô$Ð$Ð$ð%ð %r3   Ú__main__)r*   )rG  NN)XÚ__doc__ÚfontTools.misc.arrayToolsr   r   r   ÚfontTools.misc.transformr   rZ   Úcollectionsr   r   ÚAttributeErrorÚImportErrorÚfontTools.miscÚcompiledÚCOMPILEDrE   r	   Ú__all__r   r>   ÚreturnsÚdoubleÚlocalsr,   rF   r   rå   rm   ÚcfuncÚinlinerT   r]   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r§   r¬   r´   r[   rÙ   rÚ   rÛ   r   r    r   r’   r³   rÁ   rÏ   rØ   r$   r!   r"   r#   r%   r  r  r&   r5  r>  r'   rC  rF  rR  rm  r(   r)   r  r‡  Ú__name__ÚsysÚdoctestÚexitÚtestmodÚfailedr7   r3   r2   ú<module>rž     sa
  ððð ð EÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ -Ð -Ð -Ð -Ð -Ð -Ø €€€Ø "Ð "Ð "Ð "Ð "Ð "ð&Ø€M€M€M€MøØ˜Ð$ð &ð &ð &à%Ð%Ð%Ð%Ð%Ð%Ð%Ð%ð&øøøð Œ?€ð €ð ˆz˜.Ð*<Ð*<Ð*<Ñ=Ô=€ðð ð €ð@ð ð ð ð&ð ð ð €„�”ÑÔØ€„Ø„~Ø„~Ø„~Ø„~ð	ñ ô ð €„�F”M¨¬¸6¼=ÐIÑIÔIð	
ð 	
ñ JÔIñô ñ Ôð	
ð €„�”ÑÔØ€„ØŒØŒØŒØŒð	ñ ô ð €„ØŒmØ	Œðñ ô ðAð Að Añ	ô ñô ñ ÔðAð €Ø
€ð „Ø„Ø€„�”ÑÔØ€„�&”. V¤^Ð4Ñ4Ô4ð&ð &ñ 5Ô4ñ Ôñ „ñ „ð&ð „Ø„Ø€„�”ÑÔØ€„�”ÐÑÔð;ð ;ñ  Ôñ Ôñ „ñ „ð;ð Pð  Pð  PðF €„�”ÑÔØ€„ØŒØŒØŒØ„~Ø„~Ø„nØ„nðñ ô ð €„Ø
Œ-ØŒ]Ø„mØ„mØ„}Ø„}ØŒðñ ô ðð ñô ñô ñ Ôð&ð@Wð Wð Wð" €„�”ÑÔØ€„ØŒØŒØŒðñ ô ð
 €„Ø„}Ø„}Ø„}ðñ ô ð
ð ñô ñô ñ ÔððBð ð ðDð ð ð< €„�”ÑÔØ€„ØŒØŒØŒØŒð	ñ ô ð €„Ø„}Ø„}Ø„}Ø„}Ø„}ðñ ô ð!"ð !"ñô ñô ñ Ôð!"ðH#ð #ð #ðL6ð 6ð 6ðr*3ð *3ð *3ðZ"2ð "2ð "2ðJ,ð ,ð ,ð0ð ð ð> €„ØŒØŒØŒØŒØ„nØ„nØ„nØ„nð	ñ 	ô 	ð0ð 0ñ	ô 	ð0ð €„�”ÑÔØ€„Ø„mØŒØŒØŒØŒØŒ^Ø	ŒØ	Œð	ñ 	ô 	ð €„Ø„}˜6œ=°´ÈÌðñ ô ðDð Dñô ñ	ô 	ñ  ÔðDð4ð ð ð6 ð  ð  ðF €„Ø„nØ„nØ„nØ„nØ„}Ø„}Ø
Œ-ØŒMØŒMØ„~Ø„~Ø„~Ø„~ðñ ô ð#ð #ñô ð#ð6 %Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $ð "&ð ð ð ð ðBYð Yð YðB(ð (ð (ð2ð 2ð 2ð „Ø„Ø€„ØŒØŒØŒØŒØ„nØ„nØ„nðñ ô ðð ñô ñ „ñ „ðð
(ð 
(ð 
(ð2ð 2ð 2ð  „Ø„Ø€„Ø„nØ„nØ„nØ„nØ„~Ø„~Ø„~ðñ ô ðð ñô ñ „ñ „ðð
Nð 
Nð 
Nðð ð ðð ð ð4 €„�”ÑÔØ€„Ø„mØŒØŒØŒØŒðñ ô ð €„�&”- f¤m¸F¼MÐJÑJÔJðYð Yñ KÔJñô ñ  ÔðYð -ð -ð -ð%ð %ð %ð/ð /ð /ðKð Kð Kð\Cð Cð Cð
=ð 
=ð 
=ð#ð #ð #ðL-ð -ð -ð	-ð 	-ð 	-ð 9=ð@ð @ð @ð @ðF;ð ;ð ;ð
'ð 'ð 'ðT-Lð -Lð -Lð`
?ð 
?ð 
?ð%ð %ð %ð ˆzÒÐØ€J€J€JØ€N€N€Nà€C„Hˆ_ˆWŒ_ÑÔÔ%Ñ&Ô&Ð&Ð&Ð&ð	 Ðs   ž# £3²3