o
    ñh…  ã                   @   s`   d dl Zd dlmZ g d¢Zeddd„ƒZdd„ Zeddd	„ƒZedd
d„ƒZ	eddd„ƒZ
dS )é    N)Ú	decorator)Údelaunay_plot_2dÚconvex_hull_plot_2dÚvoronoi_plot_2dc              	   K   sš   dd l m} |d u r| ¡ }| ¡ }| |fd|i|¤ŽS t|ddd„ ƒƒ }|r1| |fd|i|¤ŽS z| d¡ | |fd|i|¤ŽW | |¡ S | |¡ w )Nr   ÚaxÚisholdc                   S   s   dS )NT© r   r   r   úL/var/www/vscode/kcb/lib/python3.10/site-packages/scipy/spatial/_plotutils.pyÚ<lambda>   s    z_held_figure.<locals>.<lambda>T)Úmatplotlib.pyplotÚpyplotÚfigureÚgcaÚgetattrÚhold)ÚfuncÚobjr   ÚkwÚpltÚfigÚwas_heldr   r   r	   Ú_held_figure   s   
r   c                 C   s^   dt j|dd }|jdd| }|jdd| }|  |d |d ¡ |  |d |d ¡ d S )Ngš™™™™™¹?r   ©Úaxisé   )ÚnpÚptpÚminÚmaxÚset_xlimÚset_ylim)r   ÚpointsÚmarginÚxy_minÚxy_maxr   r   r	   Ú_adjust_bounds   s
   r%   c                 C   sX   | j jd dkrtdƒ‚| j j\}}| ||d¡ | ||| j ¡ ¡ t|| j ƒ |j	S )aB  
    Plot the given Delaunay triangulation in 2-D

    Parameters
    ----------
    tri : scipy.spatial.Delaunay instance
        Triangulation to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on

    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    Delaunay
    matplotlib.pyplot.triplot

    Notes
    -----
    Requires Matplotlib.

    Examples
    --------

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.spatial import Delaunay, delaunay_plot_2d

    The Delaunay triangulation of a set of random points:

    >>> rng = np.random.default_rng()
    >>> points = rng.random((30, 2))
    >>> tri = Delaunay(points)

    Plot it:

    >>> _ = delaunay_plot_2d(tri)
    >>> plt.show()

    r   é   z!Delaunay triangulation is not 2-DÚo)
r!   ÚshapeÚ
ValueErrorÚTÚplotÚtriplotÚ	simplicesÚcopyr%   r   )Útrir   ÚxÚyr   r   r	   r   $   s   -r   c                    sˆ   ddl m} ˆ jjd dkrtdƒ‚| ˆ jdd…df ˆ jdd…df d¡ ‡ fdd	„ˆ jD ƒ}| ||d
dd¡ t|ˆ jƒ |j	S )a&  
    Plot the given convex hull diagram in 2-D

    Parameters
    ----------
    hull : scipy.spatial.ConvexHull instance
        Convex hull to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on

    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    ConvexHull

    Notes
    -----
    Requires Matplotlib.


    Examples
    --------

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.spatial import ConvexHull, convex_hull_plot_2d

    The convex hull of a random set of points:

    >>> rng = np.random.default_rng()
    >>> points = rng.random((30, 2))
    >>> hull = ConvexHull(points)

    Plot it:

    >>> _ = convex_hull_plot_2d(hull)
    >>> plt.show()

    r   ©ÚLineCollectionr   r&   zConvex hull is not 2-DNr'   c                    s   g | ]}ˆ j | ‘qS r   )r!   )Ú.0Úsimplex©Úhullr   r	   Ú
<listcomp>   s    z'convex_hull_plot_2d.<locals>.<listcomp>ÚkÚsolid)ÚcolorsÚ	linestyle)
Úmatplotlib.collectionsr3   r!   r(   r)   r+   r-   Úadd_collectionr%   r   )r7   r   r3   Úline_segmentsr   r6   r	   r   ]   s   -*þr   c              	   K   s<  ddl m} | jjd dkrtdƒ‚| dd¡r5| dd	¡}|j| jd	d	…df | jd	d	…df d
|d | dd¡rP| | jd	d	…df | jd	d	…df d¡ | dd¡}| dd¡}| dd¡}| jjdd}t	j
| jdd}	g }
g }t| j| jƒD ]€\}}t	 |¡}t	 |dk¡r•|
 | j| ¡ q|||dk d }| j|d  | j|d   }|t	j |¡ }t	 |d  |d g¡}| j| jdd}t	 t	 || |¡¡| }| jrÛ| }t|	 ¡ |	 ¡  ƒ}| j| ||	 ¡  |  }| | j| |g¡ q|| ||
|||dd¡ | |||||dd¡ t|| jƒ |jS )ae  
    Plot the given Voronoi diagram in 2-D

    Parameters
    ----------
    vor : scipy.spatial.Voronoi instance
        Diagram to plot
    ax : matplotlib.axes.Axes instance, optional
        Axes to plot on
    show_points : bool, optional
        Add the Voronoi points to the plot.
    show_vertices : bool, optional
        Add the Voronoi vertices to the plot.
    line_colors : string, optional
        Specifies the line color for polygon boundaries
    line_width : float, optional
        Specifies the line width for polygon boundaries
    line_alpha : float, optional
        Specifies the line alpha for polygon boundaries
    point_size : float, optional
        Specifies the size of points

    Returns
    -------
    fig : matplotlib.figure.Figure instance
        Figure for the plot

    See Also
    --------
    Voronoi

    Notes
    -----
    Requires Matplotlib. For degenerate input, including collinearity and
    other violations of general position, it may be preferable to
    calculate the Voronoi diagram with Qhull options ``QJ`` for random
    joggling, or ``Qt`` to enforce triangulated output. Otherwise, some
    Voronoi regions may not be visible.

    Examples
    --------
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy.spatial import Voronoi, voronoi_plot_2d

    Create a set of points for the example:

    >>> rng = np.random.default_rng()
    >>> points = rng.random((10,2))

    Generate the Voronoi diagram for the points:

    >>> vor = Voronoi(points)

    Use `voronoi_plot_2d` to plot the diagram:

    >>> fig = voronoi_plot_2d(vor)

    Use `voronoi_plot_2d` to plot the diagram again, with some settings
    customized:

    >>> fig = voronoi_plot_2d(vor, show_vertices=False, line_colors='orange',
    ...                       line_width=2, line_alpha=0.6, point_size=2)
    >>> plt.show()

    r   r2   r   r&   zVoronoi diagram is not 2-DÚshow_pointsTÚ
point_sizeNÚ.)Ú
markersizeÚshow_verticesr'   Úline_colorsr9   Ú
line_widthg      ð?Ú
line_alphar   r:   )r;   ÚlwÚalphar<   Údashed)r=   r3   r!   r(   r)   Úgetr+   ÚverticesÚmeanr   r   ÚzipÚridge_pointsÚridge_verticesÚasarrayÚallÚappendÚlinalgÚnormÚarrayÚsignÚdotÚfurthest_siteÚabsr   r   r>   r%   r   )Úvorr   r   r3   rA   rE   rF   rG   ÚcenterÚ	ptp_boundÚfinite_segmentsÚinfinite_segmentsÚpointidxr5   ÚiÚtÚnÚmidpointÚ	directionÚaspect_factorÚ	far_pointr   r   r	   r   ™   sX   D.*
üür   )N)Únumpyr   Úscipy._lib.decoratorr   Ú
_decoratorÚ__all__r   r%   r   r   r   r   r   r   r	   Ú<module>   s    8;