
    OgT                     H    d dl mZmZ d dlmZ d dlmZ  G d d      ZddZy)	    )heappopheappush)TopologicalError)Pointc                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)CellaN  A `Cell`'s centroid property is a potential solution to finding the pole
    of inaccessibility for a given polygon. Rich comparison operators are used
    for sorting `Cell` objects in a priority queue based on the potential
    maximum distance of any theoretical point within a cell to a given
    polygon's exterior boundary.
    c                     || _         || _        || _        t        ||      | _        | j                  |      | _        | j                  |dz  z   | _        y )Ng;f?)xyhr   centroid_distdistancemax_distance)selfr
   r   r   polygons        a/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/shapely/algorithms/polylabel.py__init__zCell.__init__   sO    a 

7+ !MMA0B,BB    c                 4    | j                   |j                   kD  S Nr   r   others     r   __lt__zCell.__lt__         5#5#555r   c                 4    | j                   |j                   k\  S r   r   r   s     r   __le__zCell.__le__         E$6$666r   c                 4    | j                   |j                   k(  S r   r   r   s     r   __eq__zCell.__eq__"   r   r   c                 4    | j                   |j                   k7  S r   r   r   s     r   __ne__zCell.__ne__%   r   r   c                 4    | j                   |j                   k  S r   r   r   s     r   __gt__zCell.__gt__(   r   r   c                 4    | j                   |j                   k  S r   r   r   s     r   __ge__zCell.__ge__+   r   r   c                     |j                  | j                        }| j                  j                  |j                        }|j                  D ]'  }t        || j                  j                  |            }) |r|S | S )zSigned distance from Cell centroid to polygon outline. The returned
        value is negative if the point is outside of the polygon exterior
        boundary.
        )containsr   r   exterior	interiorsmin)r   r   insider   interiors        r   r   z
Cell._dist.   st    
 !!$--0==))'*:*:;)) 	GH8T]]%;%;H%EFH	GOyr   N)__name__
__module____qualname____doc__r   r   r   r!   r#   r%   r'   r    r   r   r   r      s0    
C677767r   r   c           	      (   | j                   st        d      | j                  \  }}}}||z
  }||z
  }t        ||      }|dz  }	g }
| j                  j
                  d   \  }}t        ||d|       }t        ||dz  z   ||dz  z   d|       }|j                  |j                  kD  r|}|}||k  r;|}||k  r)t        |
t        ||	z   ||	z   |	|              ||z  }||k  r)||z  }||k  r;|
rt        |
      }|j                  |j                  kD  r|}|j                  |j                  z
  |k  rF|j                  dz  }	t        |
t        |j                  |	z
  |j                  |	z
  |	|              t        |
t        |j                  |	z   |j                  |	z
  |	|              t        |
t        |j                  |	z
  |j                  |	z   |	|              t        |
t        |j                  |	z   |j                  |	z   |	|              |
r|j                  S )a  Finds pole of inaccessibility for a given polygon. Based on
    Vladimir Agafonkin's https://github.com/mapbox/polylabel

    Parameters
    ----------
    polygon : shapely.geometry.Polygon
    tolerance : int or float, optional
                `tolerance` represents the highest resolution in units of the
                input geometry that will be considered for a solution. (default
                value is 1.0).

    Returns
    -------
    shapely.geometry.Point
        A point representing the pole of inaccessibility for the given input
        polygon.

    Raises
    ------
    shapely.errors.TopologicalError
        If the input polygon is not a valid geometry.

    Example
    -------
    >>> from shapely import LineString
    >>> polygon = LineString([(0, 0), (50, 200), (100, 100), (20, 50),
    ... (-100, -20), (-150, -200)]).buffer(100)
    >>> polylabel(polygon, tolerance=10).wkt
    'POINT (59.35615556364569 121.83919629746435)'
    zInvalid polygong       @r      )is_validr   boundsr,   r   coordsr   r   r   r   r   r   r
   r   )r   	toleranceminxminymaxxmaxywidthheight	cell_sizer   
cell_queuer
   r   	best_cell	bbox_cellcells                   r   	polylabelrE   <   s   > 011$^^D$d4KED[FE6"ICAJ ""1%DAqQ1g&I TECK'
):AwGII...	 	A
d($hZa!eQUAw!?@NA $h 	
Y d( z" ==9---I y111Y> FFSLT$&&1*dffqj!WEFT$&&1*dffqj!WEFT$&&1*dffqj!WEFT$&&1*dffqj!WEF# & r   N)g      ?)	heapqr   r   shapely.errorsr   shapely.geometryr   r   rE   r3   r   r   <module>rI      s    # + "2 2jOr   