
    ]Mh 0                        	 d dl Z n# eef$ r	 d dlm Z  Y nw xY w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 e j        e j        e j                  	 	 d2deee                  dededeeedf                  fd            Z e	dg d          Z e j        d3i 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        d2d/            Zd0 Z e!d1k    r e              dS dS )4    N)cython)splitCubicAtTC)
namedtuple)ListTupleUnionquadratic_to_curves)	tolerancep0p1p2p3)midderiv3c                 *   t          |          |k    rt          |          |k    rdS | d||z   z  z   |z   dz  }t          |          |k    rdS ||z   |z
  | z
  dz  }t          | | |z   dz  ||z
  ||          o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          U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fontTools/qu2cu/qu2cu.pyr   r   (   s    : 2ww)B9 4 4t R"W"e
+C
3xx)u2glR5(F$
R"WOS6\3	  W
#CvR3I
V
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                 l   d}ddg}t          d|          D ]}| ||z            }| ||z   dz
           }|d         |d         k    sJ t          |d         |d         z
            t          |d         |d         z
            z  }||z  }|z  |                               fd|dd         D             }| |         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 )	zGive a cubic-Bezier spline, reconstruct one cubic-Bezier
    that has the same endpoints and tangents and approxmates
    the spline.g      ?   r   r      c                     g | ]}|z  S r   r   ).0r#   r!   s     r   
<listcomp>z merge_curves.<locals>.<listcomp>   s    	)	)	)A!i-	)	)	)r   N)ranger   append)curvesr   r   r    tsr   ckc_beforer"   r   r   r   r   curver!   s                 @r   merge_curvesr2   e   s   ( JI
B1a[[ 
 
EAI%!)a-( !u####BqEBqEM""S!x{)B%C%CCe
Z	
		) 
*	)	)	)CRC	)	)	)B	q	B	q	B		A	q	!B		A	q	!B 
rBwB-2a55A.	.B	rBw24A2JJ15	5BRE"9r   )countnum_offcurvesioff1off2onc                     t          |           }d}t          |           dz
  }t          d|          D ]A}| |         }| |dz            }|||z
  dz  z   }|                    |dz   |z   |           |dz  }B|S )Nr   r&   r%   r   )listlenr+   insert)pqr3   r4   r5   r6   r7   r8   s           r   add_implicit_on_curvesr?      s     	QAEFFQJM1m$$  tQxTD[C''	Q###
Hr   )cost
is_complexr   Fquadsmax_err	all_cubicreturn.c                 V   t          | d         d                   t          u }|sd | D             } | d         d         g}dg}d}| D ]}|d         |d         k    sJ t          t          |          dz
            D ]1}|dz  }|                    |           |                    |           2t          |          dd         }	|                                 |                    |	           |dz  }|                    |           t          ||||          }
|sd |
D             }
|
S )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   c                 &    g | ]}d  |D             S )c                 4    g | ]\  }}t          ||          S r   )complex)r(   xys      r   r)   z2quadratic_to_curves.<locals>.<listcomp>.<listcomp>   s$    000FQ'!Q--000r   r   )r(   r=   s     r   r)   z'quadratic_to_curves.<locals>.<listcomp>   s'    @@@Q00a000@@@r   r%   r*   r&   Nc                 @    g | ]}t          d  |D                       S )c              3   2   K   | ]}|j         |j        fV  d S N)realimag)r(   cs     r   	<genexpr>z1quadratic_to_curves.<locals>.<listcomp>.<genexpr>   s+      88Q(888888r   )tuple)r(   r1   s     r   r)   z'quadratic_to_curves.<locals>.<listcomp>   s/    MMMU%88%88888MMMr   )	typerI   r+   r;   r,   r?   popextendspline_to_curves)rB   rC   rD   rA   r>   costsr@   r=   r5   qqr-   s              r   r	   r	      sO   F eAhqk""g-J A@@%@@@	q!ACED 
 
u!}}}}s1vvz"" 	 	AAIDLLLL#A&&qrr*				Ta;;F NMMfMMMMr   Solution)
num_pointserrorstart_indexis_cubicr5   jr   r   i_sol_countj_sol_countthis_sol_countr
   errr\   i_sol_errorj_sol_errorr^   r3   r   r   r   r   vuc           
          t                     dk    s
