
    h 0                     h    S SK r \ R                  rS SKJr  S SKJ	r	  S SK
r
S SKJrJrJr  S/r\ R                   \ R"                  " \ R$                  5      \ R&                  " \ R(                  \ R*                  \ R*                  \ R*                  \ R*                  S9\ R&                  " \ R*                  \ R*                  S9S	 5       5       5       5       r\ R&                  " \ R*                  \ R*                  \ R*                  \ R*                  S
9S 5       r\ R                   \ R&                  " \ R$                  \ R$                  \ R$                  \ R(                  \ R(                  \ R(                  \ R(                  \ R*                  \ R*                  \ R*                  \ R*                  S9S 5       5       r\ R&                  " \ R$                  \ R$                  \ R$                  \ R*                  \ R*                  \ R*                  S9S 5       r\\\\4   \4   r\ R&                  " \ R$                  \ R$                  S9  S0S\\\      S\S\S\\\S4      4S jj5       r\	" S/ SQ5      r\ R&                  " S10 S\ R$                  _S\ R$                  _S\ R$                  _S\ R$                  _S\ R$                  _S\ R$                  _S\ R$                  _S \ R(                  _S!\ R(                  _S"\ R(                  _S#\ R(                  _S$\ R(                  _S\ R$                  _S%\ R$                  _S&\ R$                  _S'\ R*                  _S(\ R*                  _S)\ R*                  _S*\ R*                  _S+\ R*                  _S,\ R*                  _6S0S- j5       rS. r \!S/:X  a  \ " 5         gg! \\4 a
    S SKJ r    GNf = f)2    N)cython)splitCubicAtTC)
