
    Mi                        S r S/rSSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
Jr  SSKrSSKJrJrJr   SSKrSrS
\\\\      \R,                  4   S\R,                  4S jrS
\\\\      \R,                  4   S\4S jrS
\\\\      \R,                  4   S\\\\      \R,                  4   4S jr SS
\\\\      \R,                  4   S\S\4   4S jjrg! \ a    S	r Nf = f)z&
Tools for working with alpha shapes.

alphashape    N)unary_union
polygonize)
MultiPointMultiLineString)Delaunay)UnionTupleListTFpointsreturnc                 
   [         R                  " U 5      n U R                  u  p[         R                  " S[         R                  " X R
                  5      -  [         R                  " US45      /[         R                  " SU45      [         R                  " S5      //5      n[         R                  " [         R                  " X -  SS9[         R                  " S5      45      n[         R                  R                  X45      SS $ )a;  
Calculate the circumcenter of a set of points in barycentric coordinates.

Args:
  points: An `N`x`K` array of points which define an (`N`-1) simplex in K
    dimensional space.  `N` and `K` must satisfy 1 <= `N` <= `K` and
    `K` >= 1.

Returns:
  The circumcenter of a set of points in barycentric coordinates.
      )r   r   )axisN)npasarrayshapebmatdotToneszeroshstacksumlinalgsolve)r   num_rowsnum_columnsAbs        o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/alphashape/alphashape.pycircumcenterr$      s     ZZF"LLH
!bffVXX..''8Q-(*''1h-("((6*:;= 	>A 			266&/277A<! 	"A99??1 "%%    c                     [         R                  " U 5      n [         R                  R                  U SSS24   [         R                  " [        U 5      U 5      -
  5      $ )a  
Calculte the circumradius of a given set of points.

Args:
  points: An `N`x`K` array of points which define an (`N`-1) simplex in K
    dimensional space.  `N` and `K` must satisfy 1 <= `N` <= `K` and
    `K` >= 1.

Returns:
  The circumradius of a given set of points.
r   N)r   r   r   normr   r$   )r   s    r#   circumradiusr(   +   sB     ZZF99>>&A,V0Df)MMNNr%   c              #     #    [         R                  " U 5      n[        U5      nUR                   H  nX   n U[	        U5      4v   M     g! [         R
                  R                   a    [        R                  " S5         MS  f = f7f)z
Returns an iterator of simplices and their circumradii of the given set of
points.

Args:
  points: An `N`x`M` array of points.

Yields:
  A simplex, and its circumradius as a tuple.
zCSingular matrix. Likely caused by all points lying in an N-1 space.N)	r   r   r   	simplicesr(   r   LinAlgErrorloggingwarn)r   coordstrisimplexsimplex_pointss        r#   alphasimplicesr2   ;   st      ZZF
6
C==	3<777 ! yy$$ 	3LL 2 3	3s(   5BAB4B BBBalphac                 t   [         (       a1  [        U [        R                  5      (       a  U R                  nU S   n OSn[        U 5      S:  d  Ub  [        U5      (       d  US::  a  [        U [        5      (       d  [        [        U 5      5      n U R                  nU(       aP  [        R                  " [        R                  " U5      5      R                  SS0S9R                  S5      nX$l        U$ U$ Uc   SSKJn  U" U 5      n[         (       a]  [        U [        R                  R                  5      (       a4  [         R"                  " U  Vs/ s H  ofR$                  S   PM     sn5      nO[         R"                  " U 5      n['        5       n['        5       n	[)        U5       H  u  p[        U5      (       a	  U" X5      nOUnUSU-  :  d  M+  [*        R,                  " XR.                  S	   S
9 H  n[1        [*        R,                  " U[        U5      S
9 Vs/ s H  oU;  PM	     sn5      (       a$  UR3                  U5        U	R3                  U5        Mf  U	['        [*        R,                  " U[        U5      S
95      -  n	M     M     UR.                  S	   S:  a  U	$ UR.                  S	   S:X  a:  SSKnUR7                  U[        U	5      S9nUR8                  R;                  U5        U$ [=        U	 Vs/ s H  o[         R"                  " U5         PM     sn5      n[        [?        U5      5      n[A        U5      nU(       aP  [        R                  " [        R                  " U5      5      R                  SS0S9R                  S5      nX$l        U$ U$ ! [         a
    SSKJn   GNf = fs  snf s  snf s  snf )aC  
Compute the alpha shape (concave hull) of a set of points.  If the number
of points in the input is three or less, the convex hull is returned to the
user.  For two points, the convex hull collapses to a `LineString`; for one
point, a `Point`.

Args:

  points (list or ``shapely.geometry.MultiPoint`` or           ``geopandas.GeoDataFrame``): an iterable container of points
  alpha (float): alpha value

Returns:

  ``shapely.geometry.Polygon`` or ``shapely.geometry.LineString`` or
  ``shapely.geometry.Point`` or ``geopandas.GeoDataFrame``:           the resulting geometry
geometryN   r   )columns)optimizealphar   g      ?r   )r   )verticesfaces)!USE_GP
isinstance	geopandasGeoDataFramecrslencallabler   listconvex_hull	GeoSeriesrenameset_geometryr8   ImportError	geoseriesr   arrayr.   setr2   	itertoolscombinationsr   alladdtrimeshTrimeshrepairfix_normalsr   r   r   )r   r3   rA   resultgdfr8   pointr.   edgesperimeter_edgespoint_indicesr(   resolved_alphaedgeerQ   m	triangless                     r#   r   r   S   s=   * v*VY%;%;<<jj
# 6{Q5,X6 6z&*--V-F##(()<)<V)DELLJ M ))5j)A GJM }	53 f% v*VY%8%8%B%BCC?u<<??@&! EE eO'5f'=#E??"=?N"N #..!..!\\"%57	0F0FD	1+ , 1+1 1+ , - -IIdO#''-#s9+A+AD	,+ (, ,O7 (>$ ||B!	b	Q	&_8MN""6* 	OLOD/OLMAZ]#I#F $$Y%8%8%@AHH
O I %%1\*%= 	
}  	544	5 @8," Ms$   9N N+N03"N5N('N()N)__doc____all__rM   r,   shapely.opsr   r   shapely.geometryr   r   scipy.spatialr   numpyr   typingr	   r
   r   r?   r=   rI   floatndarrayr$   r(   r2   r    r%   r#   <module>rj      s(   .   / 8 "  % %F
&tE%L12::=> &2:: &,OtE%L12::=> O5 O 35eEl!3RZZ!?@ 3d5< "**,-32 ,0luT%,/;< lD%K(lE  Fs   C C$#C$