Ë
    ¨ehz3  ã                   óZ   — d Z ddlZddlmZ ddlmZ ddlZ G d„ d«      Z G d„ de«      Z	y)	z'
Mesh refinement for triangular grids.
é    N)Ú_api)ÚTriangulationc                   ó   — e Zd ZdZd„ Zy)Ú
TriRefinera{  
    Abstract base class for classes implementing mesh refinement.

    A TriRefiner encapsulates a Triangulation object and provides tools for
    mesh refinement and interpolation.

    Derived classes must implement:

    - ``refine_triangulation(return_tri_index=False, **kwargs)`` , where
      the optional keyword arguments *kwargs* are defined in each
      TriRefiner concrete implementation, and which returns:

      - a refined triangulation,
      - optionally (depending on *return_tri_index*), for each
        point of the refined triangulation: the index of
        the initial triangulation triangle to which it belongs.

    - ``refine_field(z, triinterpolator=None, **kwargs)``, where:

      - *z* array of field values (to refine) defined at the base
        triangulation nodes,
      - *triinterpolator* is an optional `~matplotlib.tri.TriInterpolator`,
      - the other optional keyword arguments *kwargs* are defined in
        each TriRefiner concrete implementation;

      and which returns (as a tuple) a refined triangular mesh and the
      interpolated values of the field at the refined triangulation nodes.
    c                 óH   — t        j                  t        |¬«       || _        y )N)Útriangulation)r   Úcheck_isinstancer   Ú_triangulation)Úselfr   s     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/matplotlib/tri/_trirefine.pyÚ__init__zTriRefiner.__init__*   s   € Ü×Ñœm¸=ÕIØ+ˆÕó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r   r      s   „ ñó:,r   r   c                   óD   ‡ — e Zd ZdZˆ fd„Zdd„Zdd„Zedd„«       Zˆ xZ	S )	ÚUniformTriRefinerzÆ
    Uniform mesh refinement by recursive subdivisions.

    Parameters
    ----------
    triangulation : `~matplotlib.tri.Triangulation`
        The encapsulated triangulation (to be refined)
    c                 ó$   •— t         ‰| �  |«       y ©N)Úsuperr   )r   r   Ú	__class__s     €r   r   zUniformTriRefiner.__init__=   s   ø€ Ü‰Ñ˜Õ'r   c                 óê  — | j                   }|j                  j                  d   }t        j                  |t        j
                  ¬«      }t        |«      D ]  }| j                  ||«      \  }}Œ |j                  j                  d   }|j                  }|rÜt        j                  |dt        j
                  ¬«      }	| j                   j                  }
|
€-t        j                  |d«      j                  dd«      |	|<   ||	fS |
|   }t        j                  ||   d«      j                  dd«      |	||dd…f   <   t        j                  ||    d«      j                  dd«      |	|| dd…f   <   ||	fS |S )aÞ  
        Compute a uniformly refined triangulation *refi_triangulation* of
        the encapsulated :attr:`triangulation`.

        This function refines the encapsulated triangulation by splitting each
        father triangle into 4 child sub-triangles built on the edges midside
        nodes, recursing *subdiv* times.  In the end, each triangle is hence
        divided into ``4**subdiv`` child triangles.

        Parameters
        ----------
        return_tri_index : bool, default: False
            Whether an index table indicating the father triangle index of each
            point is returned.
        subdiv : int, default: 3
            Recursion level for the subdivision.
            Each triangle is divided into ``4**subdiv`` child triangles;
            hence, the default results in 64 refined subtriangles for each
            triangle of the initial triangulation.

        Returns
        -------
        refi_triangulation : `~matplotlib.tri.Triangulation`
            The refined triangulation.
        found_index : int array
            Index of the initial triangulation containing triangle, for each
            point of *refi_triangulation*.
            Returned only if *return_tri_index* is set to True.
        r   ©ÚdtypeéÿÿÿÿNé   )r
   Ú	trianglesÚshapeÚnpÚarangeÚint32ÚrangeÚ_refine_triangulation_onceÚxÚfullÚmaskÚrepeatÚreshape)r   Úreturn_tri_indexÚsubdivÚrefi_triangulationÚntriÚ	ancestorsÚ_Ú	refi_nptsÚrefi_trianglesÚfound_indexÚtri_maskÚancestor_masks               r   Úrefine_triangulationz&UniformTriRefiner.refine_triangulation@   s‡  € ð< "×0Ñ0ÐØ!×+Ñ+×1Ñ1°!Ñ4ˆô —I‘I˜d¬"¯(©(Ô3ˆ	Ü�v“ò 	/ˆAØ,0×,KÑ,KØ" Ió-/Ñ)Ð¡	ð	/ð '×(Ñ(×.Ñ.¨qÑ1ˆ	Ø+×5Ñ5ˆñ ô Ÿ'™' )¨R´r·x±xÔ@ˆKØ×*Ñ*×/Ñ/ˆHØÐÜ.0¯i©i¸	Ø89ó/;ß;B¹7À2Àq»>ð ˜NÑ+ð & {Ð2Ð2ð !)¨Ñ 3�ä "§	¡	¨)°MÑ*BØ*+ó!-ß-4©W°R¸«^ð ˜N¨=º!Ð+;Ñ<ñ ô !#§	¡	¨)°]°NÑ*CØ*+ó!-ß-4©W°R¸«^ð ˜N¨M¨>º1Ð+<Ñ=ñ ð & {Ð2Ð2à%Ð%r   c                 óH  — |€+t         j                  j                  | j                  |«      }n1t	        j
                  t         j                  j                  |¬«       |}| j                  |d¬«      \  }}|j                  |j                  |j                  |¬«      d   }||fS )aÅ  
        Refine a field defined on the encapsulated triangulation.

        Parameters
        ----------
        z : (npoints,) array-like
            Values of the field to refine, defined at the nodes of the
            encapsulated triangulation. (``n_points`` is the number of points
            in the initial triangulation)
        triinterpolator : `~matplotlib.tri.TriInterpolator`, optional
            Interpolator used for field interpolation. If not specified,
            a `~matplotlib.tri.CubicTriInterpolator` will be used.
        subdiv : int, default: 3
            Recursion level for the subdivision.
            Each triangle is divided into ``4**subdiv`` child triangles.

        Returns
        -------
        refi_tri : `~matplotlib.tri.Triangulation`
             The returned refined triangulation.
        refi_z : 1D array of length: *refi_tri* node count.
             The returned interpolated field (at *refi_tri* nodes).
        )ÚtriinterpolatorT)r,   r+   )Ú	tri_indexr   )Ú
