+
     ]iiJ  c                   s   R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ]P                  ]! ^R7      R 4       4       t
 ! R R]4      tR tR	 tR
 tR tRR lt ! R R4      tRR ltRR ltR tR tRR ltR tR tRR ltR# )uP   
A module providing some utility functions regarding Bézier path manipulation.
)	lru_cacheN)_api)Zmaxsizec                 s    W8  d   ^ # \        WV,
          4      p\        P                  ! ^V^,           4      p\        P                  ! V ^,           V,
          V,          4      P	                  \
        4      # )i    )ZminnparangeZprodZastypeZint)nki   && 8/usr/lib64/python3.14/site-packages/matplotlib/bezier.py_combr	      sS     	uA1uA
		!QUA77AEAIq=!((--    c                   s    ] tR t^tRtR# )NonIntersectingPathException N)__name__
__module____qualname____firstlineno____static_attributes__r   r
   r   r   r      s    r
   r   c                sZ  a W0,          W!,          ,
          pWt,          We,          ,
          p	Y2) rYv) rW,          W,          ,
          o\        S4      R8  d   \        R4      hY) rV) T
ppV3R lWVV3 4       w  rppW,          W,          ,           pVV,          VV	,          ,           pVV3# )z
Return the intersection between the line through (*cx1*, *cy1*) at angle
*t1* and the line through (*cx2*, *cy2*) at angle *t2*.
g-q=zcGiven lines do not intersect. Please verify that the angles are not equal or differ by 180 degrees.c              3   s4   <"   T F  qS,          x  K  	  R # 5i)Nr   )Z.0r   ad_bcs   & r   Z	<genexpr>Z#get_intersection.<locals>.<genexpr>9   s     :)9A%ii)9s   )abs
ValueError)Zcx1Zcy1cos_t1sin_t1Zcx2Zcy2cos_t2sin_t2Z	line1_rhsZ	line2_rhsZaZbZcdZa_Zb_Zc_Zd_xyr   s   &&&&&&&&            @r   get_intersectionr       s     v|+Iv|+I 7q7qEAEME
5zE N O 	O RB:""b)9:NBB
'A
Yi'Aa4Kr
   c                s    VR8X  d   WW3# Y2) reV) TrWE,          V ,           WF,          V,           rWG,          V ,           WH,          V,           rWW3# )z
For a line passing through (*cx*, *cy*) and having an angle *t*, return
locations of the two points located along its perpendicular line at the
distance of *length*.
        r   )cxcyZcos_tZsin_tZlengthr   r   r   r   x1y1Zx2Zy2s   &&&&&        r   get_normal_pointsr"   A   sY     |r~FFVUF_r!6?R#7_r!6?R#72>r
   c                 sV    V R R ^V,
          ,          V R,          V,          ,           pV# )N   NNr   )betatZ	next_betar   r   _de_casteljau1r(   Z   s)    Sb	QU#d2hl2Ir
   c                s   \         P                  ! V 4      p V .p \        W4      p VP                  V 4       \	        V 4      ^8X  g   K/   T U u. uF  q ^ ,          NK  	  pp \        T4       U u. uF  q R,          NK  	  pp Y43# u up i u up i )u   
Split a Bézier segment defined by its control points *beta* into two
separate segments divided at *t* and return their control points.
r%   )r   asarrayr(   appendlenZreversed)r&   r'   Z	beta_listZ	left_betaZ
right_betas   &&   r   split_de_casteljaur,   _   s    
 ::dDI
d&t9>%./YTaYI/'/	':;':tr((':J;   0;s   B.B	c                s   V ! V4      pV ! V4      pV! V4      pV! V4      pWx8X  d   WV8w  d   \        R4      h \        P                  ! V^ ,          V^ ,          ,
          V^,          V^,          ,
          4      V8  d   W#3# RW#,           ,          p	V ! V	4      p
V! V
4      pW{,          '       d   T	pWj8X  d   W#3# T
pK  T	pWZ8X  d   W#3# T
pTpK  )u$  
Find the intersection of the Bézier curve with a closed path.

