+
    5i=3                         ^ RI t ] P                  t^ RIHt ^ RIH	t	 ^ RI
t
^ RIHtHtHt R.t] P                   ] P"                  ! ] P$                  4      ] P&                  ! ] P(                  ] P*                  ] P*                  ] P*                  ] P*                  R7      ] P&                  ! ] P*                  ] P*                  R7      R	 4       4       4       4       t] P&                  ! ] P*                  ] P*                  ] P*                  ] P*                  R
7      R 4       t] P                   ] P&                  ! ] P$                  ] P$                  ] P$                  ] P(                  ] P(                  ] P(                  ] P(                  ] P*                  ] P*                  ] P*                  ] P*                  R7      R 4       4       t] P&                  ! ] P$                  ] P$                  ] P$                  ] P*                  ] P*                  ] P*                  R7      R 4       t]]]]3,          ]3,          tR tR tR t] P&                  ! ] P$                  ] P$                  R7      R/R R ll4       t]	! R. R0O4      t ] P&                  ! R1/ R] P$                  bR] P$                  bR] P$                  bR] P$                  bR] P$                  bR] P$                  bR] P$                  bR ] P(                  bR!] P(                  bR] P(                  bR"] P(                  bR#] P(                  bR$] P$                  bR] P$                  bR%] P$                  bR&] P*                  bR'] P*                  bR(] P*                  bR)] P*                  bR*] P*                  bR+] P*                  b R/R, l4       t!R- t"]#R.8X  d
   ]"! 4        R# R#   ]]3 d    ^ RIH t   ELi ; i)2    N)cython)splitCubicAtTC)
namedtuple)ListTupleUnionquadratic_to_curves)	tolerancep0p1p2p3)midderiv3c                   \        V4      V8:  d   \        V4      V8:  d   R# V ^W,           ,          ,           V,           R,          p\        V4      V8  d   R# W2,           V,
          V ,
          R,          p\        W V,           R,          WV,
          WT4      ;'       d"    \        WUV,           W#,           R,          W44      # )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.
Tg      ?F      ?)abscubic_farthest_fit_inside)r   r   r   r   r
   r   r   s   &&&&&  [/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fontTools/qu2cu/qu2cu.pyr   r   (   s    : 2w)B9 4 RW"e
+C
3x)glR5(F$
"WOS\3 W W
#Cv3
VW    r   r   r   p1_2_3c                X    VR,          pV V R,          V,           VR,          V,           V3# )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                    RpRp^.p\        ^V4       F  pWV,           ,          pWV,           ^,
          ,          pV^ ,          V^,          8X  g   Q h\        V^,          V^ ,          ,
          4      \        V^,          V^,          ,
          4      ,          p	W9,          pWC,          pVP                  V4       K  	  VRR  U
u. uF  qV,          NK  	  pp
W,          ^ ,          pW,          ^,          pWV,           ^,
          ,          ^,          pWV,           ^,
          ,          ^,          pYV,
          V'       d
   V^ ,          M^,          ,           pYV,
          V'       d   ^VR,          ,
          M^,          ,           pWW3pW3# u up
i )z}Give a cubic-Bezier spline, reconstruct one cubic-Bezier
that has the same endpoints and tangents and approxmates
the spline.g      ?N)ranger   append)curvesr   r   r   r    tsr   ckc_beforer!   r"   r   r   r   r   curves   &&&             r   merge_curvesr,   e   sS   ( 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   F)countnum_offcurvesioff1off2onc                    \        V 4      p^ p\        V 4      ^,
          p\        ^V4       FY  pW,          pW^,           ,          pWVV,
          R,          ,           pVP                  V^,           V,           V4       V^,          pK[  	  V# )r   r   )listlenr%   insert)pqr-   r.   r/   r0   r1   r2   s   &       r   add_implicit_on_curvesr9      sy     	QAEFQJM1m$tQxD[C''	Q#
 % Hr   c                 (    \        R V: RV : 24      h)z1Quadratic splines must connect end-to-start; got z then 
ValueError)pointprevious_points   &&r   _raise_incompatible_pointr?      s"    

