a
    ßÁd;(  ã                   @   s¼   d dl Z d dlZddlmZ ddlmZmZ g d¢Zedd„ ƒZ	edd	„ ƒZ
ed
d„ ƒZdd„ Zedd„ ƒZeddd„ƒZedƒeddd„ƒƒZedƒedd„ ƒƒZedƒedd„ ƒƒZdS )é    Né   )Úlib)Úmultithreading_enabledÚrequires_geos)	ÚareaÚdistanceÚboundsÚtotal_boundsÚlengthÚhausdorff_distanceÚfrechet_distanceÚminimum_clearanceÚminimum_bounding_radiusc                 K   s   t j| fi |¤ŽS )al  Computes the area of a (multi)polygon.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import MultiPolygon, Polygon
    >>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
    >>> area(polygon)
    100.0
    >>> area(MultiPolygon([polygon, Polygon([(10, 10), (10, 20), (20, 20), (20, 10), (10, 10)])]))
    200.0
    >>> area(Polygon())
    0.0
    >>> area(None)
    nan
    )r   r   ©ÚgeometryÚkwargs© r   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/shapely/measurement.pyr      s    r   c                 K   s   t j| |fi |¤ŽS )aš  Computes the Cartesian distance between two geometries.

    Parameters
    ----------
    a, b : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import LineString, Point, Polygon
    >>> point = Point(0, 0)
    >>> distance(Point(10, 0), point)
    10.0
    >>> distance(LineString([(1, 1), (1, -1)]), point)
    1.0
    >>> distance(Polygon([(3, 0), (5, 0), (5, 5), (3, 5), (3, 0)]), point)
    3.0
    >>> distance(Point(), point)
    nan
    >>> distance(None, point)
    nan
    )r   r   )ÚaÚbr   r   r   r   r   0   s    r   c                 K   s:   t j| t jd�}t j|jd dd�}tj|fd|i|¤ŽS )a¿  Computes the bounds (extent) of a geometry.

    For each geometry these 4 numbers are returned: min x, min y, max x, max y.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import LineString, Point, Polygon
    >>> bounds(Point(2, 3)).tolist()
    [2.0, 3.0, 2.0, 3.0]
    >>> bounds(LineString([(0, 0), (0, 2), (3, 2)])).tolist()
    [0.0, 0.0, 3.0, 2.0]
    >>> bounds(Polygon()).tolist()
    [nan, nan, nan, nan]
    >>> bounds(None).tolist()
    [nan, nan, nan, nan]
    )Zdtype)é   Úfloat64Úout)ÚnpZasarrayZobject_ÚemptyÚshaper   r   )r   r   Zgeometry_arrr   r   r   r   r   M   s    r   c              
   K   s�   t | fi |¤Ž}|jdkr|S t ¡ �V t dt¡ t t |d ¡t |d ¡t 	|d ¡t 	|d ¡g¡W  d  ƒ S 1 s‚0    Y  dS )aÃ  Computes the total bounds (extent) of the geometry.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Returns
    -------
    numpy ndarray of [xmin, ymin, xmax, ymax]

    Examples
    --------
    >>> from shapely import LineString, Point, Polygon
    >>> total_bounds(Point(2, 3)).tolist()
    [2.0, 3.0, 2.0, 3.0]
    >>> total_bounds([Point(2, 3), Point(4, 5)]).tolist()
    [2.0, 3.0, 4.0, 5.0]
    >>> total_bounds([
    ...     LineString([(0, 1), (0, 2), (3, 2)]),
    ...     LineString([(4, 4), (4, 6), (6, 7)])
    ... ]).tolist()
    [0.0, 1.0, 6.0, 7.0]
    >>> total_bounds(Polygon()).tolist()
    [nan, nan, nan, nan]
    >>> total_bounds([Polygon(), Point(2, 3)]).tolist()
    [2.0, 3.0, 2.0, 3.0]
    >>> total_bounds(None).tolist()
    [nan, nan, nan, nan]
    r   Úignore).r   ).r   ).é   ).é   N)
r   ÚndimÚwarningsÚcatch_warningsÚsimplefilterÚRuntimeWarningr   ÚarrayZnanminZnanmax)r   r   r   r   r   r   r	   m   s    !