The intersection point *t* is approximated by two parameters *t0*, *t1*
such that *t0* <= *t* <= *t1*.

Search starts from *t0* and *t1* and uses a simple bisecting algorithm
therefore one of the end points must be inside the path while the other
doesn't. The search stops when the distance of the points parametrized by
*t0* and *t1* gets smaller than the given *tolerance*.

Parameters
----------
bezier_point_at_t : callable
    A function returning x, y coordinates of the Bézier at parameter *t*.
    It must have the signature::

        bezier_point_at_t(t: float) -> tuple[float, float]

inside_closedpath : callable
    A function returning True if a given point (x, y) is inside the
    closed path. It must have the signature::

        inside_closedpath(point: tuple[float, float]) -> bool

t0, t1 : float
    Start parameters for the search.

tolerance : float
    Maximal allowed distance between the final points.

Returns
-------
t0, t1 : float
    The Bézier path parameters.
z3Both points are on the same side of the closed path      ?)r   r   Zhypot)bezier_point_at_tinside_closedpatht0t1	toleranceZstartZendZstart_insideZ
end_insideZmiddle_tZmiddleZmiddle_insides   &&&&&       r   *find_bezier_t_intersecting_with_closedpathr3   q   s    L b!E
B
C$U+L"3'J!el*AC 	C  88E!Hs1v%uQx#a&'89IE6M "'?"8,)&1''B} vCB vE(Lr
   c                   s|   a  ] tR t^t o RtR tR tR t]R 4       t	]R 4       t
]R 4       t]R 4       tR	 tR
tV tR# )BezierSegmentu   
A d-dimensional Bézier segment.

Parameters
----------
control_points : (N, d) array
    Location of the *N* control points.
c           	     s\   \         P                  ! V4      V n        V P                  P                  w  V n        V n        \         P                  ! V P                  4      V n        \        V P                  4       Uu. uFx  p\        P                  ! V P                  ^,
          4      \        P                  ! V4      \        P                  ! V P                  ^,
          V,
          4      ,          ,          NKz  	  ppV P                  P                  V,          P                  V n        R# u upi )r$   N)r   r)   _cpointsZshape_N_dr   _ordersZrangemathZ	factorialT_px)selfcontrol_pointsr   Zcoeffs   &&  r   __init__ZBezierSegment.__init__   s    

>2==..yy)  .*(Q !,^^A&!a)HHJ J( 	 * MMOOe+..*s   ;A>D)c                s"   \         P                  ! V4      p\         P                  P                  ^V,
          V P                  RRR1,          4      \         P                  P                  WP                  4      ,          V P
                  ,          # )u   
Evaluate the Bézier curve at point(s) *t* in [0, 1].

Parameters
----------
t : (k,) array-like
    Points at which to evaluate the curve.

Returns
-------
(k, d) array
    Value of the curve for each point in *t*.
Nr%   )r   r)   ZpowerZouterr8   r;   r<   r'      &&r   __call__ZBezierSegment.__call__   s^     JJqMq1udll4R4&89((..LL1259XX> 	>r
   c                s$    \        V ! V4      4      # )zH