namedtuple)ListTupleUnionquadratic_to_curves)	tolerancep0p1p2p3)midderiv3c                     [        U5      U::  a  [        U5      U::  a  gU SX-   -  -   U-   S-  n[        U5      U:  a  gX2-   U-
  U -
  S-  n[        X U-   S-  XV-
  XT5      =(       a    [        XUU-   X#-   S-  X45      $ )a\  Check if a cubic Bezier lies within a given distance of the origin.

"Origin" means *the* origin (0,0), not the start of the curve. Note that no
checks are made on the start and end positions of the curve; this function
only checks the inside of the curve.

Args:
    p0 (complex): Start point of curve.
    p1 (complex): First handle of curve.
    p2 (complex): Second handle of curve.
    p3 (complex): End point of curve.
    tolerance (double): Distance from origin.

Returns:
    bool: True if the cubic Bezier ``p`` entirely lies within a distance
    ``tolerance`` of the origin, False otherwise.
T   g      ?F      ?)abscubic_farthest_fit_inside)r   r   r   r   r
   r   r   s          G/var/www/html/env/lib/python3.13/site-packages/fontTools/qu2cu/qu2cu.pyr   r   (   s    : 2w)B9 4 RW"e
+C
3x)glR5(F$
"WOS\3 W
#Cv3
VW    r   r   r   p1_2_3c                 0    US-  nU U S-  U-   US-  U-   U4$ )zAGiven a quadratic bezier curve, return its degree-elevated cubic.gUUUUUU?gUUUUUU? r   s       r   elevate_quadraticr   R   s5     5\F
	u		u	
	 r   )startnk
prod_ratio	sum_ratioratiotr   r   r   r   c                    SnSnS/n[        SU5       Hd  nXU-      nXU-   S-
     nUS   US   :X  d   e[        US   US   -
  5      [        US   US   -
  5      -  n	X9-  nXC-  nUR                  U5        Mf     USS  V
s/ s H  oU-  PM	     nn
X   S   nX   S   nXU-   S-
     S   nXU-   S-
     S   nXU-
  U(       a  US   OS-  -   nXU-
  U(       a  SUS   -
  OS-  -   nXX4nX4$ s  sn
f )z}Give a cubic-Bezier spline, reconstruct one cubic-Bezier
that has the same endpoints and tangents and approxmates
the spline.g      ?   r   r      N)ranger   append)curvesr   r   r    r!   tsr   ckc_beforer"   r#   r   r   r   r   curves                   r   merge_curvesr/   e   sQ   ( JI
B1a[AI!)a-( !u###BqEBqEM"S!x{)B%CC
	
		)  "$CR	)Ai-B	)	q	B	q	B		A	q	!B		A	q	!B 
BwB2a5A.	.B	Bw2A2J15	5BRE9 
*s   C1)countnum_offcurvesioff1off2onc                     [        U 5      nSn[        U 5      S-
  n[        SU5       H5  nX   nXS-      nXVU-
  S-  -   nUR                  US-   U-   U5        US-  nM7     U$ )Nr   r&   r%   r   )listlenr(   insert)pqr0   r1   r2   r3   r4   r5   s           r   add_implicit_on_curvesr<      sy     	QAEFQJM1m$tQxD[C''	Q#
 % Hr   )cost
is_complexquadsmax_err	all_cubicreturn.c                    [        U S   S   5      [        L nU(       d3  U  VVVs/ s H"  oD VVs/ s H  u  pV[        XV5      PM     snnPM$     n nnnU S   S   /nS/nSn	U  H  nUS   US   :X  d   e[        [        U5      S-
  5       H*  n
U	S-  n	UR	                  U	5        UR	                  U	5        M,     [        U5      SS nUR                  5         UR                  U5        U	S-  n	UR	                  U	5        M     [        XxX5      nU(       d"  U Vs/ s H  n[        S U 5       5      PM     nnU$ s  snnf s  snnnf s  snf )a  Converts a connecting list of quadratic splines to a list of quadratic
and cubic curves.

A quadratic spline is specified as a list of points.  Either each point is
a 2-tuple of X,Y coordinates, or each point is a complex number with
real/imaginary components representing X,Y coordinates.

The first and last points are on-curve points and the rest are off-curve
points, with an implied on-curve point in the middle between every two
consequtive off-curve points.

Returns:
    The output is a list of tuples of points. Points are represented
    in the same format as the input, either as 2-tuples or complex numbers.

    Each tuple is either of length three, for a quadratic curve, or four,
    for a cubic curve.  Each curve's last point is the same as the next
    curve's first point.

Args:
    quads: quadratic splines

    max_err: absolute error tolerance; defaults to 0.5

    all_cubic: if True, only cubic curves are generated; defaults to False
r   r%   r'   r&   Nc              3   P   #    U  H  oR                   UR                  4v   M     g 7fN)realimag).0cs     r   	<genexpr>&quadratic_to_curves.<locals>.<genexpr>   s     8%Q(%s   $&)
typecomplexr(   r8   r)   r<   popextendspline_to_curvestuple)r?   r@   rA   r>   r:   xyr;   costsr=   r2   qqr*   r.   s                 r   r	   r	      s8   F eAhqk"g-J:?@%Qa0aFQ'!-a0%@	q!ACEDu!}}s1vz"AAIDLLLL # $A&qr*				T  a;FFLMfU%8%88fMM+ 1@( Ns   
D>D8D>E8D>Solution)
num_pointserrorstart_indexis_cubicr2   jr   r   i_sol_countj_sol_countthis_sol_countr
   errrX   i_sol_errorj_sol_errorrZ   r0   r   r   r   r   vuc           
      z   [        U 5      S:  d   S5       e[        S[        U 5      S-
  S5       Vs/ s H  n[        XUS-    6 PM     nn[        5       n[        S[        U5      5       H[  nXTS-
     S   nXT   S   nXT   S   n	[	        X-
  5      [	        X-
  5      -   U[	        X-
  5      -   :  d  MJ  UR                  U5        M]     [        SSSS5      /n
[        [        U5      S-  S-   SSS5      nSn[        S[        U5      S-   5       GH  nUn[        X5       GHu  nX   R                  X   R                  nnU(       d>  USU-  S-
     USU-     -
  S-   nUU-   nUn[        UUXN-
  S5      nUU:  a  UnUS::  a  Me   [        X^XN-
  5      u  nn[        / UQUQ76 n/ nSn[        U5       HF  u  nnX^U-      n[	        US   US   -
  5      n[        UU5      nUU:  a    OUR                  U5        MH     UU:  a  M  [        U5       HG  u  nnX^U-      n[        S [!        UU5       5       5      u  pxn	n[#        XxU	UU5      (       a  MB  US-   n  O   UU:  a  GMD  US-   n[        UU5      n[        UUXN-
  S5      nUU:  a  UnUS:X  d  GMv    O   U
R                  U5        XF;   d  GM  UnGM     / n/ n [        U
5      S-
  nU(       aL  X   R$                  X   R&                  n"n!UR                  U5        U R                  U"5        UU!-  nU(       a  ML  / n#Sn[)        [+        [!        UU 5      5      5       H_  u  nn"U"(       a!  U#R                  [        X^XN-
  5      S   5        O/[        X5       H   nU#R                  U US-  US-  S-    5        M"     UnMa     U#$ s  snf ! [         a     GM  f = f)	a.  
q: quadratic spline with alternating on-curve / off-curve points.

costs: cumulative list of encoding cost of q in terms of number of
  points that need to be encoded.  Implied on-curve points do not
  contribute to the cost. If all points need to be encoded, then
  costs will be range(1, len(q)+1).
r   z+quadratic spline requires at least 3 pointsr   r&   r%   Fc              3   .   #    U  H  u  pX-
  v   M     g 7frE   r   )rH   rb   rc   s      r   rJ   #spline_to_curves.<locals>.<genexpr>T  s     &L9Kqu9Ks   T)r8   r(   r   setr   addrV   rW   rX   r/   ZeroDivisionErrorr   	enumeratemaxr)   rQ   zipr   rY   rZ   reversedr7   )$r;   rT   r
   rA   r2   elevated_quadraticsforcedr   r   r   sols
impossibler   best_solr[   r]   ra   
this_countr\   r`   i_solr.   r+   reconstructed_iterreconstructedrX   r   reconstorigr_   r   splitscubicr0   rZ   r*   s$                                       r   rP   rP      s   B q6Q;EEE; 383q6A:q2I2IQ1Q<(2I  
 UF1c-./ Q'* #A& #A&rw<#bg,&S\)AAJJqM 0 Q1e$%D#12Q6:Aq%HJE1c-.23uA'+w'9'947==K"1q519-a!e<q@
)J6) k15%H8#$H?()<G	r
 "0!<!<!<M E'(:;
7*q51'!*tAw./E39$$$W- < y  (6
7*q51!&&LWd9K&L!LB0RKK%ME 7 y  &/Kk51K[+qudCEx ay !| 	H;EE 4J FED	AA
'--tw/?/?xaX	U
	 !
 F	AS%7 898MM,':quEaHI1[aAA	23 ! : MSN % s   N&N++
N:9N:c                     SSK Jn   SSKJn  SnUS-  nU " 5       nU" XB5      n[	        SX#4-  5        [	        S[        U5      -  5        [        U/U5      n[	        S[        U5      -  5        [	        S	U5        [	        S
U5        g )Nr   )generate_curve)curve_to_quadraticg?r%   z'cu2qu tolerance %g. qu2cu tolerance %g.z+One random cubic turned into %d quadratics.z-Those quadratics turned back into %d cubics. zOriginal curve:zReconstructed curve(s):)fontTools.cu2qu.benchmarkr|   fontTools.cu2qur}   printr8   r	   )r|   r}   r
   reconstruct_tolerancer.   
quadraticsr*   s          r   mainr     s    82I%ME#E5J	1Y4VV 

7#j/
IJ */DEF	
9CK
GH	
U#	
#V,r   __main__)r   Fr   )"r   AttributeErrorImportErrorfontTools.misccompiledCOMPILEDfontTools.misc.bezierToolsr   collectionsr   mathtypingr   r   r   __all__cfuncreturnsintlocalsdoublerM   r   r   r/   r<   floatPointboolr	   rV   rP   r   __name__r   r   r   <module>r      s  && ?? 5 "   !
! 

mm~~~~~~~~ 6>>&..9W :  W@ ~~~~~~>>	

 
**jjjj}}mm
--mm~~~~~~~~$ $N 
****jj		~~

 	eE5L!7*+ 	zz 6U66 6 
%s

	6	6r j"TU  jjjj jj **	
 

 

 :: mm 	 --   jj ZZ **  ~~!" ~~#$ ~~%& ~~'( nn)* nn+.v/.vr-$ zF  	$ &%%&s   N N10N1