
    MiXi                        S r SSKrSSKJr  SSKJrJr  SSKJ	r	J
r
JrJrJrJrJr   SSKJr       S/S	\\   S
\\   S\\
   S\\
   S\\
   4
S jjrS0S\\
   S\\
   4S jjr S1S\	S\\
   S\S\4S jjrS2S\\
   S\\R4                     4S jjr S3S\	S\S\4S jjr   S4S\	S\
S\S\4S jjrS2S\	S\\
   4S  jjr   S5S\S\S\\
   4S! jjrS6S" jr S2S# jr!S0S$ jr"\RF                  4S%\	S&\	S\\R4                     4S' jjr$S7S( jr%S\	S)\S\\\RL                     \4   4S* jr'S+ r(S,\RR                  SSS4S- jr*S. r+g! \ a#  rSSKJr  \R*                  " \5      r SrCGN:SrCff = f)8zD
grouping.py
-------------

Functions for grouping values and rows.
    N   )util)logtol)	ArrayLikeIntegerNDArrayNumberOptionalSequenceTuple)cKDTree)
exceptions	merge_tex
merge_normdigits_vertexdigits_norm	digits_uvc                 |   [        U R                  5      S:X  a  gUc  SnUc  SnUc  SnUc  SnUc$  [        R                  " [        R
                  5      n[        U S5      (       aT  [        U R                  5      S:  a;  [        R                  " [        U R                  5      [        S9nSX`R                  '   O,[        R                  " [        U R                  5      [        S9nU R                  S	U-  -  /nU(       d  U R                  R                  (       a  U R                  R                  S
:X  ax  U R                  R                  ba  [        U R                  R                  5      [        U R                  5      :X  a+  UR!                  U R                  R                  S	U-  -  5        U R"                  S   nU(       dE  [        R$                  " U5      U R                  R$                  :X  a  UR!                  US	U-  -  5        [        R&                  " U5      R)                  5       R+                  [        R,                  5      n[/        Xv   SS9u  p[        R                  " [        U R                  5      [        R,                  S9nXU'   [        R0                  " U5      S   U	   nU R3                  XS9  g)ae  
Removes duplicate vertices, grouped by position and
optionally texture coordinate and normal.

Parameters
-------------
mesh : Trimesh object
  Mesh to merge vertices on
merge_tex : bool
  If True textured meshes with UV coordinates will
  have vertices merged regardless of UV coordinates
merge_norm : bool
  If True, meshes with vertex normals will have
  vertices merged ignoring different normals
digits_vertex : None or int
  Number of digits to consider for vertex position
digits_norm : int
  Number of digits to consider for unit normals
digits_uv : int
  Number of digits to consider for UV coordinates
r   NF      facesdtypeT
   texturevertex_normals)
keep_order)maskinverse)lenverticesr   decimal_to_digitsr   mergehasattrr   npzerosboolonesvisualdefinedkinduvappend_cacheshapecolumn_stackroundastypeint64unique_rowsnonzeroupdate_vertices)meshr   r   r   r   r   
referencedstackednormalsuir    r   s                j/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/grouping.pymerge_verticesr?      s   < 4==Q	
	..syy9 tW#djj/A"5XXc$--0=
!%
:: WWS/t<
 }}M 123G
 KKKK	)KKNN&3t}}#55 	t{{~~Y78 kk*+G"((7+t}}/B/BBw"k/23 oog&,,.55bhh?G w*t<DA hhs4==):GJ::j!!$Q'Dd4    min_lenmax_lenc                    [         R                  " U 5      nUR                  5       nX4   n U R                  R                  S:X  aN  [         R
                  " [         R                  " [         R                  " U 5      5      [        R                  5      nOU SS U SS :g  n[         R                  " S[         R                  " U5      S   S-   5      n[         R                  " [        U5      [        S9n[         R                  " [         R                  " U[        U 5      /45      5      nUc  Ub  Ub  XxU:  -  nUb  XxU:*  -  n[!        Xg   X   5       V	V
s/ s H  u  pXIX-    PM     nn	n
U$ s  sn
n	f )a  
Return the indices of values that are identical

Parameters
----------
values : (n,) int
  Values to group
min_len : int
  The shortest group allowed
  All groups will have len >= min_length
max_len : int
  The longest group allowed
  All groups will have len <= max_length

Returns
----------
groups : sequence
  Contains indices to form groups
  IE [0,1,0,1] returns [[0,2], [1,3]]
fr   Nr   r   )r&   
asanyarrayargsortr   r,   greaterabsdiffr   zeror.   r6   r)   r!   r(   concatenatezip)valuesrA   rB   originalordernondupedupe_idxdupe_okdupe_lenr=   jgroupss               r>   grouprW   q   sC   * }}V$H E_F ||C **RVVBGGFO4chh?
 *s+yyBJJw/2Q67H ggc(m40G wwr~~x#f+&?@AH g17**G7**G-01BHDU-VW-VTQe -VFWM Xs   E+datadigits	allow_intreturnc                    [        U 5      S:X  a#  [        R                  " / [        R                  S9$ [	        XS9n[        UR
                  5      S:X  a  U$ U(       Ga  [        UR
                  5      S:X  Ga  UR
                  S   S::  a  [        [        R                  " SUR
                  S   -  5      5      nUR                  5       UR                  5       peSUS-
  -  S-
  nXg:  a  XW* :  a  [        R                  " [        U5      [        R                  S9nUR                  US-   -   R                  [        R                  5      n	[        U	5       H  u  p[        R                  " XX-  -  US9  M!     U$ [        R                  " [        R                   UR                  R"                  UR
                  S   -  45      n[        R$                  " U5      R'                  U5      R)                  S	5      nS
UR*                  S'   U$ )ai  
We turn our array into integers based on the precision
given by digits and then put them in a hashable format.

Parameters
---------
data : (n, m) array
  Input data
digits : int or None
  How many digits to add to hash if data is floating point
  If None, tol.merge will be used

Returns
---------
hashable : (n,)
  May return as a `np.void` or a `np.uint64`
r   r   rY   r   r   r   @   )outrE   F	WRITEABLE)r!   r&   arrayuint64float_to_intr0   intfloorminmaxr'   Tr3   	enumeratebitwise_xorr   voiditemsizeascontiguousarrayviewreshapeflags)rX   rY   rZ   as_int	precisiond_mind_max	thresholdhashablebitbangoffsetcolumnr   results                 r>   hashable_rowsr{      s   * 4yA~xx")),, $.F 6<<A S&!+Q10Dfll1o!567	 zz|VZZ\u 9q=)Q.	 !3xxF299=H xx9q=199"))DG #,G"4xF4F)GXV #5 O HHbggv||44v||AFGHE!!&)..u5==bAF %FLLMr@   c                    [         R                  " U 5      n U R                  [         R                  :X  a  U $ U R                  R                  S;   d  U R
                  S:X  a  U R                  [         R                  5      $ U R                  R                  S:w  a  U R                  [         R                  5      n Uc%  [        R                  " [        R                  5      nO=[        U[        [         R                  45      (       d  [        S[!        U5       S35      e[         R"                  " U SU-  -  S-
  5      R                  [         R                  5      $ )z
Given a numpy array of float/bool/int, return as integers.

Parameters
-------------
data :  (n, d) float, int, or bool
  Input data
digits : float or int
  Precision for float conversion

Returns
-------------
as_int : (n, d) int
  Data as integers
iubr   rD   z%Digits must be `None` or `int`, not ``r   gư>)r&   rF   r   r4   r,   sizer3   float64r   r#   r   r$   
isinstancerd   integer	TypeErrortyper2   )rX   rY   s     r>   rc   rc      s    " ==D zzRXX	E	!TYY!^{{288$$	C	{{2::&~''		2bjj 122?V~QOPP
 88TBJ&$./66rxx@@r@   Freturn_indexreturn_inversec                    [         R                  " U SSS9u  p4nUR                  5       nU(       d  U(       d  X6   $ X6   /nU(       a  UR                  XF   5        U(       a"  UR                  UR                  5       U   5        U$ )a$  
Returns the same as np.unique, but ordered as per the
first occurrence of the unique value in data.

Examples
---------
In [1]: a = [0, 3, 3, 4, 1, 3, 0, 3, 2, 1]

In [2]: np.unique(a)
Out[2]: array([0, 1, 2, 3, 4])

In [3]: trimesh.grouping.unique_ordered(a)
Out[3]: array([0, 3, 4, 1, 2])
Tr   r   )r&   uniquerG   r.   )rX   r   r   r   indexr    rP   rz   s           r>   unique_orderedr     sp    ,  YYt$tTF7 MMOE} m_Fel#emmog./Mr@   rN   	minlengthreturn_countsc                 H   [         R                  " U 5      n [        U R                  5      S:w  d  U R                  R
                  S:w  a  [        S5      e [         R                  " XS9nUR                  [        5      n[         R                  " U5      S   nU4nU(       a!  [         R                  " U5      S-
  U    nXx4-  nU(       a	  XF   n	Xy4-  n[        U5      S:X  a  US   $ U$ ! [         a.    [        R                  " S5        [         R                  " XUS9s $ f = f)a	  
For arrays of integers find unique values using bin counting.
Roughly 10x faster for correct input than np.unique

Parameters
--------------
values : (n,) int
  Values to find unique members of
minlength : int
  Maximum value that will occur in values (values.max())
return_inverse : bool
  If True, return an inverse such that unique[inverse] == values
return_counts : bool
  If True, also return the number of times each
  unique item appears in values

Returns
------------
unique : (m,) int
  Unique values in original array
inverse : (n,) int, optional
  An array such that unique[inverse] == values
  Only returned if return_inverse is True
counts : (m,) int, optional
  An array holding the counts of each unique item in values
  Only returned if return_counts is True
r   r=   zinput must be 1D integers!)r   zcasting failed, falling back!)r   r   r   )r&   rF   r!   r0   r   r,   
ValueErrorbincountr   r   warningr   r3   r(   wherecumsum)
rN   r   r   r   counts
unique_binr   retr    unique_countss
             r>   unique_bincountr   A  s   B ]]6"F
6<<A!2!2c!9566	
V9 t$J XXj!!$F)C99Z(1,f5z
3x1}1vJ9  
34yy
 	
	
s   C) )5D! D!c                    Uc  [         R                  nOSU* -  n[        R                  " U 5      n [        R                  " [        U 5      [        S9nSUS'   [        R                  " U SS U SS -
  5      U:  USS& X   $ )a  
Merge duplicate sequential values. This differs from unique_ordered
in that values can occur in multiple places in the sequence, but
only consecutive repeats are removed

Parameters
-----------
data: (n,) float or int

Returns
--------
merged: (m,) float or int

Examples
---------
In [1]: a
Out[1]:
array([-1, -1, -1,  0,  0,  1,  1,  2,  0,
        3,  3,  4,  4,  5,  5,  6,  6,  7,
        7,  8,  8,  9,  9,  9])

In [2]: trimesh.grouping.merge_runs(a)
Out[2]: array([-1,  0,  1,  2,  0,  3,  4,  5,  6,  7,  8,  9])
Nr   r   Tr   r   rE   )r   r$   r&   rF   r'   r!   r(   rI   )rX   rY   epsilonr   s       r>   
merge_runsr     sz    2 ~))&/==D88CIT*DDGvvd12hcr*+g5DH:r@   c                    [         R                  " U 5      n [        X5      n[         R                  " USSS9u  pVnU(       d  U(       d  X   $ X   /nU(       a  UR	                  U5        U(       a  UR	                  U5        [        U5      $ )z
Identical to the numpy.unique command, except evaluates floating point
numbers, using a specified number of digits.

If digits isn't specified, the library default TOL_MERGE will be used.
Tr   )r&   rF   rc   r   r.   tuple)	rX   r   r   rY   rq   _junkr   r    rz   s	            r>   unique_floatr     sr     ==D$'FYYvDQUVE7>|l^Ffg=r@   c                 p    [        XS9nU(       a  [        USSS9SS $ [        R                  " USSS9SS $ )a  
Returns indices of unique rows. It will return the
first occurrence of a row that is duplicated:
[[1,2], [3,4], [1,2]] will return [0,1]

Parameters
---------
data : (n, m) array
  Floating point data
digits : int or None
  How many digits to consider

Returns
--------
unique :  (j,) int
  Index in data which is a unique row
inverse : (n,) int
  Array to reconstruct original
  Example: data[unique][inverse] == data
r]   Tr   r   N)r{   r   r&   r   )rX   rY   r   rowss       r>   r5   r5     sE    , -D ddKABOO 99TTB12FFr@   c                    Uc  [         R                  " U 5      n[         R                  " U 5      n [         R                  " U [        SS9nU H1  n[         R
                  " X5      nUR                  SS9S:H  nXE   X%'   M3     U$ )a,  
For a 2D array of integers find the position of a
value in each row which only occurs once.

If there are more than one value per row which
occur once, the last one is returned.

Parameters
----------
data :   (n, d) int
  Data to check values
unique : (m,) int
  List of unique values contained in data.
  Generated from np.unique if not passed

Returns
---------
result : (n, d) bool
  With one or zero True values per row.


Examples
-------------------------------------
In [0]: r = np.array([[-1,  1,  1],
                      [-1,  1, -1],
                      [-1,  1,  1],
                      [-1,  1, -1],
                      [-1,  1, -1]], dtype=np.int8)

In [1]: unique_value_in_row(r)
Out[1]:
       array([[ True, False, False],
              [False,  True, False],
              [ True, False, False],
              [False,  True, False],
              [False,  True, False]], dtype=bool)

In [2]: unique_value_in_row(r).sum(axis=1)
Out[2]: array([1, 1, 1, 1, 1])

In [3]: r[unique_value_in_row(r)]
Out[3]: array([-1,  1, -1,  1,  1], dtype=int8)
F)r   subokr   axis)r&   r   rF   
zeros_liker(   equalsum)rX   r   rz   valuetesttest_oks         r>   unique_value_in_rowr     st    X ~4==D]]4t59Fxx$((("a'-  Mr@   c                    [        XS9nUc  [        U5      $ UR                  5       nX4   nUSS USS :g  n[        R                  " S[        R
                  " U5      S   S-   5      n[        R                  " [        R                  " U[        U5      /45      5      U:H  n[        R                  " Xg   R                  S5      U5      [        R                  " U5      -   nXH   n	US:X  a  U	R                  S5      $ U	$ )a{  
Returns index groups of duplicate rows, for example:
[[1,2], [3,4], [1,2]] will return [[0,2], [1]]


Note that using require_count allows numpy advanced
indexing to be used in place of looping and
checking hashes and is ~10x faster.


Parameters
----------
data : (n, m) array
  Data to group
require_count : None or int
  Only return groups of a specified length, eg:
  require_count =  2
  [[1,2], [3,4], [1,2]] will return [[0,2]]
digits : None or int
If data is floating point how many decimals
to consider, or calculated from tol.merge

Returns
----------
groups : sequence (*,) int
  Indices from in indicating identical rows.
r]   Nr   rE   r   )rE   r   )r{   rW   rG   r&   r.   r6   rJ   rL   r!   tilero   arange)
rX   require_countrY   rv   rP   duperR   start_okrV   
groups_idxs
             r>   
group_rowsr   #  s    < T1H X EH AB<8CR=(D yyBJJt,Q/!34H wwr~~x#h-&ABC}THWWX'//8-H299L F J!!"%%r@   abc                    [         R                  " U [         R                  S9n [         R                  " U[         R                  S9nU R                  SU R                  4/U R
                  S   -  5      R                  5       nUR                  SUR                  4/UR
                  S   -  5      R                  5       nU" X45      R                  U R                  5      R                  SU R
                  S   5      $ )ac  
Find the rows in two arrays which occur in both rows.

Parameters
---------
a: (n, d) int
    Array with row vectors
b: (m, d) int
    Array with row vectors
operation : function
    Numpy boolean set operation function:
      -np.intersect1d
      -np.setdiff1d

Returns
--------
shared : (p, d) int64
   Array containing requested rows in both a and b
r    r   rE   )r&   rF   r4   rn   r   r0   ravelro   )r   r   	operationavbvs        r>   boolean_rowsr   _  s    , 	arxx(A
arxx(A	
"agg!''!*,	-	3	3	5B	
"agg!''!*,	-	3	3	5BR!!!''*222qwwqzBBr@   c                    [         R                  " U [         R                  S9n [        U5      nU(       a  [        R
                  " U 5      n [        R                  " U 5      n[        X15      u  pE[        R                  " U5      nXe4$ )a  
Group vectors based on an angle tolerance, with the option to
include negative vectors.

Parameters
-----------
vectors : (n,3) float
    Direction vector
angle : float
    Group vectors closer than this angle in radians
include_negative : bool
    If True consider the same:
    [0,0,1] and [0,0,-1]

Returns
------------
new_vectors : (m,3) float
    Direction vector
groups : (m,) sequence of int
    Indices of source vectors
r   )	r&   rF   r   floatr   vector_hemispherevector_to_sphericalgroup_distancespherical_to_vector)vectorsangleinclude_negative	sphericalanglesrV   new_vectorss          r>   group_vectorsr   }  si    . mmG2::6G%LE((1((1I#I5NF**62Kr@   distancec                    [         R                  " U [         R                  S9n [         R                  " [	        U 5      [
        S9n[        U 5      n/ n/ n[        U 5       H  u  pgX&   (       a  M  [         R                  " UR                  Xq5      [         R                  S9nXU   )    nSX('   UR                  [         R                  " X   SS95        UR                  U5        M     [         R                  " U5      U4$ )a  
Find non-overlapping groups of points where no two points in a
group are farther than 2*distance apart.

Parameters
---------
values : (n, d) float
    Points of dimension d
distance : float
    Max distance between points in a cluster

Returns
----------
unique : (m, d) float
    Median value of each group
groups : (m) sequence of int
    Indexes of points that make up a group

r   Tr   r   )r&   rF   r   r'   r!   r(   r   ri   ra   query_ball_pointr4   r.   median)	rN   r   consumedtreer   rV   r   r   rW   s	            r>   r   r     s    , ]]64FxxF40H6?D FF!&)?..u?rxxP&'biiA67e * 88FV##r@   c                 j    SSK Jn  [        U 5      nUR                  USS9nUR	                  U5      nU$ )a  
Find clusters of points which have neighbours closer than radius

Parameters
---------
points : (n, d) float
    Points of dimension d
radius : float
    Max distance between points in a cluster

Returns
----------
groups : (m,) sequence of int
    Indices of points in a cluster

r   )graphndarray)routput_type)r   r   r   query_pairsconnected_components)pointsradiusr   r   pairsrV   s         r>   clustersr     s<    " 6?D v9=E''.FMr@   r   c           	          [        XS9n [        R                  " [        U 5      5      nSUR                  S'   USS U SS U SS :g     n[        R
                  " [        U5      S-   [        S9n[        U 5      US'   XxSS& USS USS -
  n	[        R                  " X:  X:*  5      n
U(       a  [        R                  " XUSS    5      n
[        U
5       VVs/ s H  u  pU(       d  M  XhU   XS-       PM     nnnU(       Gau  U S	   U S   :w  a  U$ U(       a  [        U S	   5      (       d  U$ [        U5      S:X  a  [        US	   5      [        U 5      :X  a  U$ [        U5      S	:  =(       a    US	   S	   S	:H  n[        U5      S	:  =(       a    US   S   [        U 5      S-
  :H  nU(       a9  U(       a2  [        R                  " US   US	   5      US	'   UR                  5         U$ U	S	   U	S   -   nUU:  d  UU:  a  U$ [        R                  " [        R                  " US
   US   5      [        R                  " US	   US   5      5      nU(       a  UUS	'   U$ U(       a  UUS'   U$ UR                  U5        U$ s  snnf )a  
Find the indices in an array of contiguous blocks
of equal values.

Parameters
------------
data : (n,) array
  Data to find blocks on
min_len : int
  The minimum length group to be returned
max_len : int
  The maximum length group to be retuurned
wrap : bool
  Combine blocks on both ends of 1D array
digits : None or int
  If dealing with floats how many digits to consider
only_nonzero : bool
  Only return blocks of non- zero values

Returns
---------
blocks : (m) sequence of (*,) int
  Indices referencing data
r]   Fr`   r   NrE   r   r   r   )rc   r&   r   r!   rp   r'   rd   logical_andri   r(   r.   pop)rX   rA   rB   wraprY   only_nonzeror   r6   inflinfl_leninfl_okr=   okblocksfirstlastcombined	new_blocks                     r>   r   r     su   2 ,D YYs4y!F %FLLQRjabT#2Y./G88CL1$C0D4yDH2J ABx$s)#H nnX0(2EFG ..tCRy/: :C79KR9Kr+f!WtE{+9KFR7d2hM T!WM v;!F1I#d) ;M Fa5F1IaLA$56{QD6":b>c$i!m#D T		&*fQi8F1IJJL. M)  {Xb\1H'!X%7				$r(DH-ryya$q'/JI %q	 M &r
 M i(Mg Ss   I:(I:c                     [         R                  " X45      nX   n X   n[         R                  " [        U 5      S5      nSUS'   U SS U SS :g  USS& X   $ )aG  
Given a list of groups find the minimum element of data
within each group

Parameters
-----------
groups : (n,) sequence of (q,) int
    Indexes of each group corresponding to each element in data
data : (m,)
    The data that groups indexes reference

Returns
-----------
minimums : (n,)
    Minimum value of data per group

r(   Tr   r   NrE   )r&   lexsortr'   r!   )rV   rX   rP   r   s       r>   	group_minr   N  sc    & JJ~&E]F;DHHS[&)EE!Hqr
fSbk)E!"I;r@   )NNNNN)NN)NT)N)FF)r   FF)FFN)NF)g-C6?F),__doc__numpyr&   r   r   	constantsr   r   typedr   r   r	   r
   r   r   r   scipy.spatialr   BaseExceptionEr   ExceptionWrapperr(   r?   rW   r{   r4   rc   r   r   r   r   r5   r   r   intersect1dr   r   r   r   r   infr   r    r@   r>   <module>r      sp      Q Q Q-% !%!%'+%)#'V5~V5 V5 G$	V5
 '"V5  V5r68G, 6hw>O 6t JN?
?%g.?BF??D&Ax0 &AGBHH<M &AT IN)
)#')AE)\  	DDD D 	DN#Y #(9 #P   $	  W	8GD4n9z +-..CCCRXXC< F($($!'($
72::()($V: BFFtRW cL}  - ))!,G-s   E E-
E((E-