Evaluate the curve at a single point, returning a tuple of *d* floats.
)Ztupler?   r@   r   
point_at_tZBezierSegment.point_at_t   s     T!W~r
   c                    V P                   # )z The control points of the curve.)r5   r<      &r   r=   ZBezierSegment.control_points   s     }}r
   c                rC   )zThe dimension of the curve.)r7   rD   rE   r   	dimensionZBezierSegment.dimension   s     wwr
   c                s(    V P                   ^,
          # )z@Degree of the polynomial. One less the number of control points.)r6   rD   rE   r   degreeZBezierSegment.degree   s     ww{r
   c                sv   V P                   pV^
8  d   \        P                  ! R\        4       V P                  p\
        P                  ! V^,           4      R,          p\
        P                  ! V^,           4      R,          pRWC,           ,          \        W44      ,          p\        W4      V,          V,          # )u:  
The polynomial coefficients of the Bézier curve.

.. warning:: Follows opposite convention from `numpy.polyval`.

Returns
-------
(n+1, d) array
    Coefficients after expanding in polynomial basis, where :math:`n`
    is the degree of the Bézier curve and :math:`d` its dimension.
    These are the numbers (:math:`C_j`) such that the curve can be
    written :math:`\sum_{j=0}^n C_j t^j`.

Notes
-----
The coefficients are calculated as

.. math::

    {n \choose j} \sum_{i=0}^j (-1)^{i+j} {j \choose i} P_i

where :math:`P_i` are the control points of the curve.
zFPolynomial coefficients formula unstable for high order Bezier curves!NNNN)NrI   r%   )rG   warningsZwarnZRuntimeWarningr=   r   r   r	   )r<   r   ZPZjr   Z	prefactors   &     r   polynomial_coefficientsZ%BezierSegment.polynomial_coefficients   s    2 KKr6MM 12@BIIacN7#IIacN7#15ME!K/	Q{Y&**r
   c                s   V P                   pV^8:  d-   \        P                  ! . 4      \        P                  ! . 4      3# V P                  p\        P                  ! ^V^,           4      R,          VR,          ,          p. p. p\        VP                  4       F[  w  rg\        P                  ! VRRR1,          4      pVP                  V4       VP                  \        P                  ! W4      4       K]  	  \        P                  ! V4      p\        P                  ! V4      p\        P                  ! V4      V^ 8  ,          V^8*  ,          p	WI,          \        P                  ! V4      V	,          3# )a  
Return the dimension and location of the curve's interior extrema.

The extrema are the points along the curve where one of its partial
derivatives is zero.

Returns
-------
dims : array of int
    Index :math:`i` of the partial derivative which is zero at each
    interior extrema.
dzeros : array of float
    Of same size as dims. The :math:`t` such that :math:`d/dx_i B(t) =
    0`
Nr#   rH   r%   )rG   r   ZarrayrK   r   Z	enumerater:   rootsr*   Z	full_likeconcatenateZisrealZreal)
r<   r   ZCjZdCjZdimsrL   r   pirZin_ranges
   &         r   axis_aligned_extremaZ"BezierSegment.axis_aligned_extrema  s	     KK688B<"--))ii1Q3(2b61suu%EADbD"ALLOKKQ*+ & u%~~d#99U#uz2eqjA~rwwu~h777r
   )r6   r5   r7   r8   r;   N)r   r   r   r   __doc__r>   rA   rB   Zpropertyr=   rF   rG   rK   rP   r   Z__classdictcell__)Z__classdict__s   @r   r4   r4      st     />$       !+ !+F8 8r
   r4   c                s    \        V 4      pVP                  p\        WAVR7      w  rV\        WV,           R,          4      w  rxWx3# )u2  
Split a Bézier curve into two at the intersection with a closed path.

Parameters
----------
bezier : (N, 2) array-like
    Control points of the Bézier segment. See `.BezierSegment`.
inside_closedpath : callable
    A function returning True if a given point (x, y) is inside the
    closed path. See also `.find_bezier_t_intersecting_with_closedpath`.
tolerance : float
    The tolerance for the intersection. See also
    `.find_bezier_t_intersecting_with_closedpath`.

Returns
-------
left, right
    Lists of control points for the two Bézier segments.
)r2   g       @)r4   rB   r3   r,   )	Zbezierr/   r2   Zbzr.   r0   r1   Z_leftZ_rights	   &&&      r   )split_bezier_intersecting_with_closedpathrR   <  sH    , 
v	B7	CFB 'vR2~>ME=r
   c           	     s   ^RI Hp V P                  4       p\        V4      w  rgV! VRR 4      pTp	^ p