J d             fdt          dt                     dz
  d          D             }t                      }t          dt          |                    D ]}||dz
           d         }||         d         }||         d         }	t          ||z
            t          |	|z
            z   |t          |	|z
            z   k    r|                    |           t          dddd          g}
t          t          |          dz  dz   ddd          }d}t          dt          |          dz             D ]}|}t          ||          D ]}|
|         j        |
|         j        }}|sH|d|z  dz
           |d|z           z
  dz   }||z   }|}t          ||||z
  d          }||k     r|}|dk    rg	 t          ||||z
            \  }}n# t          $ r Y w xY wt          g ||R  }g }d}t          |          D ][\  }}|||z            }t          |d         |d         z
            }t          ||          }||k    r n|                    |           \||k    rt          |          D ]V\  }}|||z            }t          d t          ||          D                       \  }}}	}t!          |||	||          s|dz   } nW||k    r|dz   }t          ||          }t          ||||z
  d	          }||k     r|}|dk    r n|
                    |           ||v r|}g }g } t          |
          dz
  }|rK|
|         j        |
|         j        }"}!|                    |           |                     |"           ||!z  }|Kg }#d}t'          t)          t          ||                               D ]p\  }}"|"r.|#                    t          ||||z
            d                    n9t          ||          D ](}|#                     |dz  |dz  dz                       )|}q|#S )
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 pointsc                 8    g | ]}t          ||d z             S )r   )r   )r(   r5   r>   s     r   r)   z$spline_to_curves.<locals>.<listcomp>  s8       -.1QQY<(  r   r   r&   r%   Fc              3   &   K   | ]\  }}||z
  V  d S rN   r   )r(   rf   rg   s      r   rR   z#spline_to_curves.<locals>.<genexpr>T  s*      &L&LAq1u&L&L&L&L&L&Lr   T)r;   r+   setr   addrZ   r[   r\   r2   ZeroDivisionErrorr   	enumeratemaxr,   rS   zipr   r]   r^   reversedr:   )$r>   rX   r
   rD   elevated_quadraticsforcedr5   r   r   r   sols
impossibler   best_solr_   ra   re   
this_countr`   rd   i_solr1   r.   reconstructed_iterreconstructedr\   r   reconstorigrc   r   splitscubicr3   r^   r-   s$   `                                   r   rW   rW      s2   B q66Q;;;E;;;   273q66A:q2I2I  
 UUF1c-..//   Q'* #A& #A&rBw<<#b2g,,&Sb\\)AAAJJqMMM Q1e$$%D#122Q6:Aq%HHJE1c-..233 B Bua <	 <	A'+Aw'947=K "1q519-a!e<q@
)J6) k1q5%HH8##$H??()<aQGG	rr$    "0!<!<!<!<!<M E'(:;; . .
7*1q51'!*tAw.//E39$$E$$W----y   (66  
7*1q51!&&L&LWd9K9K&L&L&L!L!LBB0RRKK %MEE y   &/Kk511K[+q1udCCEx a   	H;;E FED		AA
 q'-tAw/?xaX	U
	  
 F	AS%7%7 8 899  8 	4MM,':Aq1uEEaHIIII1a[[ 4 4aAA	 123333Ms   G''
G43G4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
|           d S )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   printr;   r	   )r   r   r
   reconstruct_tolerancer1   
quadraticsr-   s          r   mainr     s    888888222222I%MNE##E955J	1Y@U4VV   

7#j//
IJJJ */DEEF	
9CKK
GHH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doublerI   r   r   r2   r?   floatPointboolr	   rZ   rW   r   __name__r   r   r   <module>r      s  &&MMMM$ & & &%%%%%%%%& ? 5 5 5 5 5 5 " " " " " "           !
! 
m~~~~   6>&.999W W :9   W@ ~~~>	  
 
 
 
*jj}m
-m~~~~  $ $  $N 
**j		~  
 
 
 	eE5L!7*+ 	z   6 6U66 6 
%s

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

 

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