U
    9%e                      @   sb   d dl Zd dlmZ dddg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 kr8| }| }| |fd|i|S t|ddd  }|rb| |fd|i|S z"|d | |fd|i|W S || X d S )Nr   axZisholdc                   S   s   dS )NT r   r   r   W/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/scipy/spatial/_plotutils.py<lambda>       z_held_figure.<locals>.<lambda>T)Zmatplotlib.pyplotZpyplotfigureZgcagetattrZhold)funcobjr   kwZpltZfigZwas_heldr   r   r   _held_figure   s    
r   c                 C   s\   d|j dd }|jdd| }|jdd| }| |d |d  | |d |d  d S )Ng?r   Zaxis   )ptpminmaxZset_xlimZset_ylim)r   pointsmarginZxy_minZ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plotZtriplot	simplicescopyr   r   )Ztrir   xyr   r   r   r   $   s    -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.collectionsr$   r   r   r   r   r   add_collectionr   r   )r(   r   r$   Zline_segmentsr   r'   r   r   ]   s    -*c              	   K   s&  ddl m} | jjd dkr$td|ddrj|dd	}|j| jd	d	df | jd	d	df d
|d |ddr|| jd	d	df | jd	d	df d |dd}|dd}|dd}| jjdd}| 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| }| j| ||	   }|| j| |g q|||
|||dd ||||||dd t|| j |jS )a;  
    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.

    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   r#   r   r   zVoronoi diagram is not 2-DZshow_pointsT
point_sizeN.)Z
markersizeZshow_verticesr   line_colorsr*   
line_widthg      ?
line_alphar   r+   )r,   Zlwalphar-   Zdashed)r.   r$   r   r   r   getr   ZverticesZmeanr   zipZridge_pointsZridge_verticesnpZasarrayallappendZlinalgZnormarraysigndotZfurthest_siter   r/   r   r   )Zvorr   r   r$   r0   r2   r3   r4   centerZ	ptp_boundZfinite_segmentsZinfinite_segmentsZpointidxr&   itnZmidpoint	directionZ	far_pointr   r   r   r      sV    @.*
)N)N)N)N)numpyr8   Zscipy._lib.decoratorr   Z
_decorator__all__r   r   r   r   r   r   r   r   r   <module>   s   
8;