
    Li=3                        	 d dl Z e j                  Zd dlmZ d dlm	Z	 d dl
Z
d dlmZmZmZ dg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*                        d	                             Z 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*                        d               Z e j&                  e j$                  e j$                  e j$                  e j*                  e j*                  e j*                        d        Zeeeef   ef   Zd Zd Zd Z e j&                  e j$                  e j$                        	 	 d3deee      dededeeedf      fd       Z  e	dg d      Z! e j&                  d4i de j$                  de j$                  de j$                  de j$                  d e j$                  d!e j$                  d"e j$                  d#e j(                  d$e j(                  d%e j(                  d&e j(                  d'e j(                  de j$                  d(e j$                  d)e j$                  d*e j*                  d+e j*                  d,e j*                  d-e j*                  d.e j*                  d/e j*                  d3d0       Z"d1 Z#e$d2k(  r e#        yy# eef$ r
 d dlm Z  Y w xY w)5    N)cython)splitCubicAtTC)
namedtuple)ListTupleUnionquadratic_to_curves)	tolerancep0p1p2p3)midderiv3c                     t        |      |k  rt        |      |k  ry| d||z   z  z   |z   dz  }t        |      |kD  ry||z   |z
  | z
  dz  }t        | | |z   dz  ||z
  ||      xr t        |||z   ||z   dz  ||      S )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          [/home/ubuntu/crypto_trading_bot/.venv/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.pyr   r   (   s    : 2w)B9 4 R"W"e
+C
3x)2glR5(F$
R"WOS6\3	 W
#CvR3I
VW    r   r   r   p1_2_3c                 0    |dz  }| | dz  |z   |dz  |z   |fS )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                    d}d}dg}t        d|      D ]f  }| ||z      }| ||z   dz
     }|d   |d   k(  sJ t        |d   |d   z
        t        |d   |d   z
        z  }	||	z  }||z  }|j                  |       h |dd D 
cg c]  }
|
|z  	 }}
| |   d   }| |   d   }| ||z   dz
     d   }| ||z   dz
     d   }|||z
  |r|d   ndz  z   }|||z
  |rd|d   z
  ndz  z   }||||f}||fS c c}
w )zGive 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[ 
EAI%!)a-( !u###BqEBqEM"S!x{)B%CCe
Z	
		)
 "$CR	)A!i-	)B	)	q	B	q	B		A	q	!B		A	q	!B 
rBwB2a5A.	.B	rBw2A2J15	5BRE"9 
*s   C/)countnum_offcurvesioff1off2onc                     t        |       }d}t        |       dz
  }t        d|      D ]7  }| |   }| |dz      }|||z
  dz  z   }|j                  |dz   |z   |       |dz  }9 |S )Nr   r&   r%   r   )listlenr(   insert)pqr0   r1   r2   r3   r4   r5   s           r   add_implicit_on_curvesr<      s     	QAEFQJM1m$ tQxTD[C''	Q#
 Hr   c                 $    t        d|d|       )Nz1Quadratic splines must connect end-to-start; got z then 
ValueError)pointprevious_points     r   _raise_incompatible_pointrB      s"    

;N;MVTYS\] r   c                 6    t        |       dk  rt        d      y )Nr   z0Quadratic splines must contain at least 3 points)r8   r?   )splines    r   _validate_spline_lengthrE      s    
6{QKLL r   c                 $    | dk  rt        d      y )Nr   z!max_err must be greater than zeror>   )max_errs    r   _validate_positive_tolerancerH      s    !|<== r   )cost
is_complexquadsrG   	all_cubicreturn.c                    | sg S t        |       | D ]  }t        |        t        | d   d         t        u }|s0| D cg c]!  }|D cg c]  \  }}t        ||       c}}# } }}}| d   d   g}dg}	d}
| D ]  }|d   |d   k7  rt	        |d   |d          t        t        |      dz
        D ])  }|
dz  }
|	j                  |
       |	j                  |
       + t        |      dd }|	j                          |j                  |       |
