
    Mi,              	       N   S r SSKJrJr  SSKrSSKJrJr  SSK	J
r
  SSKJr  SSKJrJr   SS	KJr   SSKJr  \ " S S5      5       r\" SSSS9r\S4S\\\4   S\\\S4   S\SS4S jjrS rS rSS jrg! \ a  rSS
KJr  \" \5      r SrCN_SrCff = f! \ a    \r Njf = f)aP  
convex.py

Deal with creating and checking convex objects in 2, 3 and N dimensions.

Convex is defined as:
1) "Convex, meaning "curving out" or "extending outward" (compare to concave)
2) having an outline or surface curved like the exterior of a circle or sphere.
3) (of a polygon) having only interior angles measuring less than 180
    )	dataclassfieldsN   )	trianglesutil)tol)
Geometry3D)NDArrayUnion)
ConvexHull)ExceptionWrapper)
QhullErrorc                   (   \ rS rSr% SrSr\\S'    Sr\\S'    Sr	\\S'    Sr
\\S'    Sr\\S'    Sr\\S	'    Sr\\S
'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    Sr\\S'    S\4S jrSrg)QhullOptions"   aA  
A helper class for constructing correct Qhull option strings.
More details available at: http://www.qhull.org/html/qh-quick.htm#options

Currently only includes the boolean flag options, which is most of them.

Parameters
-----------
Qa
  Allow input with fewer or more points than coordinates
Qc
  Keep coplanar points with nearest facet
Qi
  Keep interior points with nearest facet.
QJ
  Joggled input to avoid precision problems
Qt
  Triangulated output.
Qu
  Compute upper hull for furthest-site Delaunay triangulation
Qw
  Allow warnings about Qhull options
Qbb
  Scale last coordinate to [0,m] for Delaunay
Qs
  Search all points for the initial simplex
Qv
  Test vertex neighbors for convexity
Qx
  Exact pre-merges (allows coplanar facets)
Qz
  Add a point-at-infinity for Delaunay triangulations
QbB
  Scale input to fit the unit cube
QR0
  Random rotation (n=seed, n=0 time, n=-1 time/no rotate)
Qg
  only build good facets (needs 'QGn', 'QVn', or 'Pdk')
Pp
  Do not print statistics about precision problems and remove
  some of the warnings including the narrow hull warning.
FQaQcQiQJQtQuQwQbbQsQvQxQzQbBQR0QgPpreturnc                 L   ^  SR                  U 4S j[        T 5       5       5      $ )z
Construct the `qhull_options` string used by `scipy.spatial`
objects and functions.

Returns
----------
qhull_options
  Can be passed to `scipy.spatial.[ConvexHull,Delaunay,Voronoi]`
 c              3   v   >#    U  H.  n[        TUR                  5      (       d  M   UR                  v   M0     g 7f)N)getattrname).0fselfs     h/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/convex.py	<genexpr>'QhullOptions.__str__.<locals>.<genexpr>   s$     N1aff8Ms   99)joinr   )r*   s   `r+   __str__QhullOptions.__str__   s     xxNtNNN     N)__name__
