ó
    {ñ:iO)  ã                   ó<   • S r SSKrSSKJr  SSKJr   " S S5      rg)z
Tools for triangular grids.
é    N)Ú_api)ÚTriangulationc                   óX   • \ rS rSrSrS r\S 5       rSS jrSS jr	S r
\S 5       rS	rg
)ÚTriAnalyzeré   aT  
Define basic tools for triangular mesh analysis and improvement.

A TriAnalyzer encapsulates a `.Triangulation` object and provides basic
tools for mesh analysis and mesh improvement.

Attributes
----------
scale_factors

Parameters
----------
triangulation : `~matplotlib.tri.Triangulation`
    The encapsulated triangulation to analyze.
c                 óB   • [         R                  " [        US9  Xl        g )N)Útriangulation)r   Úcheck_isinstancer   Ú_triangulation)Úselfr	   s     Ú[/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/matplotlib/tri/_tritools.pyÚ__init__ÚTriAnalyzer.__init__   s   € Ü×Òœm¸=ÒIØ+Õó    c                 óŠ  • U R                   R                  5       n[        R                  " [        R                  " U5      U R                   R
                  R                  S9S:g  nS[        R                  " U R                   R
                  U   5      -  S[        R                  " U R                   R                  U   5      -  4$ )zí
Factors to rescale the triangulation into a unit square.

Returns
-------
(float, float)
    Scaling factors (kx, ky) so that the triangulation
    ``[triangulation.x * kx, triangulation.y * ky]``
    fits exactly inside a unit square.
©Ú	minlengthr   é   )	r   Úget_masked_trianglesÚnpÚbincountÚravelÚxÚsizeÚptpÚy)r   Úcompressed_trianglesÚ	node_useds      r   Úscale_factorsÚTriAnalyzer.scale_factors    s    € ð  $×2Ñ2×GÑGÓIÐÜ—[’[¤§¢Ð*>Ó!?Ø+/×+>Ñ+>×+@Ñ+@×+EÑ+EñGØJKñLˆ	à”B—F’F˜4×.Ñ.×0Ñ0°Ñ;Ó<Ñ<Ø”B—F’F˜4×.Ñ.×0Ñ0°Ñ;Ó<Ñ<ð>ð 	>r   c                 óÀ  • U(       a  U R                   u  p#OSu  p#[        R                  " U R                  R                  U-  U R                  R
                  U-  /5      R                  nX@R                  R                     nUSS2SSS24   USS2SSS24   -
  nUSS2SSS24   USS2SSS24   -
  nUSS2SSS24   USS2SSS24   -
  n[        R                  " USS2S4   USS2S4   5      n[        R                  " USS2S4   USS2S4   5      n[        R                  " USS2S4   USS2S4   5      nXg-   U-   S-  n	X–U-   U	-
  -  Xh-   U	-
  -  Xx-   U	-
  -  n
U
S:H  n[        R                  " U5      (       aq  UR                  S   n[        R                  " U[        R                  S9n[        R                  XÛ'   Xg-  U-  nXë)    S	[        R                  " X«)    5      -  -  XÛ) '   O!Xg-  U-  S	[        R                  " U
5      -  -  nXg-  U-  S	U-  U	-  -  nXý-  nU R                  R                  nUc  U$ [        R                   R#                  UUS
9$ )a¦  
Return a measure of the triangulation triangles flatness.

The ratio of the incircle radius over the circumcircle radius is a
widely used indicator of a triangle flatness.
It is always ``<= 0.5`` and ``== 0.5`` only for equilateral
triangles. Circle ratios below 0.01 denote very flat triangles.

To avoid unduly low values due to a difference of scale between the 2
axis, the triangular mesh can first be rescaled to fit inside a unit
square with `scale_factors` (Only if *rescale* is True, which is
its default value).

Parameters
----------
rescale : bool, default: True
    If True, internally rescale (based on `scale_factors`), so that the
    (unmasked) triangles fit exactly inside a unit square mesh.

Returns
-------
masked array
    Ratio of the incircle radius over the circumcircle radius, for
    each 'rescaled' triangle of the encapsulated triangulation.
    Values corresponding to masked triangles are masked out.

)ç      ð?r"   Nr   r   é   g      à?g        ©Údtypeg      @)Úmask)r   r   Úvstackr   r   r   ÚTÚ	trianglesÚhypotÚanyÚshapeÚemptyÚfloat64ÚinfÚsqrtr&   ÚmaÚarray)r   ÚrescaleÚkxÚkyÚptsÚtri_ptsÚaÚbÚcÚsÚprodÚ	bool_flatÚntriÚcircum_radiusÚabcÚ	in_radiusÚcircle_ratior&   s                     r   Úcircle_ratiosÚTriAnalyzer.circle_ratios2   sU  € ö: Ø×)Ñ)‰HˆR�à!‰HˆRÜ�iŠi˜×,Ñ,×.Ñ.¨rÑ1Ø×,Ñ,×.Ñ.¨rÑ1ð3ó 4ß45±Að 	à×)Ñ)×3Ñ3Ñ4ˆà’A�qš!�GÑ˜w¢q¨!ªQ wÑ/Ñ/ˆØ’A�qš!�GÑ˜w¢q¨!ªQ wÑ/Ñ/ˆØ’A�qš!�GÑ˜w¢q¨!ªQ wÑ/Ñ/ˆÜ�HŠH�Q’q˜!�t‘W˜a¢ 1 ™gÓ&ˆÜ�HŠH�Q’q˜!�t‘W˜a¢ 1 ™gÓ&ˆÜ�HŠH�Q’q˜!�t‘W˜a¢ 1 ™gÓ&ˆà‰S�‰U�C‰KˆØ�A‘#�a‘%‰y˜!™#˜a™%Ñ  !¡# a¡%Ñ(ˆà˜R‘Zˆ	Ü�6Š6�)×Ñà—=‘= Ñ#ˆDÜŸHšH T´·±Ñ<ˆMÜ')§v¡vˆMÑ$Ø‘#�a‘%ˆCØ(+¨J©Ø”B—G’G˜D Ñ,Ó-Ñ-ñ)/ˆM˜*Ò%ð ™S ™U s¬2¯7ª7°4«=Ñ'8Ñ9ˆMØ‘S˜‘U˜s =Ñ0°Ñ2Ñ3ˆ	Ø Ñ.ˆØ×"Ñ"×'Ñ'ˆØ‰<ØÐä—5‘5—;‘;˜|°$�;Ð7Ð7r   c                 ó”  • U R                   R                  R                  S   nU R                  U5      U:  nU R                   R                  nUc  [
        R                  " U[        S9n[
        R                  " U R                   R                  5      n[
        R                  " U[
        R                  S9nSnUS:w  ak  [
        R                  " USS9S:H  U) -  n	X”-  n
X¥-  n[
        R                  " U
5      nSXjSS24'   SXz'   [
        R                  " US:H  SXv   5      nUS:w  a  Mk  [
        R                  R!                  US5      $ )aÓ  
Eliminate excessively flat border triangles from the triangulation.

Returns a mask *new_mask* which allows to clean the encapsulated
triangulation from its border-located flat triangles
(according to their :meth:`circle_ratios`).
This mask is meant to be subsequently applied to the triangulation
using `.Triangulation.set_mask`.
*new_mask* is an extension of the initial triangulation mask
in the sense that an initially masked triangle will remain masked.

The *new_mask* array is computed recursively; at each step flat
triangles are removed only if they share a side with the current mesh
border. Thus, no new holes in the triangulated domain will be created.

Parameters
----------
min_circle_ratio : float, default: 0.01
    Border triangles with incircle/circumcircle radii ratio r/R will
    be removed if r/R < *min_circle_ratio*.
rescale : bool, default: True
    If True, first, internally rescale (based on `scale_factors`) so
    that the (unmasked) triangles fit exactly inside a unit square
    mesh.  This rescaling accounts for the difference of scale which
    might exist between the 2 axis.

Returns
-------
array of bool
    Mask to apply to encapsulated triangulation.
    All the initially masked triangles remain masked in the
    *new_mask*.

Notes
-----
The rationale behind this function is that a Delaunay
triangulation - of an unstructured set of points - sometimes contains
almost flat triangles at its border, leading to artifacts in plots
(especially for high-resolution contouring).
Masked with computed *new_mask*, the encapsulated
triangulation would contain no more unmasked border triangles
with a circle ratio below *min_circle_ratio*, thus improving the
mesh quality for subsequent plots or interpolation.
r   Nr$   éÿÿÿÿr   )ÚaxisT)r   r)   r,   rC   r&   r   ÚzerosÚboolÚcopyÚ	neighborsÚarangeÚint32ÚminÚsumÚwherer1   Úfilled)r   Úmin_circle_ratior3   r>   Úmask_bad_ratioÚcurrent_maskÚvalid_neighborsÚrenum_neighborsÚnaddÚ	wavefrontÚ
added_masks              r   Úget_flat_tri_maskÚTriAnalyzer.get_flat_tri_masku   s*  € ð` ×"Ñ"×,Ñ,×2Ñ2°1Ñ5ˆØ×+Ñ+¨GÓ4Ð7GÑGˆà×*Ñ*×/Ñ/ˆØÑÜŸ8š8 D´Ñ5ˆLÜŸ'š' $×"5Ñ"5×"?Ñ"?Ó@ˆÜŸ)š) D´·±Ñ9ˆØˆØ�a‹iô Ÿš °aÑ8¸BÑ>À<À-ÑOˆIð #Ñ3ˆJØ%Ñ4ˆLÜ—6’6˜*Ó%ˆDð .0ˆOª˜MÑ*Ø*,ˆOÑ'Ü Ÿhšh ¸"Ñ'<¸bØ'6Ñ'GóIˆOð �a�iô  �u‰u�|‰|˜L¨$Ó/Ð/r   c                 óF  • U R                   R                  nU R                   R                  5       nU R                   R                  R                  S   nUb  U R                  U) 5      nO#[        R                  " U[        R                  S9n[        R                  " [        R                  " U5      U R                   R                  R                  S9S:g  nU R                   R                  U   nU R                   R                  U   nU R                  U5      nX‚   nX&XtU4$ )aä  
Compress (if masked) the encapsulated triangulation.

Returns minimal-length triangles array (*compressed_triangles*) and
coordinates arrays (*compressed_x*, *compressed_y*) that can still
describe the unmasked triangles of the encapsulated triangulation.

Returns
-------
compressed_triangles : array-like
    the returned compressed triangulation triangles
compressed_x : array-like
    the returned compressed triangulation 1st coordinate
compressed_y : array-like
    the returned compressed triangulation 2nd coordinate
tri_renum : int array
    renumbering table to translate the triangle numbers from the
    encapsulated triangulation into the new (compressed) renumbering.
    -1 for masked triangles (deleted from *compressed_triangles*).
node_renum : int array
    renumbering table to translate the point numbers from the
    encapsulated triangulation into the new (compressed) renumbering.
    -1 for unused points (i.e. those deleted from *compressed_x* and
    *compressed_y*).

r   r$   r   )r   r&   r   r)   r,   Ú_total_to_compress_renumr   rL   rM   r   r   r   r   r   )	r   Útri_maskr   r>   Ú	tri_renumÚ
valid_nodeÚcompressed_xÚcompressed_yÚ
node_renums	            r   Ú_get_compressed_triangulationÚ)TriAnalyzer._get_compressed_triangulationÀ   s  € ð8 ×&Ñ&×+Ñ+ˆØ#×2Ñ2×GÑGÓIÐØ×"Ñ"×,Ñ,×2Ñ2°1Ñ5ˆØÑØ×5Ñ5°x°iÓ@‰IäŸ	š	 $¬b¯h©hÑ7ˆIô —k’k¤"§(¢(Ð+?Ó"@Ø,0×,?Ñ,?×,AÑ,A×,FÑ,FñHØKLñMˆ
à×*Ñ*×,Ñ,¨ZÑ8ˆØ×*Ñ*×,Ñ,¨ZÑ8ˆØ×2Ñ2°:Ó>ˆ
ð  *Ñ?Ðà$°LØðð 	r   c                 óì   • [         R                  " [         R                  " U 5      S[         R                  S9n[         R                  " U 5      n[         R
                  " U[         R                  S9X'   U$ )ah  
Parameters
----------
valid : 1D bool array
    Validity mask.

Returns
-------
int array
    Array so that (`valid_array` being a compressed array
    based on a `masked_array` with mask ~*valid*):

    - For all i with valid[i] = True:
      valid_array[renum[i]] = masked_array[i]
    - For all i with valid[i] = False:
      renum[i] = -1 (invalid value)
rF   r$   )r   Úfullr   rM   rO   rL   )ÚvalidÚrenumÚn_valids      r   r]   Ú$TriAnalyzer._total_to_compress_renumñ   sJ   € ô& —’œŸš ›¨´"·(±(Ñ;ˆÜ—&’&˜“-ˆÜ—y’y ´·±Ñ9ˆ‰Øˆr   )r   N)T)g{®Gáz„?T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Úpropertyr   rC   rZ   rd   Ústaticmethodr]   Ú__static_attributes__© r   r   r   r      sH   † ñò ,ð ñ>ó ð>ô"A8ôFI0òV/ðb ñó ór   r   )rp   Únumpyr   Ú
matplotlibr   Úmatplotlib.trir   r   rt   r   r   Ú<module>rx      s!   ðñó å Ý (÷|ò |r   