;N;MVTYS\] r   c                 <    \        V 4      ^8  d   \        R4      hR# )   z0Quadratic splines must contain at least 3 pointsN)r5   r<   )splines   &r   _validate_spline_lengthrC      s    
6{QKLL r   c                 *    V ^ 8:  d   \        R4      hR# )r   z!max_err must be greater than zeroNr;   )max_errs   &r   _validate_positive_tolerancerF      s    !|<== r   )cost
is_complexc                    V ^8  d   QhR\         \         \        ,          ,          R\        R\        R\         \        \        R3,          ,          /# )   quadsrE   	all_cubicreturn.)r   Pointfloatboolr   )formats   "r   __annotate__rR      sM     B BUBB B 
%s

	Br   c                   V '       g   . # \        V4       V  F  p\        V4       K  	  \        V ^ ,          ^ ,          4      \        J pV'       g2   V  UUUu. uF!  qU UUu. uF  w  rg\        Wg4      NK  	  uppNK#  	  p pppV ^ ,          ^ ,          .p^.p	^p
V  F  pVR,          V^ ,          8w  d   \	        V^ ,          VR,          4       \        \        V4      ^,
          4       F.  pV
^,          p
V	P                  V
4       V	P                  V
4       K0  	  \        V4      R,          pV	P                  4        VP                  V4       V
^,          p
V	P                  V
4       K  	  \        WW4      pV'       g<   V Uu. uF/  p\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      NK1  	  ppV# u uppi u upppi u upi )ao  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.
    If ``quads`` is empty, returns an empty list.

    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

Raises:
    ValueError: if an input spline has fewer than 3 points, or if adjacent
    splines do not connect end-to-start.
:   NNc              3   P   "   T F  qP                   VP                  3x  K  	  R # 5iN)realimag).0cs   & r   	<genexpr>&quadratic_to_curves.<locals>.<genexpr>  s     8%Q(%s   $&r$   )rF   rC   typecomplexr?   r%   r5   r&   r9   popextendspline_to_curvestuple)rK   rE   rL   rB   rH   r7   xyr8   costsrG   r/   qqr'   r+   s   &&&            r   r	   r	      su   P 	 )'  eAhqk"g-J:?@%Qa0aFQ'!-a0%@	q!ACEDR5AaD=%adAbE2s1vz"AAIDLLLL # $A&r*				T  a;FFLMfU%%8%8%%8%88fMM- 1@* Ns$   	G F;6GG%G;GSolutionerroris_cubicr/   jr   r   i_sol_countj_sol_countthis_sol_countr
   erri_sol_errorj_sol_errorrL   r-   r   r   r   r   vuc           
     V	   \        V 4      ^8  g   Q R4       h\        ^ \        V 4      ^,
          ^4       Uu. uF  p\        WV^,            !  NK  	  pp\        4       p\        ^\        V4      4       F  pWT^,
          ,          ^,          pWT,          ^ ,          pWT,          ^,          p	\	        W,
          4      \	        W,
          4      ,           V\	        W,
          4      ,           8  g   K{  VP                  V4       K  	  \        ^ ^ ^ R4      .p
\        \        V4      ^,          ^,           ^ ^R4      p^ p\        ^\        V4      ^,           4       EF.  pTp\        W4       EF  pW,          P                  W,          P                  ppV'       ge   V^V,          ^,
          ,          V^V,          ,          ,
          ^,           pVV,           pTp\        VVWN,
          R4      pVV8  d   TpV^8:  d   K   \        W^WN,
          4      w  pp\        . TOTO5!  p. p^ p\        T4       F[  w  ppY^T,           ,          p\	        T^,          T^,          ,
          4      p\        TT4      pTT8  d    MTP                  T4       K]  	  TT8  d   EK0  \        T4       Fx  w  ppY^T,           ,          p\        ;QJ d    . R \!        TT4       4       F  NK  	  5M! R \!        TT4       4       4      w  rxp	p\#        YxT	TT4      '       d   Ko  T^,           p M	  TT8  d   EK  T^,           p\        TT4      p\        TTYN,
          R4      pTT8  d   TpT^8X  g   EK   M	  V
P                  V4       WF9   g   EK,  TpEK1  	  . p. p \        V
4      ^,
          pV'       dR   W,          P$                  W,          P&                  p"p!VP                  V4       V P                  V"4       VV!,          pKY  . p#^ p\)        \+        \!        VV 4      4      4       Ft  w  pp"V"'       d*   V#P                  \        W^WN,
          4      ^ ,          4       M;\        W4       F,  pV#P                  V V^,          V^,          ^,            4       K.  	  TpKv  	  V## u upi   \         d     EKA  i ; i)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).
z+quadratic spline requires at least 3 pointsFc              3   6   "   T F  w  rW,
          x  K  	  R # 5irV   r   )rY   rq   rr   s   &  r   r[   #spline_to_curves.<locals>.<genexpr>p  s     &L9Kquu9Ks   T)r5   r%   r   setr   addrg   
num_pointsrh   r,   ZeroDivisionErrorr   	enumeratemaxr&   rb   zipr   start_indexri   reversedr4   )$r8   re   r
   rL   r/   elevated_quadraticsforcedr   r   r   sols
impossibler   best_solrj   rl   rp   
this_countrk   ro   i_solr+   r(   reconstructed_iterreconstructedrh   r   reconstorigrn   r   splitscubicr-   ri   r'   s$   &&&&                                r   ra   ra     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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   R;RR('R(c                  .   ^ RI Hp  ^ RIHp RpV^,          pV ! 4       pV! WB4      p\	        RW#3,          4       \	        R\        V4      ,          4       \        V.V4      p\	        R\        V4      ,          4       \	        RV4       \	        RV4       R	# )
r   )generate_curve)curve_to_quadraticg?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):N)fontTools.cu2qu.benchmarkr   fontTools.cu2qur   printr5   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   F)rx   rh   r}   ri   r   )$r   AttributeErrorImportErrorfontTools.misccompiledCOMPILEDfontTools.misc.bezierToolsr   collectionsr   mathtypingr   r   r   __all__cfuncreturnsintlocalsdoubler^   r   r   r,   r9   rO   rN   r?   rC   rF   r	   rg   ra   r   __name__r   r   r   <module>r      s  && ?? 5 "   !
! 

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

 

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