^pV FO  w  rgTp
V\	        V4      ^,          ,          pV! VRR 4      V8w  d   \
        P                  ! V	RR V.4      p MTp	KQ  	  \        R4      hVP                  R4      p\        WV4      w  r\	        V4      ^8X  d'   VP                  .pVP                  VP                  .pM\	        V4      ^8X  d=   VP                  VP                  .pVP                  VP                  VP                  .pMm\	        V4      ^8X  dS   VP                  VP                  VP                  .pVP                  VP                  VP                  VP                  .pM\        R4      hVR,          pVR,          pV P                  fX   V! \
        P                  ! V P                   RV V.4      4      pV! \
        P                  ! VV P                   VR .4      4      pMV! \
        P                  ! V P                   RV
 V.4      \
        P                  ! V P                  RV
 V.4      4      pV! \
        P                  ! VV P                   VR .4      \
        P                  ! VV P                  VR .4      4      pV'       d   V'       g   TTppVV3# )	zT
Divide a path into two segments at the point where ``inside(x, y)`` becomes
False.
)PathNz*The path does not intersect with the patchzThis should never be reachedr#   rI   i)r%      )pathrS   Ziter_segmentsZnextr+   r   rM   r   ZreshaperR   ZLINETOZMOVETOZCURVE3ZCURVE4ZAssertionErrorZcodesZvertices)rU   Zinsider2   Zreorder_inoutrS   Z	path_iterZ
ctl_pointsZcommandZbegin_insideZctl_points_oldZioldr   Zbezier_pathZbpZleftZrightZ
codes_leftZcodes_rightZ
verts_leftZverts_rightZpath_inZpath_outs   &&&&                  r   split_path_inoutrV   _  sw   
 ""$Iy/J*RS/*LND	A(
	S_!!*RS/"l2...*=z)JKK#  ) EFF			W	%B;
IKD
4yA~kk]
{{DKK0	Takk4;;/
{{DKK=	Takk4;;<
{{DKKdkkJ;<<bJ(Kzzr~~t}}Ra'8*&EFGT]]125F'GHI r~~t}}Ud';Z&HI~~tzz%4'8*&EFH T]]125F'GHTZZ^'DEG \$gHr
   c                s.   a aa V^,          oV VV3R lpV# )z
Return a function that checks whether a point is in a circle with center
(*cx*, *cy*) and radius *r*.

The returned function has the signature::

    f(xy: tuple[float, float]) -> bool
c                 s\   < V w  rVS,
          ^,          VS,
          ^,          ,           S8  # )rT   r   )Zxyr   r   r   r   r2s   &  r   _fZinside_circle.<locals>._f  s*    B1}B1},r11r
   r   )r   r   rO   rX   rW   s   ff& @r   inside_circlerY     s     
aB2 Ir
   c                 s    W ,
          W1,
          rTWD,          WU,          ,           R ,          pV^ 8X  d   R# WF,          WV,          3# )r-   )r   r   r   )Zx0Zy0r    r!   ZdxZdyr   s   &&&&   r   get_cos_sinrZ     s:    Wbg	27	r!AAv626>r
   c                s    \         P                  ! W4      p\         P                  ! W#4      p\        WV,
          4      pWt8  d   ^# \        V\         P                  ,
          4      V8  d   R# R# )a  
Check if two lines are parallel.

Parameters
----------
dx1, dy1, dx2, dy2 : float
    The gradients *dy*/*dx* of the two lines.
tolerance : float
    The angular tolerance in radians up to which the lines are considered
    parallel.

Returns
-------
is_parallel
    - 1 if two lines are parallel in same direction.
    - -1 if two lines are parallel in opposite direction.
    - False otherwise.
