L i0 ddlZejZddlmZddlm Z ddl Z ddl m Z m Z mZdgZej ej"ej$ej&ej(ej*ej*ej*ej*ej&ej*ej*d Zej&ej*ej*ej*ej* d Zej ej&ej$ej$ej$ej(ej(ej(ej(ej*ej*ej*ej* d Zej&ej$ej$ej$ej*ej*ej*dZee eefefZej&ej$ej$ d0de e ededede e edffdZe dgdZej&d1idej$dej$dej$dej$dej$dej$dej$d ej(d!ej(d"ej(d#ej(d$ej(dej$d%ej$d&ej$d'ej*d(ej*d)ej*d*ej*d+ej*d,ej*d0d-Zd.Z e!d/k(re yy#eef$r ddlmZYwxYw)2N)cython)splitCubicAtTC) namedtuple)ListTupleUnionquadratic_to_curves) tolerancep0p1p2p3)midderiv3ct||krt||kry|d||zzz|zdz}t||kDry||z|z |z dz}t|||zdz||z ||xrt|||z||zdz||S)aCheck 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?)abscubic_farthest_fit_inside)r r r rr rrs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.pyrr(s: 2w)B9 4 R"W  "e +C 3x)2glR5 (F $ R"WOS6\3   W #CvR3I VWr r r p1_2_3c0|dz}||dz|z|dz|z|fS)zAGiven a quadratic bezier curve, return its degree-elevated cubic.gUUUUUU?gUUUUUU?rs relevate_quadraticrRs55\F u  u   r) startnk prod_ratio sum_ratioratiotr r r rcd}d}dg}td|D]f}|||z}|||zdz }|d|dk(sJt|d|dz t|d|dz z } || z}||z }|j|h|ddD cgc]} | |z  }} ||d} ||d} |||zdz d} |||zdz d}| | | z |r|dndz z} || |z |rd|dz ndz z} | | | |f}||fScc} w)zGive a cubic-Bezier spline, reconstruct one cubic-Bezier that has the same endpoints and tangents and approxmates the spline.g?rrN)rangerappend)curvesrrr r!tsrckc_beforer"r#r r r rcurves r merge_curvesr/esq(JI B 1a[  EAI %!)a-(!u ###BqEBqEM"S!x{)B%CCe Z  ) "$CR )A!i- )B ) q B q B  A q !B  A q !B rBwB2a5A. .B rBw2A2J15 5B R E "9 *s C/)count num_offcurvesioff1off2onct|}d}t|dz }td|D]7}||}||dz}|||z dzz}|j|dz|z||dz }9|S)Nrr&r%r)listlenr(insert)pqr0r1r2r3r4r5s radd_implicit_on_curvesr<s QA EFQJM 1m $tQx TD[C' ' Q#    Hr)cost is_complexquadsmax_err all_cubicreturn.c nt|ddtu}|s0|Dcgc]!}|Dcgc]\}}t||c}}#}}}}|ddg}dg}d} |D]}|d|dk(sJtt|dz D])} | dz } |j | |j | +t |dd} |j |j| | dz } |j | t||||} |s| D cgc]} td| D} } | Scc}}wcc}}}wcc} w)aConverts 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 rr%r'r&Nc3LK|]}|j|jfywN)realimag).0cs r z&quadratic_to_curves..s8Q(8s"$) typecomplexr(r8r)r<popextendspline_to_curvestuple)r?r@rAr>r:xyr;costsr=r2qqr*r.s rr r sGFeAhqk"g-J :?@@Qa0FQ'!Q-0@@ q! A CE D  u!}}s1vz" A AID LL  LL  $A &qr *      T a ;F FLMU%8%88MM M+1@(Ns D+D%D+D2%D+Solution) num_pointserror start_indexis_cubicr2jrr i_sol_count j_sol_countthis_sol_countr errrW i_sol_error j_sol_errorrYr0r r r rvuc 0t|dk\sJdtdt|dz dDcgc]}t|||dz}}t}tdt|D]^}||dz d}||d}||d} t ||z t | |z z|t | |z zkDsN|j |`t ddddg} t t|dzdzddd} d} tdt|dzD]}| } t| |D]f}| |j| |j}}|s<|d|zdz |d|zz dz}||z}|}t ||||z d}|| kr|} |dkr` t||||z \}}tg||}g}d}t|D]E\}}|||z}t |d|dz }t||}||kDrn|j|G||kDrt|D]D\}}|||z}tdt!||D\}}} }t#||| ||r?|dz}n||kDr7|dz}t||}t ||||z d}|| kr|} |dk(sgn| j| ||vs|} g}g} t| dz }|rH| |j$| |j&}"}!|j|| j|"||!z}|rHg}#d}t)t+t!|| D]Z\}}"|"r#|#jt||||z dn.t||D]}|#j||dz|dzdz!|}\|#Scc}w#t$rYtwxYw) 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). rz+quadratic spline requires at least 3 pointsrr&r%Fc3,K|] \}}||z ywrEr)rHrarbs rrJz#spline_to_curves..Ts&LAq1u&LsT)r8r(rsetraddrUrVrWr/ZeroDivisionErrorr enumeratemaxr)rPziprrXrYreversedr7)$r;rSr rAr2elevated_quadraticsforcedr r r sols impossiblerbest_solrZr\r` this_countr[r_i_solr.r+reconstructed_iter reconstructedrWrreconstorigr^rsplitscubicr0rYr*s$ rrOrOs`B q6Q;EEE;383q6A:q2I-.1QQ<( UF 1c-. / Q ' *  #A &  #A & rBw<#b2g, &Sb\)A A JJqM  Q1e $ %D#12Q6:Aq%HJ E 1c-.2 3Bua< A'+Aw'9'947==K"1q519-a!e rs&& ??5"  ! ! mm ~~ ~~ ~~ ~~ 6>>&..9W:W@ ~~ ~~ ~~ >>     ** jj jj}}mm -- mm ~~ ~~ ~~ ~~ $ $N **** jj   ~~      eE5L!7*+ zz 6 U 6 66 %s  6 6r j"T U jj jj jj **     ::mm   --  jjZZ ** ~~!"~~#$~~%&~~'( nn)* nn+.v/.vr-$ zF  $&%%&sN-- N>=N>