matplotlibÚtriÚCubicTriInterpolatorr
   r   r	   ÚTriInterpolatorr6   Ú_interpolate_multikeysr&   Úy)r   Úzr8   r,   ÚinterpÚrefi_trir3   Úrefi_zs           r   Úrefine_fieldzUniformTriRefiner.refine_field…   s¤   € ð0 Ð"Ü—^‘^×8Ñ8Ø×#Ñ# Qó(‰Fô ×!Ñ!¤*§.¡.×"@Ñ"@Ø2AõCà$ˆFà $× 9Ñ 9Ø¨Dð !:ó !2Ñˆ�+à×.Ñ.Ø�J‰J˜Ÿ
™
¨kð /ó ;Ø;<ñ>ˆà˜ÐÐr   c           
      ód	  — | j                   }| j                  }| j                  }| j                  }t	        j
                  |«      d   }t	        j
                  |«      d   }|�et	        j                  |«      }t	        j
                  |«      |fk7  r7t        dt	        j
                  |«      › dt	        j
                  |«      › �«      ‚t	        j                  |dk(  «      }d|z  |z   dz  }	||	z   }
t	        j                  |
«      }t	        j                  |
«      }||d| ||d| t	        j                  t	        j                  |t        j                  ¬«      d«      }t	        j                  t	        j                  dt        j                  ¬«      |«      }|||f   }||kD  }||   }||   }||||f      ||||d	z   dz  f      z   d
z  }||||f      ||||d	z   dz  f      z   d
z  }|||d |||d |}t	        j                  |dgt        j                  ¬«      }|}t        d«      D ]X  }||k(  }t	        j                  |«      }||   }t	        j                  |t        j                  ¬«      |z   |dd…|f   |<   ||z  }ŒZ t	        j                   |«      }||   }||   }t	        j"                  ||dd…f   t	        j$                  |t	        j&                  dt        j                  ¬«      «      z
  «      }t	        j(                  |d	¬«      } ||   }!||| f   |||!f<   t	        j                  |dz  dgt        j                  ¬«      }"t	        j*                  |dd…df   |dd…df   |dd…df   g«      j,                  |"ddd…dd…f<   t	        j*                  |dd…d	f   |dd…d	f   |dd…df   g«      j,                  |"d	dd…dd…f<   t	        j*                  |dd…df   |dd…df   |dd…d	f   g«      j,                  |"ddd…dd…f<   t	        j*                  |dd…df   |dd…d	f   |dd…df   g«      j,                  |"ddd…dd…f<   t/        |||"«      }#| j0                  �/|#j3                  t	        j                  | j0                  d«      «       |€|#S |#t	        j                  |d«      fS )aë  
        Refine a `.Triangulation` by splitting each triangle into 4
        child-masked_triangles built on the edges midside nodes.

        Masked triangles, if present, are also split, but their children
        returned masked.

        If *ancestors* is not provided, returns only a new triangulation:
        child_triangulation.

        If the array-like key table *ancestor* is given, it shall be of shape
        (ntri,) where ntri is the number of *triangulation* masked_triangles.
        In this case, the function returns
        (child_triangulation, child_ancestors)
        child_ancestors is defined so that the 4 child masked_triangles share
        the same index as their father: child_ancestors.shape = (4 * ntri,).
        r   NzNIncompatible shapes provide for triangulation.masked_triangles and ancestors: z and r   r   é   r   é   g      à?)Úaxisé   )r&   r?   Ú	neighborsr   r!   r    ÚasarrayÚ
