Ë rL iO)ãó<—dZddlZddlmZddlmZGd„d«Zy)z Tools for triangular grids. éN)Ú_api)Ú TriangulationcóL—eZdZdZd„Zed„«Zd d„Zd d„Zd„Z e d„«Z y) Ú TriAnalyzera€ 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óH—tjt|¬«||_y)N)Ú triangulation)rÚcheck_isinstancerÚ_triangulation)Úselfrs ú^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/tri/_tritools.pyÚ__init__zTriAnalyzer.__init__s€Ü ×Ñœm¸=ÕIØ+ˆÕócóˆ—|jj«}tjtj|«|jj j ¬«dk7}dtj|jj |«z dtj|jj|«z fS)a- 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_factorszTriAnalyzer.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°Ñ;Ó<Ñ<ð>ð >rcóÄ—|r|j\}}nd\}}tj|jj|z|jj |zg«j }||jj}|dd…ddd…f|dd…ddd…fz }|dd…ddd…f|dd…ddd…fz }|dd…ddd…f|dd…ddd…fz }tj|dd…df|dd…df«}tj|dd…df|dd…df«}tj|dd…df|dd…df«}||z|zdz} | ||z| z z||z| z z||z| z z} | dk(} tj| «rw|jd} tj| tj¬«} tj| | <||z|z}|| d tj| | «zz | | <n!||z|zd tj| «zz } ||z|zd | z| zz }|| z }|jj}|€|Stj j#||¬ «S) aN 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. )çð?rNrrégà?g©Údtypeg@)Úmask)rrÚvstackr rrÚ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_ratioszTriAnalyzer.circle_ratios2sn€ñ: Ø×)Ñ)‰HˆR‘à!‰HˆRÜi‰i˜×,Ñ,×.Ñ.¨rÑ1Ø×,Ñ,×.Ñ.¨rÑ1ð3ó4ß45±Að àd×)Ñ)×3Ñ3Ñ4ˆà ’Aqš!GÑ ˜w¢q¨!ªQ wÑ/Ñ /ˆØ ’Aqš!GÑ ˜w¢q¨!ªQ wÑ/Ñ /ˆØ ’Aqš!GÑ ˜w¢q¨!ªQ wÑ/Ñ /ˆÜ H‰HQ’q˜!t‘W˜a¢ 1 ™gÓ &ˆÜ H‰HQ’q˜!t‘W˜a¢ 1 ™gÓ &ˆÜ H‰HQ’q˜!t‘W˜a¢ 1 ™gÓ &ˆà ˆq‰S‰UC‰KˆØ!A‘#a‘%‰y˜!˜A™#˜a™%Ñ  ! A¡# a¡%Ñ(ˆà˜R‘Zˆ Ü 6‰6)Ô à—=‘= Ñ#ˆDÜŸH™H T´·±Ô<ˆMÜ')§v¡vˆM˜)Ñ $ØA‘#a‘%ˆCØ(+¨Y¨J©Ø”B—G‘G˜D ) Ñ,Ó-Ñ-ñ)/ˆM˜9˜*Ò %ð˜q™S ™U s¬2¯7©7°4«=Ñ'8Ñ9ˆMØq‘S˜‘U˜s =Ñ0°Ñ2Ñ3ˆ Ø  Ñ.ˆ Ø×"Ñ"×'Ñ'ˆØ ˆ<ØÐ ä—5‘5—;‘;˜|°$;Ó7Ð 7rcóœ—|jjjd}|j|«|k}|jj}|€t j |t¬«}t j|jj«}t j|t j¬«}d}|dk7rnt j|d¬«dk(|z} | |z} | |z}t j| «}d|| dd…f<d|| <t j|dk(d||«}|dk7rŒnt jj!|d«S)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. rNr!éÿÿÿÿr)ÚaxisT)r r&r)r@r#rÚzerosÚboolÚcopyÚ neighborsÚarangeÚint32ÚminÚsumÚwherer.Úfilled) r Úmin_circle_ratior0r;Úmask_bad_ratioÚ current_maskÚvalid_neighborsÚrenum_neighborsÚnaddÚ wavefrontÚ added_masks r Úget_flat_tri_maskzTriAnalyzer.get_flat_tri_maskus4€ð`×"Ñ"×,Ñ,×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˜Jª˜MÑ *Ø*,ˆO˜JÑ 'Ü Ÿh™h ¸"Ñ'<¸bØ'6°Ñ'GóIˆOða‹iô u‰u|‰|˜L¨$Ó/Ð/rcóP—|jj}|jj«}|jjjd}||j |«}n%t j|t j¬«}t jt j|«|jjj¬«dk7}|jj|}|jj|}|j |«}||}|||||fS)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*). rr!r)r r#rr&r)Ú_total_to_compress_renumrrHrIrrrrr) r Útri_maskrr;Ú tri_renumÚ valid_nodeÚ compressed_xÚ compressed_yÚ node_renums r Ú_get_compressed_triangulationz)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°LÀ)Øðð rcóò—tjtj|«dtj¬«}tj|«}tj |tj¬«||<|S)aØ 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) rBr!)rÚfullrrIrKrH)ÚvalidÚrenumÚn_valids r rXz$TriAnalyzer._total_to_compress_renumñsL€ô&—‘œŸ™ ›¨´"·(±(Ô;ˆÜ—&‘&˜“-ˆÜ—y‘y ´·±Ô9ˆˆe‰ ؈ rN)T)g{®Gáz„?T) Ú__name__Ú __module__Ú __qualname__Ú__doc__r Úpropertyrr@rVr_Ú staticmethodrX©rr rr sH„ñò ,ðñ>óð>ó"A8óFI0òV/ðbñóñrr)rhÚnumpyrÚ matplotlibrÚmatplotlib.trirrrkrr úros!ðñóåÝ(÷|ò|r