
    Mif                     <   S /r SSKrSSKrSSKrSSKJr  SSKrSSKJrJ	r	J
r
  SSKrSSKr SSKrSrS\\
\	\      \R$                  4   S\4S	 jrS
S\R(                  R*                  S4S\\
\	\      \R$                  4   S\S\S\S\4
S jjrg! \ a    Sr Ngf = f)optimizealpha    N)
MultiPoint)UnionTupleListTFpointsalphac                 `    SSK J n  U" X5      n[        U[        R                  R
                  R                  5      (       aS  [        U [        5      (       d  [        [        U 5      5      n [        U  Vs/ s H  oCR                  U5      PM     sn5      $ [        U[        R                  R                  5      (       aT  [        UR                  5      S:  =(       a5    [        [        R                   R#                  U[        U 5      5      S:  5      $ g! [         a
    SSK J n   GNf = fs  snf )a  
Evaluates an alpha parameter.

This helper function creates an alpha shape with the given points and alpha
parameter.  It then checks that the produced shape is a Polygon and that it
intersects all the input points.

Args:
    points: data points
    alpha: alpha value

Returns:
    bool: True if the resulting alpha shape is a single polygon that
        intersects all the input data points.
r   )
alphashape   F)r   ImportError
isinstanceshapelygeometrypolygonPolygonr   listall
intersectstrimeshbaseTrimeshlenfaces	proximitysigned_distance)r   r	   r   r   points        r/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/alphashape/optimizealpha.py
_testalphar      s     +) 'G'7++33;;<<&*--V-F6B6%&&u-6BCC	GW\\11	2	27==!A% K#--gtF|DI+K 	K   +**+ Cs   D 5D+D('D(i'          max_iterationsloweruppersilentc                    [         (       a$  [        U [        R                  5      (       a  U S   n US:  d   S5       eU[        R
                  R                  ::  d#   S[        R
                  R                   S35       e[        X5      (       a  U(       d  [        R                  " S5        gSnX2-
  [        R                  " [        5      R                  S-  :  aw  X2-   S	-  n[        X5      (       a  UnOUnUS
-  nXQ:  a"  U(       d  [        R                  " S5        Sn U$ X2-
  [        R                  " [        5      R                  S-  :  a  Mw  U$ )a  
Solve for the alpha parameter.

Attempt to determine the alpha parameter that best wraps the given set of
points in one polygon without dropping any points.

Note:  If the solver fails to find a solution, a value of zero will be
returned, which when used with the alphashape function will safely return a
convex hull around the points.

Args:

    points: an iterable container of points
    max_iterations (int): maximum number of iterations while finding the
        solution
    lower: lower limit for optimization
    upper: upper limit for optimization
    silent: silence warnings

Returns:

    float: The optimized alpha parameter

r   r   z#The lower bounds must be at least 0z/The upper bounds must be less than or equal to z on your systemz?the max float value does not bound the alpha parameter solutionr       g      ?r   zGmaximum allowed iterations reached while optimizing the alpha parameter)USE_GPr   	geopandasGeoDataFramesys
float_infomaxr   loggingerrornpfinfofloatepswarning)r   r!   r"   r#   r$   counter
test_alphas          r   r   r   1   s:   8 v*VY%;%;<<
# A:<<<:CNN&&& 
9#..:L:L9M N 	& &  MM / 0 G=BHHUO//!3
3mr)
 f))EE 	1# !A BEL% =BHHUO//!3
3$ L    )__all__r*   r-   r   shapely.geometryr   r   typingr   r   r   rtreenumpyr/   r(   r'   r   r1   ndarrayr   r+   r,   intboolr    r6   r   <module>r@      s   
 
   '  % %  F
uT%,/;< U B ).b!$!3!3E@%U5\ 2BJJ >? @"%@6;@@=A@I  Fs   B BB