üÿr	   c                 K   s   t j| fi |¤ŽS )aÛ  Computes the length of a (multi)linestring or polygon perimeter.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import LineString, MultiLineString, Polygon
    >>> length(LineString([(0, 0), (0, 2), (3, 2)]))
    5.0
    >>> length(MultiLineString([
    ...     LineString([(0, 0), (1, 0)]),
    ...     LineString([(1, 0), (2, 0)])
    ... ]))
    2.0
    >>> length(Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]))
    40.0
    >>> length(LineString())
    0.0
    >>> length(None)
    nan
    )r   r
   r   r   r   r   r
   Ÿ   s    r
   c                 K   s6   |du rt j| |fi |¤ŽS t j| ||fi |¤ŽS dS )a¶  Compute the discrete Hausdorff distance between two geometries.

    The Hausdorff distance is a measure of similarity: it is the greatest
    distance between any point in A and the closest point in B. The discrete
    distance is an approximation of this metric: only vertices are considered.
    The parameter 'densify' makes this approximation less coarse by splitting
    the line segments between vertices before computing the distance.

    Parameters
    ----------
    a, b : Geometry or array_like
    densify : float or array_like, optional
        The value of densify is required to be between 0 and 1.
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import LineString
    >>> line1 = LineString([(130, 0), (0, 0), (0, 150)])
    >>> line2 = LineString([(10, 10), (10, 150), (130, 10)])
    >>> hausdorff_distance(line1, line2)  # doctest: +ELLIPSIS
    14.14...
    >>> hausdorff_distance(line1, line2, densify=0.5)
    70.0
    >>> hausdorff_distance(line1, LineString())
    nan
    >>> hausdorff_distance(line1, None)
    nan
    N)r   r   Zhausdorff_distance_densify©r   r   Zdensifyr   r   r   r   r   ¾   s    !r   z3.7.0c                 K   s2   |du rt j| |fi |¤ŽS t j| ||fi |¤ŽS )u~  Compute the discrete FrÃ©chet distance between two geometries.

    The FrÃ©chet distance is a measure of similarity: it is the greatest
    distance between any point in A and the closest point in B. The discrete
    distance is an approximation of this metric: only vertices are considered.
    The parameter 'densify' makes this approximation less coarse by splitting
    the line segments between vertices before computing the distance.

    FrÃ©chet distance sweep continuously along their respective curves
    and the direction of curves is significant. This makes it a better measure
    of similarity than Hausdorff distance for curve or surface matching.

    Parameters
    ----------
    a, b : Geometry or array_like
    densify : float or array_like, optional
        The value of densify is required to be between 0 and 1.
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import LineString
    >>> line1 = LineString([(0, 0), (100, 0)])
    >>> line2 = LineString([(0, 0), (50, 50), (100, 0)])
    >>> frechet_distance(line1, line2)  # doctest: +ELLIPSIS
    70.71...
    >>> frechet_distance(line1, line2, densify=0.5)
    50.0
    >>> frechet_distance(line1, LineString())
    nan
    >>> frechet_distance(line1, None)
    nan
    N)r   r   Zfrechet_distance_densifyr%   r   r   r   r   å   s    &r   z3.6.0c                 K   s   t j| fi |¤ŽS )a>  Computes the Minimum Clearance distance.

    A geometry's "minimum clearance" is the smallest distance by which
    a vertex of the geometry could be moved to produce an invalid geometry.

    If no minimum clearance exists for a geometry (for example, a single
    point, or an empty geometry), infinity is returned.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.

    Examples
    --------
    >>> from shapely import Polygon
    >>> polygon = Polygon([(0, 0), (0, 10), (5, 6), (10, 10), (10, 0), (5, 4), (0, 0)])
    >>> minimum_clearance(polygon)
    2.0
    >>> minimum_clearance(Polygon())
    inf
    >>> minimum_clearance(None)
    nan
    )r   r   r   r   r   r   r     s    r   z3.8.0c                 K   s   t j| fi |¤ŽS )aC  Computes the radius of the minimum bounding circle that encloses an input geometry.

    Parameters
    ----------
    geometry : Geometry or array_like
    **kwargs
        For other keyword-only arguments, see the
        `NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.


    Examples
    --------
    >>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
    >>> minimum_bounding_radius(Polygon([(0, 5), (5, 10), (10, 5), (5, 0), (0, 5)]))
    5.0
    >>> minimum_bounding_radius(LineString([(1, 1), (1, 10)]))
    4.5
    >>> minimum_bounding_radius(MultiPoint([(2, 2), (4, 2)]))
    1.0
    >>> minimum_bounding_radius(Point(0, 1))
    0.0
    >>> minimum_bounding_radius(GeometryCollection())
    0.0

    See also
    --------
    minimum_bounding_circle
    )r   r   r   r   r   r   r   0  s    r   )N)N)r    Únumpyr   Ú r   Z
decoratorsr   r   Ú__all__r   r   r   r	   r
   r   r   r   r   r   r   r   r   Ú<module>   s0   


2
&)