+
    £‡iO)  ã                   ó>   € R t ^ RIt^ RIHt ^ RIHt  ! R R4      tR# )z
Tools for triangular grids.
N)Ú_api)ÚTriangulationc                   ód   a € ] tR t^t o RtR t]R 4       tR
R ltRR lt	R t
]R 4       tRtV tR	# )ÚTriAnalyzeraT  
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                óJ   € \         P                  ! \        VR 7       Wn        R# ))ÚtriangulationN)r   Úcheck_isinstancer   Ú_triangulation)Úselfr   s   &&Úx/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/matplotlib/tri/_tritools.pyÚ__init__ÚTriAnalyzer.__init__   s   € Ü×Òœm¸=ÕIØ+Öó    c                ó°  € V P                   P                  4       p\        P                  ! \        P                  ! V4      V P                   P
                  P                  R7      ^ 8g  p^\        P                  ! V P                   P
                  V,          4      ,          ^\        P                  ! V P                   P                  V,          4      ,          3# )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.
©Ú	minlength)	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                óÄ  € V'       d   V P                   w  r#MRRr2\        P                  ! V P                  P                  V,          V P                  P
                  V,          .4      P                  pW@P                  P                  ,          pVR,          VR,          ,
          pVR	,          VR,          ,
          pVR,          VR	,          ,
          p\        P                  ! VR
,          VR,          4      p\        P                  ! VR
,          VR,          4      p\        P                  ! VR
,          VR,          4      pWg,           V,           R,          p	W–V,           V	,
          ,          Wh,           V	,
          ,          Wx,           V	,
          ,          p
V
R8H  p\        P                  ! V4      '       d‘   VP                  ^ ,          p\        P                  ! V\        P                  R7      p\        P                  WÛ&   Wg,          V,          pWë( ,          R\        P                  ! W«( ,          4      ,          ,          WÛ( &   M1Wg,          V,          R\        P                  ! V
4      ,          ,          pWg,          V,          RV,          V	,          ,          pWý,          pV P                  P                  pVf   V# \        P                   P#                  VVR7      # )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.

g      ð?g      à?g        ©Údtypeg      @)Úmask)ºNNNé   r"   )r"   é    r"   )r"   é   r"   )r"   r$   )r"   r#   )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   s  € ÷: Ø×)Ñ)‰HˆRà˜SÜiŠi˜×,Ñ,×.Ñ.¨rÕ1Ø×,Ñ,×.Ñ.¨rÕ1ð3ó 4ß45±Að 	à×)Ñ)×3Ñ3Õ4ˆàGÕ˜w wÕ/Õ/ˆØGÕ˜w wÕ/Õ/ˆØGÕ˜w wÕ/Õ/ˆÜHŠHQt•W˜a gÓ&ˆÜHŠHQt•W˜a gÓ&ˆÜHŠHQt•W˜a gÓ&ˆàSUCKˆØ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                óÂ  € V P                   P                  P                  ^ ,          pV P                  V4      V8  pV P                   P                  pVf   \
        P                  ! V\        R7      p\
        P                  ! V P                   P                  4      p\
        P                  ! V\
        P                  R7      pRpV^ 8w  dw   \
        P                  ! V^R7      R8H  V( ,          p	W”,          p
W¥,          p\
        P                  ! V
4      pRWjR3&   RWz&   \
        P                  ! VR8H  RWv,          4      pK}  \
        P                  P!                  VR4      # )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   )Úaxisr"   Téÿÿÿÿ)r	   r(   r+   rB   r!   r   ÚzerosÚboolÚcopyÚ	neighborsÚarangeÚint32ÚminÚsumÚwherer0   Úfilled)r
   Úmin_circle_ratior2   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ô u‰u|‰|˜L¨$Ó/Ð/r   c                ót  € V P                   P                  pV P                   P                  4       pV P                   P                  P                  ^ ,          pVe   V P                  V( 4      pM&\        P                  ! V\        P                  R7      p\        P                  ! \        P                  ! V4      V P                   P                  P                  R7      ^ 8g  pV P                   P                  V,          pV P                   P                  V,          pV P                  V4      pW‚,          pW&WtV3# )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+   Ú_total_to_compress_renumr   rK   rL   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                óø   € \         P                  ! \         P                  ! V 4      R\         P                  R7      p\         P                  ! V 4      p\         P
                  ! V\         P                  R7      W&   V# )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)
r   rF   )r   Úfullr   rL   rN   rK   )Ú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   rB   rY   rc   Ústaticmethodr\   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      sK   ø‡ € ñò ,ð ñ>ó ð>ô"A8ôFI0òV/ðb ñó ör   r   )ro   Únumpyr   Ú
matplotlibr   Úmatplotlib.trir   r   © r   r   Ú<module>ry      s!   ðñó å Ý (÷|ó |r   