Fr%   )r   Zarctan2r   rN   )Zdx1Zdy1Zdx2Zdy2r2   Ztheta1Ztheta2Zdthetas   &&&&&   r   check_if_parallelr[     sR    & ZZ!FZZ!F!F	Vbee^	y	(	r
   c           
     s   V ^ ,          w  r#V ^,          w  rEV ^,          w  rg\        W$,
          W5,
          WF,
          WW,
          4      pVR8X  d(   \        P                  ! R4       \        W#Wg4      w  rYrM\        W#WE4      w  r\        WEWg4      w  r\	        W#WV4      w  rpp\	        WgWV4      w  pppp \        WV	V
VVW4      w  pp\        VVV	V
VVW4      w  ppW3VV3VV3.pVV3VV3VV3.pVV3#   \         dD    RTT,           ,          RTT,           ,          ppRTT,           ,          RTT,           ,          pp Lfi ; i)u   
Given the quadratic Bézier control points *bezier2*, returns
control points of quadratic Bézier lines roughly parallel to given
one separated by *width*.
z8Lines do not intersect. A straight line is used instead.r-   r%   )r[   r   Zwarn_externalrZ   r"   r   r   )bezier2widthc1xc1ycmxcmyc2xc2yZparallel_testr   r   r   r   c1x_leftc1y_left	c1x_right	c1y_rightZc2x_leftZc2y_leftZ	c2x_rightZ	c2y_rightZcmx_leftZcmy_leftZ	cmx_rightZ	cmy_right	path_left
path_rights   &&                         r   get_parallelsrj     s    qzHCqzHCqzHC%ci&)i<M F	H$Ss8 %Ss8$Ss8 	#FE: -H	9 	#FE: -Hh	9
-h&.4h.4>(  0	9f06	906 @	9  %H%H%'I i(i(i(*J j  )  	

 8h&'80C)D  9y()3)i2G+H 	9	
s   6'C6 6AEEc                s    R^V,          W,           ,
          ,          pR^V,          W,           ,
          ,          pW3Wg3WE3.# )u   
Find control points of the Bézier curve passing through (*c1x*, *c1y*),
(*mmx*, *mmy*), and (*c2x*, *c2y*), at parametric values 0, 0.5, and 1.
r-   r   )r^   r_   ZmmxZmmyrb   rc   r`   ra   s   &&&&&&  r   find_control_pointsrk      sA    
 C39%
&C
C39%
&CJ
SJ//r
   c                s2   V ^ ,          w  rVV ^,          w  rxV ^,          w  r\        WVWx4      w  r\        WxW4      w  r\        WVWW,          4      w  pppp\        WWW,          4      w  ppppWW,           R,          Wh,           R,          ppWy,           R,          W,           R,          ppVV,           R,          VV,           R,          pp\        VVVV4      w  pp\        VVVVW,          4      w  pp p!p"\        VVVV VV4      p#\        VVV!V"VV4      p$V#V$3# )u   
Being similar to `get_parallels`, returns control points of two quadratic
Bézier lines having a width roughly parallel to given one separated by
*width*.
r-   )rZ   r"   rk   )%r\   r]   Zw1ZwmZw2r^   r_   r`   ra   Zc3xZc3yr   r   r   r   rd   re   rf   rg   Zc3x_leftZc3y_leftZ	c3x_rightZ	c3y_rightZc12xZc12yZc23xZc23yZc123xZc123yZcos_t123Zsin_t123Z
c123x_leftZ
c123y_leftZc123x_rightZc123y_rightrh   ri   s%   &&&&&                                r   make_wedged_bezier2rl   *  sA    qzHCqzHCqzHC !34NF 34NF 	#FEJ? -Hh	9 	#FEJ? -Hh	9 )r!CI#3$D)r!CI#3$D4K2%tr'95E %T4t<Hh 	%(EJG 5J
K $Hh$.
$,h8I %Y	%0+%.	;J j  r
   )r         ?{Gz?)rn   )rn   F)gh㈵>)rm   r-   r   )rQ   Z	functoolsr    r9   rJ   Znumpyr   Z
matplotlibr   Z	vectorizer	   r   r   r   r"   r(   r,   r3   r4   rR   rV   rY   rZ   r[   rj   rk   rl   r   r
   r   <module>ro      s          
3.  .	: 	B2
!$I)X|8 |8~F:z&<G!T00!r
   