ValueErrorÚsumÚzerosÚtiler"   r#   r)   Úemptyr$   Úlogical_notÚabsÚouterÚonesÚargminÚvstackÚTr   r(   Úset_mask)$r   r/   r&   r?   rJ   r   Únptsr.   ÚbordersÚ	added_ptsr1   Úrefi_xÚrefi_yÚ
edge_elemsÚedge_apexesÚedge_neighborsÚmask_mastersÚmastersÚapex_mastersÚx_addÚy_addÚnew_pt_cornerÚnew_pt_midsideÚcum_sumÚimidÚmask_st_locÚn_masters_locÚelem_masters_locÚmask_slavesÚslavesÚslaves_mastersÚ
diff_tableÚslave_masters_apexÚslaves_apexÚchild_trianglesÚchild_triangulations$                                       r   r%   z,UniformTriRefiner._refine_triangulation_once«   sý  € ð( �O‰OˆØ�O‰Oˆð "×+Ñ+ˆ	Ø!×+Ñ+ˆ	Ü�x‰x˜‹{˜1‰~ˆÜ�x‰x˜	Ó" 1Ñ%ˆØÐ ÜŸ
™
 9Ó-ˆIÜ�x‰x˜	Ó" t gÒ-Ü ðEä—x‘x 	Ó*Ð+¨5´·±¸)Ó1DÐ0EðGóHð Hô —&‘&˜ b™Ó)ˆØ�t‘V˜gÑ%¨!Ñ+ˆ	Ø˜9Ñ$ˆ	Ü—‘˜)Ó$ˆÜ—‘˜)Ó$ˆð ˆˆu�ˆØˆˆu�ˆô —W‘WœRŸY™Y t´2·8±8Ô<¸aÓ@ˆ
Ü—i‘i¤§	¡	¨!´2·8±8Ô <¸dÓCˆØ" :¨{Ð#:Ñ;ˆØ" ^Ñ3ˆð ˜\Ñ*ˆØ" <Ñ0ˆØ�9˜W lÐ2Ñ3Ñ4Ø�9˜W |°A¡~¸Ñ&:Ð:Ñ;Ñ<ñ=Ø@CñDˆà�9˜W lÐ2Ñ3Ñ4Ø�9˜W |°A¡~¸Ñ&:Ð:Ñ;Ñ<ñ=Ø@CñDˆàˆˆtˆuˆØˆˆtˆuˆð "ˆô Ÿ™ 4¨ )´2·8±8Ô<ˆØˆÜ˜!“Hò 	%ˆDØ <Ñ/ˆKÜŸF™F ;Ó/ˆMØ& {Ñ3ÐÜ8:¿	¹	Ø¤R§X¡Xô9/Ø18ñ99ˆNš1˜d˜7Ñ#Ð$4Ñ5à�}Ñ$‰Gð	%ô —n‘n \Ó2ˆØ˜KÑ(ˆØ'¨Ñ4ˆÜ—V‘V˜I n²aÐ&7Ñ8ÜŸH™H V¬R¯W©W°Q¼b¿h¹hÔ-GÓHñIó Jˆ
äŸY™Y z¸Ô:ÐØ! +Ñ.ˆØ.<ØÐ.Ð.ñ/0ˆ�v˜{Ð*Ñ+ô Ÿ(™( D¨¡F¨A ;´b·h±hÔ?ˆÜ#%§9¡9Øš!˜Q˜$Ñ ²°1°Ñ!5Øš1˜a˜4Ñ ð."ó $#ç#$¡1ð 	˜˜˜1˜ša˜Ñ ô $&§9¡9Øš!˜Q˜$Ñ ²°1°Ñ!5Øš1˜a˜4Ñ ð."ó $#ç#$¡1ð 	˜˜˜1˜ša˜Ñ ô $&§9¡9Øš!˜Q˜$Ñ ²°1°Ñ!5Øš1˜a˜4Ñ ð."ó $#ç#$¡1ð 	˜˜˜1˜ša˜Ñ ô $&§9¡9Øš1˜a˜4Ñ  .²°A°Ñ"6Øš1˜a˜4Ñ ð."ó $#ç#$¡1ð 	˜˜˜1˜ša˜Ñ ô ,¨F°F¸OÓLÐð ×ÑÐ)Ø×(Ñ(¬¯©°=×3EÑ3EÀqÓ)IÔJàÐØ&Ð&à&¬¯	©	°)¸QÓ(?Ð?Ð?r   )Fr   )Nr   r   )
r   r   r   r   r   r6   rD   Ústaticmethodr%   Ú__classcell__)r   s   @r   r   r   /   s2   ø„ ñô(óC&óJ$ ðL òG@ó ôG@r   r   )
r   Únumpyr!   r:   r   Úmatplotlib.tri._triangulationr   Úmatplotlib.tri._triinterpolater   r   r   r   r   ú<module>rz      s3   ðñó å Ý 7Û %÷ ,ñ  ,ôFD@˜
õ D@r   