__module____qualname____firstlineno____doc__r   bool__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   strr/   __static_attributes__r2   r1   r+   r   r   "   s    )V BAB2B4B5B BGB. C7B5B/B6B?C,CC BABB&
O 
Or1   r   T)r   r!   r   objqhull_optionsrepairr"   ztrimesh.Trimeshc           	         SSK Jn  Uc  SnOM[        U[        5      (       a  [	        U5      nO,[        U[        5      (       a  UnO[        [        U5      5      e[        U S5      (       a*  U R                  R                  [        R                  5      nOJ[        R                  " U [        R                  S9n[        R                  " US5      (       d  [!        S5      e [#        XTS9n[        R*                  " UR                  5      n[        R,                  " [/        UR0                  5      [        R2                  S9n[        R4                  " [/        U5      5      X'   XR6                     R9                  5       n	UR0                  U   R9                  5       n
U(       d  U" XS
SS9$ [:        R<                  " X   5      n[        R>                  " US
S9u  pX   n	X   n[:        R@                  " US9nX   RC                  SS9n[        RD                  " XSS9nUU-
  n[        RF                  " UU5      S:  n[        RH                  " U	U   5      U	U'   UU==   S-  ss'   UUUUS.nU" U
U	UUS
SS9nURK                  SS9  Uc  URL                  (       d
  [O        USS9$ U$ ! [$         a,    [        R&                  R)                  S	S
S9  [#        USS9n GNf = f)a  
Get a new Trimesh object representing the convex hull of the
current mesh attempting to return a watertight mesh with correct
normals.

Arguments
--------
obj
  Mesh or `(n, 3)` points.
qhull_options
  Options to pass to qhull.

Returns
--------
convex
  Mesh of convex hull.
r   )TrimeshNverticesdtype)   z'Object must be Trimesh or (n,3) points!r=   z1Failed to compute convex hull: retrying with `QJ`T)exc_infor   F)rA   facesprocessvalidate)check_valid)crossesaxisr   )weightsrN   g        g      )triangles_crosstriangles_center
area_facescentroid)rA   rH   face_normalsinitial_cacherI   rJ   )	multibody)(baser@   
isinstancer   r:   	TypeErrortypehasattrrA   viewnpndarrayasarrayfloat64r   is_shape
ValueErrorr   r   logdebugsortzeroslenpointsint64arange	simplicescopyr   crossunitizeareameanaveragediagonal_dotfliplrfix_normalsis_winding_consistentconvex_hull)r<   r=   r>   r@   	qhull_strrh   hullvidmaskrH   rA   rL   normalsvalidtriangles_arearQ   rS   test_vector	backwardsrU   convexs                        r+   rv   rv      s   .  		M<	0	0&		M3	'	'!	]+,,sJ""2::. Crzz2}}VW--FGG6&: ''$--
 C88C$BHH5D		#c(#DI %%'E{{3$$&HteTT ooho.G \\'t<NG LEnG ^^G4N+++3 zz*KH"X-K!!';7#=I yyy!12E)I$ #,$	M #F '
 V%A%A666Ma  6JUYZ&56s    	J" "2KKc                     U R                   U R                  SS2S4      nU R                  U R                  SS2S4      nU R                  SS2S4   nU R                  U   U-
  n[
        R                  " XA5      nU$ )a  
Test if a mesh is convex by projecting the vertices of
a triangle onto the normal of its adjacent face.

Parameters
----------
mesh : Trimesh
  Input geometry

Returns
----------
projection : (len(mesh.face_adjacency),) float
  Distance of projection of adjacent vertex onto plane
Nr   r   )rT   face_adjacencyrA   face_adjacency_edgesface_adjacency_unsharedr   rr   )meshr{   origins	vid_othervector_otherdotss         r+   adjacency_projectionsr   #  s       3 3AqD 9:GmmD55ad;<G ,,QT2I==+g5L \3DKr1   c                 r   U R                   (       a  U R                  S:w  a  gU R                  [        R                  :  nXR
                     R                  SS9nUR                  5       (       d  g[        R                  U R                  -  n[        U R                  U   R                  5       U:  5      nU$ )z
Check if a mesh is convex.

Parameters
-----------
mesh : Trimesh
  Input geometry

Returns
-----------
convex : bool
  Was passed mesh convex or not
r   FrM   )is_watertight
body_countrR   r   zeror   allanyplanarscaler8   face_adjacency_projectionsmax)r   nonzeroadj_ok	thresholdr   s        r+   	is_convexr   A  s      A!5 oo(G(()--1-5F ::<< 

TZZ'I
 $11&9==?)KLFMr1   c                 &   [        U S5      (       a  U R                  R                  $ [        R                  " U [        R
                  S9n[        UR                  5      S:w  a  [        S5      e[        X!S9nUR                  UR                     nU$ )a  
Try to extract a convex set of points from multiple input formats.

Details on qhull options:
  http://www.qhull.org/html/qh-quick.htm#options

Parameters
---------
obj: Trimesh object
     (n,d) points
     (m,) Trimesh objects

Returns
--------
points: (o,d) convex set of points
rv   rB      zpoints must be (n, dimension)!rF   )r[   rv   rA   r]   
asanyarrayr`   rg   shaperb   r   rh   )r<   r=   initialrx   rh   s        r+   hull_pointsr   k  ss    " sM""'''mmCrzz2G
7==Q9::g;D[['FMr1   )zQbB Pp) r7   dataclassesr   r   numpyr]    r   r   	constantsr   parentr	   typedr
   r   scipy.spatialr   ImportErrorE
exceptionsr   r   BaseExceptionr   QHULL_DEFAULTr:   r8   rv   r   r   r   r2   r1   r+   <module>r      s   	 *     !%((
 yO yO yOx $48
 5B~	z7"	#~sD01~ ~ 	~B<'Ti
  %,!!$J%  Js(   A8 B 8B>BBB$#B$