dz  }
|	j                  |
        t        ||	||      }|s|D cg c]  }t        d |D               }}|S c c}}w c c}}}w c c}w )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.
        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.
    r   r%   r'   r&   Nc              3   L   K   | ]  }|j                   |j                  f  y wN)realimag).0cs     r   	<genexpr>z&quadratic_to_curves.<locals>.<genexpr>  s     8Q(8s   "$)rH   rE   typecomplexrB   r(   r8   r)   r<   popextendspline_to_curvestuple)rK   rG   rL   rD   rJ   r:   xyr;   costsrI   r2   qqr*   r.   s                  r   r	   r	      s}   P 	 ) ('( eAhqk"g-J:?@@Qa0FQ'!Q-0@@	q!ACED R5AaD=%adAbE2s1vz" 	AAIDLLLL	 $A&qr*				T a;FFLMU%8%88MMM- 1@* Ns   
EE!E9E#ESolution)
num_pointserrorstart_indexis_cubicr2   jr   r   i_sol_countj_sol_countthis_sol_countr
   errrb   i_sol_errorj_sol_errorrd   r0   r   r   r   r   vuc           
      0   t        |       dk\  sJ d       t        dt        |       dz
  d      D cg c]  }t        | ||dz      }}t               }t        dt        |            D ]^  }||dz
     d   }||   d   }||   d   }	t	        ||z
        t	        |	|z
        z   |t	        |	|z
        z   kD  sN|j                  |       ` t        dddd      g}
t        t        |      dz  dz   ddd      }d}t        dt        |      dz         D ]  }|}t        ||      D ]f  }|
|   j                  |
|   j                  }}|s<|d|z  dz
     |d|z     z
  dz   }||z   }|}t        ||||z
  d      }||k  r|}|dk  r`	 t        ||||z
        \  }}t        g || }g }d}t        |      D ]E  \  }}|||z      }t	        |d   |d   z
        }t        ||      }||kD  r n|j                  |       G ||kD  rt        |      D ]D  \  }}|||z      }t        d t!        ||      D              \  }}}	}t#        |||	||      r?|dz   } n ||kD  r7|dz   }t        ||      }t        ||||z
  d      }||k  r|}|dk(  sg n |
j                  |       ||v s|} g }g } t        |
      dz
  }|rH|
|   j$                  |
|   j&                  }"}!|j                  |       | j                  |"       ||!z  }|rHg }#d}t)        t+        t!        ||                   D ]Z  \  }}"|"r#|#j                  t        ||||z
        d          n.t        ||      D ]  }|#j                  | |dz  |dz  dz           ! |}\ |#S c c}w # t        $ r Y tw xY w)	aF  
    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   ,   K   | ]  \  }}||z
    y wrP   r   )rS   rl   rm   s      r   rU   z#spline_to_curves.<locals>.<genexpr>p  s     &LAq1u&Ls   T)r8   r(   r   setr   addr`   ra   rb   r/   ZeroDivisionErrorr   	enumeratemaxr)   r[   zipr   rc   rd   reversedr7   )$r;   r^   r
   rL   r2   elevated_quadraticsforcedr   r   r   sols
impossibler   best_solre   rg   rk   
this_countrf   rj   i_solr.   r+   reconstructed_iterreconstructedrb   r   reconstorigri   r   splitscubicr0   rd   r*   s$                                       r   rZ   rZ     s`   B q6Q;EEE; 383q6A:q2I-.1QQ<( 
 UF1c-./  Q'* #A& #A&rBw<#b2g,&Sb\)AAJJqM Q1e$%D#12Q6:Aq%HJE1c-.23 Bua <	A'+Aw'9'947==K"1q519-a!e<q@
)J6) k1q5%H8#$H?()<aQG	r
 "0!<!<!<M E'(:; .
7*1q51'!*tAw./E39$$$W-. y  (6 
7*1q51!&&LWd9K&L!LBB0RRK%ME y  &/Kk51K[+q1udCEx ay<	| 	H;EEBJ FED	AA
q'--tAw/?/?xaX	U
	 
 F	AS%7 89 8MM,':Aq1uEaHI1a[ 4aAA	234 MSN % s   NN	NNc                     ddl m}  ddlm} d}|dz  } |        } |||      }t	        d||fz         t	        dt        |      z         t        |g|      }t	        dt        |      z         t	        d	|       t	        d
|       y )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#E95J	1Y@U4V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doublerW   r   r   r/   r<   floatPointrB   rE   rH   boolr	   r`   rZ   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UBB B 
%s

	B	BJ j"TU  jjjj jj **	
 

 

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