+
    iiJ                        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)maxsizec                     W8  d   ^ # \        WV,
          4      p\        P                  ! ^V^,           4      p\        P                  ! V ^,           V,
          V,          4      P	                  \
        4      # )    )minnparangeprodastypeint)nkis   && q/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/matplotlib/bezier.py_combr      sS     	uA1uA
		!QUA77AEAIq=!((--    c                       ] tR t^tRtR# )NonIntersectingPathException N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r   r      s    r   r   c                Z  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   4   <"   T F  qS,          x  K  	  R # 5i)Nr   ).0r   ad_bcs   & r   	<genexpr>#get_intersection.<locals>.<genexpr>9   s     :)9A%ii)9s   )abs
ValueError)cx1cy1cos_t1sin_t1cx2cy2cos_t2sin_t2	line1_rhs	line2_rhsabcda_b_c_d_xyr   s   &&&&&&&&            @r   get_intersectionr7       s     v|+Iv|+I 7q7qEAEME
5zE N O 	O RB:""b)9:NBB
'A
Yi'Aa4Kr   c                    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cycos_tsin_tlengthr%   r&   r)   r*   x1y1x2y2s   &&&&&        r   get_normal_pointsrC   A   sY     |r~FFVUF_r!6?R#7_r!6?R#72>r   c                 V    V R R ^V,
          ,          V R,          V,          ,           pV# )N   NNr   )betat	next_betas   && r   _de_casteljau1rK   Z   s)    Sb	QU#d2hl2Ir   c                   \         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.
rG   )r   asarrayrK   appendlenreversed)rH   rI   	beta_list	left_beta
right_betas   &&   r   split_de_casteljaurT   _   s    
 ::dDI
d&t9>%./YTaYI/'/	':;':tr((':J;   0;s   B.B	c                   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   hypot)bezier_point_at_tinside_closedpatht0t1	tolerancestartendstart_inside
end_insidemiddle_tmiddlemiddle_insides   &&&&&       r   *find_bezier_t_intersecting_with_closedpathrd   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                   |   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           	     \   \         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 )rF   N)r   rM   _cpointsshape_N_dr	   _ordersrangemath	factorialT_px)selfcontrol_pointsr   coeffs   &&  r   __init__BezierSegment.__init__   s    

>2==..yy)  .*(Q !,^^A&!a)HHJ J( 	 * MMOOe+..*s   ;A>D)c                "   \         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*.
NrG   )r   rM   powerouterrl   rq   rr   rI   s   &&r   __call__BezierSegment.__call__   s^     JJqMq1udll4R4&89((..LL1259XX> 	>r   c                $    \        V ! V4      4      # )zH
Evaluate the curve at a single point, returning a tuple of *d* floats.
)tuplerz   s   &&r   
point_at_tBezierSegment.point_at_t   s     T!W~r   c                    V P                   # )z The control points of the curve.)rh   rr   s   &r   rs   BezierSegment.control_points   s     }}r   c                    V P                   # )zThe dimension of the curve.)rk   r   s   &r   	dimensionBezierSegment.dimension   s     wwr   c                (    V P                   ^,
          # )z@Degree of the polynomial. One less the number of control points.)rj   r   s   &r   degreeBezierSegment.degree   s     ww{r   c                v   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)Nr   rG   )r   warningswarnRuntimeWarningrs   r   r	   r   )rr   r   Pjr   	prefactors   &     r   polynomial_coefficients%BezierSegment.polynomial_coefficients   s    2 KKr6MM 12@BIIacN7#IIacN7#15ME!K/	Q{Y&**r   c                   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`
NrE   r   rG   )r   r   arrayr   r	   	enumeraterp   rootsrN   	full_likeconcatenateisrealreal)
rr   r   CjdCjdimsr   r   pirin_ranges
   &         r   axis_aligned_extrema"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   )rj   rh   rk   rl   rq   N)r   r   r   r   __doc__ru   r{   r   propertyrs   r   r   r   r   r   __classdictcell__)__classdict__s   @r   rf   rf      st     />$       !+ !+F8 8r   rf   c                    \        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.
)r\   g       @)rf   r   rd   rT   )	bezierrY   r\   bzrX   rZ   r[   _left_rights	   &&&      r   )split_bezier_intersecting_with_closedpathr   <  sH    , 
v	B7	CFB 'vR2~>ME=r   c           	        ^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 reachedrE   r   )rG      )pathr   iter_segmentsnextrO   r   r   r"   reshaper   LINETOMOVETOCURVE3CURVE4AssertionErrorcodesvertices)r   insider\   reorder_inoutr   	path_iter
ctl_pointscommandbegin_insidectl_points_oldioldr   bezier_pathbpleftright
codes_leftcodes_right
verts_leftverts_rightpath_inpath_outs   &&&&                  r   split_path_inoutr   _  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                .   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                 \   < V w  rVS,
          ^,          VS,
          ^,          ,           S8  # )r   r   )xyr5   r6   r:   r;   r2s   &  r   _finside_circle.<locals>._f  s*    B1}B1},r11r   r   )r:   r;   r   r   r   s   ff& @r   inside_circler     s     
aB2 Ir   c                     W ,
          W1,
          rTWD,          WU,          ,           R ,          pV^ 8X  d   R# WF,          WV,          3# )rV   )r9   r9   r   )x0y0r?   r@   dxdyr0   s   &&&&   r   get_cos_sinr     s:    Wbg	27	r!AAv626>r   c                    \         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.
FrG   )r   arctan2r!   r   )dx1dy1dx2dy2r\   theta1theta2dthetas   &&&&&   r   check_if_parallelr     sR    & ZZ!FZZ!F!F	Vbee^	y	(	r   c           
        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.rV   rG   )r   r   warn_externalr   rC   r7   r"   )bezier2widthc1xc1ycmxcmyc2xc2yparallel_testr%   r&   r)   r*   c1x_leftc1y_left	c1x_right	c1y_rightc2x_leftc2y_left	c2x_right	c2y_rightcmx_leftcmy_left	cmx_right	cmy_right	path_left
path_rights   &&                         r   get_parallelsr    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                    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.
rV   r   )r   r   mmxmmyr   r   r   r   s   &&&&&&  r   find_control_pointsr     sA    
 C39%
&C
C39%
&CJ
SJ//r   c                2   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*.
rV   )r   rC   r  )%r   r   w1wmw2r   r   r   r   c3xc3yr%   r&   r)   r*   r   r   r   r   c3x_leftc3y_left	c3x_right	c3y_rightc12xc12yc23xc23yc123xc123ycos_t123sin_t123
c123x_left
c123y_leftc123x_rightc123y_rightr   r   s%   &&&&&                                r   make_wedged_bezier2r  *  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   )r9         ?{Gz?)r  )r  F)gh㈵>)r  rV   r9   )r   	functoolsr   rn   r   numpyr   
matplotlibr   	vectorizer   r"   r   r7   rC   rK   rT   rd   rf   r   r   r   r   r   r  r  r  r   r   r   <module>r#     s          
3.  .	: 	B2
!$I)X|8 |8~F:z&<G!T00!r   