Files
intellecton/venv/lib/python3.12/site-packages/matplotlib/__pycache__/bezier.cpython-312.pyc
T

277 lines
21 KiB
Plaintext
Raw Normal View History

Ë
†RjiJãóúdZddlmZddlZddlZddlZddlmZejed¬«d««Z
Gdd e «Z d
Z
d Zd Zd
Z ddZGdd«Z ddZddZdZdZddZdZdZddZy)uP
A module providing some utility functions regarding Bézier path manipulation.
é)Ú lru_cacheN)Ú_apié€)ÚmaxsizecóÀ||kDryt|||z
«}tjd|dz«}tj|dz|z
|z «j t
«S)Nré)ÚminÚnpÚarangeÚprodÚastypeÚint)Úis úT/home/antigravity/intellecton/venv/lib/python3.12/site-packages/matplotlib/bezier.pyÚ_combrsWð ˆ1‚uØÜ ˆAˆq1‰u‹
€AÜ
!Q˜€AÜ
7‰7‘E˜A‘I˜q‘=Ó Ó có eZdZy)ÚNonIntersectingPathExceptionN)Ú__name__Ú
__module__Ú __qualname__©rrrrsØrrcóü||z||zz
}||z||zz
} || } }
|| }
} |
|
z| | zz
Št«dkr td«|
| }}| |
}}ˆfd||||fD«\}}}}||z|| zz}||z|| zz}||fS)
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.c3ó(K|] }|z Œ y­w)Nr)Ú.0rÚad_bcs €rú <genexpr>z#get_intersection.<locals>.<genexpr>9søèø€Ò: Aa˜%•iÑ:ùsƒ)ÚabsÚ
ValueError)Úcx1Úcy1Úcos_t1Úsin_t1Úcx2Úcy2Úcos_t2Úsin_t2Ú line1_rhsÚ line2_rhsÚa_Úb_Úc_Úd_Úyrs @rÚget_intersectionr6 ø€ð˜ ˜v¨™|Ñ+€Iؘ ˜v¨™|Ñ+€Ið F7€q€AØ F7€q€Aà
‰EA˜E‰M€EÜ
ˆ5ƒzÜðNóOð Oðˆ€B؈Rˆ€BÛ:¨"¨b°"°bÐ)9Ô:N€BˆˆBà
ˆY‰˜˜i™Ñ'€AØ
ˆY‰˜˜i™Ñ'€Aà ˆaˆ4€Krcóx|dk(r||||fS|| }}| |}}||z|z||z|z}
} ||z|z||z|z} } | |
| | fS)
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_pointsrBAssð‚|Ø2r˜2ˆ~Ðà˜U˜FˆF€FØV˜UˆF€Fà
f‰_˜
! 6¨F¡?°RÑ#7ˆ€BØ
f‰_˜
! 6¨F¡?°RÑ#7ˆ€Bà
ˆr2rˆrcó.|ddd|z
z|dd|zz}|S)Néÿÿÿÿrr)ÚbetaÚtÚ next_betas rÚ_de_casteljau1rHZs+ØSb ˜Q ™UÑ# d¨1¨2 ¡lÑ2€IØ Ðrcótj|«}|g} t||«}|j|«t |«dk(rnŒ-|Dcgc]}|dŒ }}t |«Dcgc]}|dŒ }}||fScc}wcc}w)u•
Split a Bézier segment defined by its control points *beta* into two
separate segments divided at *t* and return their control points.
rrrD)r
ÚasarrayrHÚappendÚlenÚreversed)rErFÚ beta_listÚ left_betaÚ
right_betas rÚsplit_de_casteljaurQ_sô
:‰: €DØ€IØ
ܘd AÓØ×јÔÜ ˆt‹9˜Š>Ø ð ð
&/Ö/˜Ta“Ð/€IÐ/Ü'/° Ó':Ö;˜t$r“(Ð;€JÐ  Ð ùò0ùÚ;s Á A8Á& A=cóB||«}||«}||«}||«}||k(r||k7r td« tj|d|dz
|d|dz
«|kr||fSd||zz} || «}
||
«} || z r| }||
k(r||fS|
}n| }||
k(r||fS|
}| }Œj)
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 pathrrçà?)rr
Ú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_closedpathraqñL
˜ !€EÙ
˜
€Cá$ +€LÙ" '€Jà! e¨s¢lÜ Cð Cð ô 8‰8E˜!H˜s 1™vÑ% u¨Q¡x°#°a±&Ñ'8Ó 9¸ r6ˆ˜"˜r™'?ˆÙ" ,ˆÙ)¨&Ó1ˆ
à ˜ ˆfŠ}ð˜2v
؉CàˆBؘŠð˜2v
؈(ˆLð3 rcóheZdZdZdZdZdZed«Zed«Z ed«Z
ed«Z d „Z y
) Ú
BezierSegmentu—
A d-dimensional Bézier segment.
Parameters
----------
control_points : (N, d) array
Location of the *N* control points.
c ótj|«|_|jj\|_|_tj |j«|_t|j«Dcgc]`}tj|jdz
«tj|«tj|jdz
|z
«zzŒb}}|jj|zj|_ ycc}w)Nr)
r
rJÚ_cpointsÚshapeÚ_NÚ_dr Ú_ordersÚrangeÚmathÚ factorialÚ_px)ÚselfÚcontrol_pointsrÚcoeffs rÚ__init__zBezierSegment.__init__ÇÜŸ
 2ˆŒ
ØŸ=™=׈ŒÜ—y‘y §¡ÓŒ ô  §¡›.öô §¡¨!¡ Ó—^‘^ AÓ¯©¸¿¹À!¹ Àa¹Ó)HÑJðð—M‘M—O‘O eÑ.ˆùò*sÁ9A%D cótj|«}tjjd|z
|jddd«tjj||j«z|j
zS)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*.
rNrD)r
rJÚpowerÚouterrirn©rorFs rÚ__call__zBezierSegment.__call__Ðs`ô
J‰Jq‹MˆÜ˜q 1™u d§l¡l±4°R°4Ñ&8Ó—((—..  D§L¡LÓ2Ø59·X±Xñ >rcó$t||««S)zX
Evaluate the curve at a single point, returning a tuple of *d* floats.
)Útuplervs rÚ
point_at_tzBezierSegment.point_at_tâsôT˜!“W‹~Ðrcó|jS)z The control points of the curve.)re©ros rrpzBezierSegment.control_pointsèsð}‰}Ðrcó|jS)zThe dimension of the curve.)rhr|s rÚ dimensionzBezierSegment.dimensionís
ðw‰wˆrcó |jdz
S)z@Degree of the polynomial. One less the number of control points.r)rgr|s rÚdegreezBezierSegment.degreeòsðw‰w˜‰{Ðrcó:|j}|dkDrtjdt«|j}t j |dz«dddf}t j |dz«dddf}d||zzt||«z}t||«|z|zS)
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!rNrD)r€ÚwarningsÚwarnÚRuntimeWarningrpr
r r)rorÚjrÚ prefactors rÚpolynomial_coefficientsz%BezierSegment.polynomial_coefficients÷sð2
K‰Kˆà ˆrŠ6Ü M‰Mð1Ü2@ô
Bà × Ñ ˆÜ I‰I‘c‹Nš1˜d˜7Ñ Ü I‰I‘c‹N˜4¢˜7Ñ Ø˜1˜q™5‘M¤E¨!¨Q£KÑ/ˆ ÜQ˜{˜Ñ*rcó|j}|dkr*tjg«tjg«fS|j}tjd|dz«dddf|ddz}g}g}t |j «D]V\}}tj|ddd«}|j|«|jtj||««ŒXtj|«}tj|«}tj|«|dk\z|dkz} || tj|«| fS)
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`
rNrDr)
r€r
Úarrayr‰r Ú enumeratermÚrootsrKÚ full_likeÚ concatenateÚisrealÚreal)
rorÚCjÚdCjÚdimsrrÚpiÚin_ranges
rÚaxis_aligned_extremaz"BezierSegment.axis_aligned_extremasð
K‰KˆØ Š6Ü—88˜B“<¤§¡¨"£Ð
×
Üi‰i˜˜1˜Q™3Ó¢ 4 Ñ(¨2¨a¨b¨6ÑØˆØˆÜ˜sŸu™uÓ ,‰EˆAˆrܘ™D˜b˜D™Ó"ˆAØ L‰L˜ŒOØ K‰KœŸ  Q¨Ó ˜uÓÜ~‰~˜dÓÜ—9‘9˜UÓ# u°¡zÑ2°e¸q±jÑØH‰~œrŸw™w u~¨hÑ7rN)
rrrÚ__doc__rrrwrzÚpropertyrpr~r€r‰r˜rrrrcrc½slñò>ò$ð ñóððñóððñóððñ!ð!+óF8rrccó„t|«}|j}t|||¬«\}}t|||zdz «\}}||fS)ur
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.
)rYg@)rcrzrarQ) ÚbezierrVrYÚbzrUrWrXÚ_leftÚ_rights rÚ)split_bezier_intersecting_with_closedpathr <sSô,
€BØŸ
Ðä
Ð,¸ ôCF€Bˆô' °R±¸2©~Ó>M€Eˆ &ˆrc óJddlm}|j«}t|«\}}||dd«}|} d}
d} |D]D\}}| }
| t |«dzz
} ||dd«|k7rt j | dd|g«} n|} ŒFtd«| jd«}
t|
||«\}}t |«dk(r&|jg}|j|jg}nµt |«d k(r<|j|jg}|j|j|jg}nkt |«d
k(rR|j|j|jg}|j|j|j|jg}n td «|dd}|dd}|j€U|t j |j d| |g««}|t j ||j | dg««}|t j |j d|
|g«t j |jd|
|g««}|t j ||j | dg«t j ||j| dg««}|r|s||}}||fS) z`
Divide a path into two segments at the point where ``inside(x, y)`` becomes
False.
r)ÚPathéþÿÿÿNréz*The path does not intersect with the patch)rDéézThis should never be reached)Úpathr¢Ú
iter_segmentsÚnextrLr
rr!Úreshaper ÚLINETOÚMOVETOÚCURVE3ÚCURVE4ÚAssertionErrorÚcodesÚvertices)ÚinsiderYÚ
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Ä_sˆõ
Ø×$€Iä˜y€JÙ˜* R S˜/Ó*€Là€Nà €DØ €AàGш
ˆØ ŒS‹_ Ñ
!ˆÙ *˜R˜S "  Ÿ.™.¨.¸¸Ð*=¸zÐ)JÓKˆKÙ Ø#‰ð
GôÐ× Ñ ˜WÓ %€BÜ
ˆFK€Dˆ
ˆ4ƒyA—kk]ˆ
Ø—{‘{ D§K¡KÐ0‰ Ü ˆT‹Ø—k‘k 4§;¡;Ð
Ø—{‘{ D§K¡K°·±Ð=‰ Ü ˆT‹Ø—k‘k 4§;¡;°· ± Ð<ˆ
Ø—{‘{ D§K¡K°·±¸d¿k¹kÐJ‰ äÐab€JØ(€Kà ‡zÙ”r—~~ t§}¡}°R°aÐ'8¸*Ð&EÓGˆÙœŸ¨ °T·]±]À1À2Ð5FÐ'GÓI‰ñ”r—~~ t§}¡}°U°dÐ';¸ZÐ&HÓ—~~ t§z¡z°%°4Ð'8¸*Ð&EÓHˆñœŸ¨ °T·]±]À1À2Ð5FÐ'GÓŸ¨ °T·Z±ZÀÀ°^Ð'DÓGˆñ™\Ø$ gˆà  Ðrcó$|dzŠˆˆˆfd}|S)
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ó6|\}}|z
dz|z
dzzkS)Nr¤r)Úxyr4r5r9r:Úr2s €€€rÚ_fzinside_circle.<locals>._f§s,ø€Øˆˆ1ØB‘˜1‰}  B¡¨1™}Ñ,¨rÑ1rr)r9r:rs`` @rÚ
inside_circlerÊœsú€ð
ˆa‰€Bö €IrcóR||z
||z
}}||z||zzdz}|dk(ry||z ||z fS)NrSr)r8r8r)Úx0Úy0r>r?ÚdxÚdyr/s rÚ get_cos_sinrЯsFØ
"‰Wb˜2gˆ€BØ ˆb‰‘7Ñ ˜rÑ!€AàˆA‚vØØ
‰62˜6ˆrcóÄtj||«}tj||«}t||z
«}||kryt|tjz
«|kryy)
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.
rrDF)r
Úarctan2r r•)Údx1Údy1Údx2Údy2rYÚtheta1Útheta2Údthetas rÚcheck_if_parallelrÚ¸sXô&Z‰Z˜˜