
    Mi,X                     
   S r SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SS	K
JrJr  SS
KJrJr  \" \5      r " S S\	5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z
entities.py
--------------

Basic geometric primitives which only store references to
vertex indices rather than vertices themselves.
    )deepcopy)	getLoggerN   )util)ABC   )
arc_centerdiscretize_arc)discretize_bezierdiscretize_bsplinec                       \ rS rSr SS jr\S 5       r\S 5       r\R                  S 5       rS\	4S jr
\S	 5       r\S
 5       r\S 5       r\S 5       rSS jrS rS rS rS rS rS rS rSrg)Entity   Nc                     [         R                  " U[         R                  S9U l        Ub  X l        Ub  X0l        Ub  U R                  R                  U5        0 U l        XPl	        X`l
        g Ndtype)np
asanyarrayint64pointsclosedlayermetadataupdate_cachecolorkwargs)selfr   r   r   r   r   r   s          o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/path/entities.py__init__Entity.__init__   s[     mmF"((; KJMM  * 
    c                 J    [        U S5      (       d  0 U l        U R                  $ )z\
Get any metadata about the entity.

Returns
---------
metadata : dict
  Bag of properties.
	_metadata)hasattrr%   r   s    r    r   Entity.metadata,   s"     t[))DN~~r#   c                 8    U R                   R                  S5      $ )z
Set the layer the entity resides on as a shortcut
to putting it in the entity metadata.

Returns
----------
layer : any
  Hashable layer identifier.
r   )r   getr'   s    r    r   Entity.layer;   s     }}  ))r#   c                      XR                   S'   g)za
Set the current layer of the entity.

Returns
----------
layer : any
  Hashable layer indicator
r   N)r   r   values     r    r   r+   H   s     "'gr#   returnc                 z    U R                   R                  U R                  R                  5       U R                  S.$ )z
Returns a dictionary with all of the information
about the entity.

Returns
-----------
as_dict : dict
  Has keys 'type', 'points', 'closed'
)typer   r   )	__class____name__r   tolistr   r'   s    r    to_dictEntity.to_dictT   s2     NN++kk((*kk
 	
r#   c                 ~    [        U R                  5      S:  =(       a    U R                  S   U R                  S   :H  $ )z
If the first point is the same as the end point
the entity is closed

Returns
-----------
closed : bool
  Is the entity closed or not?
r   r   lenr   r'   s    r    r   Entity.closedd   s2     4;;!#IA$++b/(IIr#   c                     [         R                  " U R                  U R                  45      R                  S5      SS R                  S5      $ )a  
Returns an (n,2) list of nodes, or vertices on the path.
Note that this generic class function assumes that all of the
reference points are on the path which is true for lines and
three point arcs.

If you were to define another class where that wasn't the case
(for example, the control points of a bezier curve),
you would need to implement an entity- specific version of this
function.

The purpose of having a list of nodes is so that they can then be
added as edges to a graph so we can use functions to check
connectivity, extract paths, etc.

The slicing on this function is essentially just tiling points
so the first and last vertices aren't repeated. Example:

self.points = [0,1,2]
returns:      [[0,1], [1,2]]
r8   r   r8   r   )r   column_stackr   reshaper'   s    r    nodesEntity.nodesq   s@    0 OOT[[$++67??CAbIQQRYZ	
r#   c                 $    U R                   SS/   $ )a0  
Returns the first and last points. Also note that if you
define a new entity class where the first and last vertices
in self.points aren't the endpoints of the curve you need to
implement this function for your class.

Returns
-------------
ends : (2,) int
  Indices of the two end points of the entity
r   r8   r   r'   s    r    
end_pointsEntity.end_points   s     {{Ar7##r#   c                     g)d
Is the current entity valid.

Returns
-----------
valid : bool
  Is the current entity well formed
T r'   s    r    is_validEntity.is_valid   s     r#   c                 .    US:  a  SU l         gSU l         g)z
Reverse the current entity in place.

Parameters
----------------
direction : int
  If positive will not touch direction
  If negative will reverse self.points
r   r8   r   N)
_direction)r   	directions     r    reverseEntity.reverse   s     q= DODOr#   c                 X    [        U S5      (       a  U R                  S:  a  USSS2   $ U$ )z
Reverse a curve if a flag is set.

Parameters
--------------
curve : (n, dimension) float
  Curve made up of line segments in space

Returns
------------
orient : (n, dimension) float
  Original curve, but possibly reversed
rL   r   Nr8   )r&   rL   )r   curves     r    _orientEntity._orient   s/     4&&4??Q+>2;r#   c                     [         R                  " XR                     R                  SS9XR                     R	                  SS9/5      nU$ )z
Return the AABB of the current entity.

Parameters
-----------
vertices : (n, dimension) float
  Vertices in space

Returns
-----------
bounds : (2, dimension) float
  Coordinates of AABB, in (min, max) form
r   axis)r   arrayr   minmax)r   verticesboundss      r    r[   Entity.bounds   sK     kk"&&A&.0E0I0Iq0I0QR
 r#   c                     [         R                  " U R                  U5      SS9S-  n[         R                  " US/UR                  S   -  5      S-  R                  5       nU$ )z
Return the total length of the entity.

Parameters
--------------
vertices : (n, dimension) float
  Vertices in space

Returns
---------
length : float
  Total length of entity
r   rU   r   r   g      ?)r   diffdiscretedotshapesum)r   rZ   r^   lengths       r    rc   Entity.length   sU     wwt}}X.Q71<&&sX^^A%6673>CCEr#   c                 $    U R                  5       /$ )z
Split the entity into multiple entities.

Returns
------------
explode : list of Entity
  Current entity split into multiple entities.
)copyr'   s    r    explodeEntity.explode   s     		}r#   c                 *   [        U 5      n[        U S5      (       aH  [        U R                  5      Ul        [        UR                  5      [        U R                  5      :w  d   e[        UR                  5      [        U R                  5      :w  d   eU$ )ze
Return a copy of the current entity.

Returns
------------
copied : Entity
  Copy of current entity
r%   )r   r&   r%   idr   )r   copieds     r    rf   Entity.copy   sq     $4%%'7Ff&&'2dnn+====&-- Bt{{O333r#   c                 4    [        U R                  5       5      $ )z
Return a hash that represents the current entity.

Returns
----------
hashed : int
    Hash of current class name, points, and closed
)hash_bytesr'   s    r    __hash__Entity.__hash__
  s     DKKM""r#   c                 N   U R                   S   U R                   S   :  a@  U R                  R                  R                  S5      U R                   R	                  5       -   $ U R                  R                  R                  S5      U R                   SSS2   R	                  5       -   $ )z
Get hashable bytes that define the current entity.

Returns
------------
data : bytes
  Hashable data defining the current entity
r   r8   utf-8N)r   r2   r3   encodetobytesr'   s    r    ro   Entity._bytes  s     ;;q>DKKO+>>**11':T[[=P=P=RRR>>**11':T[[2=N=V=V=XXXr#   )r   rL   r%   r   r   r   r   r   )NNNN)r8   )r3   
__module____qualname____firstlineno__r!   propertyr   r   setterdictr5   r   r@   rD   rI   rN   rR   r[   rc   rg   rf   rp   ro   __static_attributes__rH   r#   r    r   r      s    DH*   
* 
* \\	' 	'
 
  
J 
J 
 
4 $ $ 	 	 $&$	$	#Yr#   r   c                   .   \ rS rSrSr       SS jr\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\S	 5       r
\
R                  S
 5       r
SS jrS rS rS r\S 5       r\S 5       r\S 5       r\S 5       rS rSrg)Texti%  z#
Text to annotate a 2D or 3D path.
Nc
                    Xl         X@l        XPl        X0l        Ub  Xpl        U	b  U R
                  R                  U	5        Xl        Uc  SS/nO3[        U[        5      (       a  Xf/nO[        U5      S:w  a  [        S5      eX`l        [        US5      (       a  UR                  S5      U l        g[        U5      U l        g)a  
An entity for text labels.

Parameters
--------------
origin : int
  Index of a single vertex for text origin
text : str
  The text to label
height : float or None
  The height of text
vector : int or None
  An vertex index for which direction text
  is written along unitized: vector - origin
normal : int or None
  A vertex index for the plane normal:
  vector is along unitized: normal - origin
align : (2,) str or None
  Where to draw from for [horizontal, vertical]:
      'center', 'left', 'right'
Ncenterr   zalign must be (2,) strdecoders   )originvectornormalheightr   r   r   r   
isinstancestrr:   
ValueErroralignr&   r   text)
r   r   r   r   r   r   r   r   r   r   s
             r    r!   Text.__init__*  s    D JMM  * 
 =x(Es## NEZ1_566
 4""G,DID	DIr#   c                      U R                   S   $ )zU
The origin point of the text.

Returns
-----------
origin : int
  Index of vertices
r   rC   r'   s    r    r   Text.originq  s     {{1~r#   c                     [        U5      n[        U S5      (       a$  [        R                  " U R                  5      S:X  a,  [        R
                  " S[        R                  S9U-  U l        g XR                  S'   g )Nr   r      r   )intr&   r   ptpr   onesr   r-   s     r    r   r   }  sR    E
tX&&"&&*=*B''!2884u<DK"KKNr#   c                      U R                   S   $ )z
A point representing the text direction
along the vector: vertices[vector] - vertices[origin]

Returns
----------
vector : int
  Index of vertex
r   rC   r'   s    r    r   Text.vector       {{1~r#   c                 <    Uc  g [        U5      U R                  S'   g )Nr   r   r   r-   s     r    r   r         =UAr#   c                      U R                   S   $ )z
A point representing the plane normal along the
vector: vertices[normal] - vertices[origin]

Returns
------------
normal : int
  Index of vertex
r   rC   r'   s    r    r   Text.normal  r   r#   c                 <    Uc  g [        U5      U R                  S'   g )Nr   r   r-   s     r    r   r     r   r#   c           	      R   UR                   S   S:w  a  [        S5      eSSKJn  [        R
                  " U R                  U5      5      nUR                  " XR                     U R                  UU R                  S   U R                  S   SS.6  U(       a  UR                  5         gg)z
Plot the text using matplotlib.

Parameters
--------------
vertices : (n, 2) float
  Vertices in space
show : bool
  If True, call plt.show()
r   r   zonly for 2D points!r   N   )srotationhavasize)ra   r   matplotlib.pyplotpyplotr   degreesangler   r   r   show)r   rZ   r   pltr   s        r    plot	Text.plot  s     >>!!233' 

4::h/0 	kk"iizz!}zz!}	
 HHJ r#   c                     UR                   S   S:w  a  [        S5      eXR                     XR                     -
  n[        R
                  " USSS2   6 nU$ )z
If Text is 2D, get the rotation angle in radians.

Parameters
-----------
vertices : (n, 2) float
  Vertices in space referenced by self.points

Returns
---------
angle : float
  Rotation angle in radians
r   r   zangle only valid for 2D points!Nr8   )ra   r   r   r   r   arctan2)r   rZ   rM   r   s       r    r   
Text.angle  sV     >>!!>?? [[)H[[,AA	

IddO,r#   c                     g)Ng        rH   )r   rZ   s     r    rc   Text.length  s    r#   c                 .    [         R                  " / 5      $ Nr   rW   )r   argsr   s      r    r_   Text.discrete  s    xx|r#   c                     g)NFrH   r'   s    r    r   Text.closed  s    r#   c                     g)NTrH   r'   s    r    rI   Text.is_valid  s    r#   c                 .    [         R                  " / 5      $ r   r   r'   s    r    r@   
Text.nodes      xx|r#   c                 .    [         R                  " / 5      $ r   r   r'   s    r    rD   Text.end_points  r   r#   c                     SR                  SU R                  R                  5       U R                  R	                  S5      /5      nU$ )Nr#   s   Textrs   )joinr   ru   r   rt   )r   datas     r    ro   Text._bytes  s8    xx$++"5"5"79I9I'9RSTr#   )	r   r   r   r   r   r   r   r   r   )NNNNNNN)F)r3   rw   rx   ry   __doc__r!   rz   r   r{   r   r   r   r   rc   r_   r   rI   r@   rD   ro   r}   rH   r#   r    r   r   %  s    E"N 	 	 ]]# # 
 
 ]]$ $
 
 
 ]]$ $
@2        r#   r   c                       \ rS rSrSrSS jr\S 5       r\R                  S\	4S j5       r\S 5       r
S rS	 rS
\4S jrSrg)Linei  z
A line or poly-line entity
c                 <    U R                  XR                     5      $ )a  
Discretize into a world- space path.

Parameters
------------
vertices: (n, dimension) float
  Points in space
scale : float
  Size of overall scene for numerical comparisons

Returns
-------------
discrete: (m, dimension) float
  Path in space composed of line segments
)rR   r   r   rZ   scales      r    r_   Line.discrete  s      ||H[[122r#   c                 ~    [        U R                  5      S:  =(       a    U R                  S   U R                  S   :H  $ Nr   r   r8   r9   r'   s    r    r   Line.closed  s0    4;;!#IA$++b/(IIr#   r.   c                    U R                   S   U R                   S   :H  nU(       a=  U(       d6  [        R                  " U R                   U R                   S   /45      U l         g U(       d  U(       a  [        R	                  S5        g g g )Nr   r8   zignoring `Line.closed = False`)r   r   concatenatelogdebug)r   r.   currents      r    r   r     s`    ++a.DKKO3 ..$++A7G)HIDK7II67 #r#   c                 l    [         R                  " U R                  U R                  S   -
  S:g  5      nU$ )rG   r   )r   anyr   )r   valids     r    rI   Line.is_valid%  s-     dkk!n4:;r#   c                     U R                   n[        R                  " U R                  U R                  45      R	                  5       SS R                  S5      nU Vs/ s H  n[        X1S9PM     nnU$ s  snf )z
If the current Line entity consists of multiple line
break it up into n Line entities.

Returns
----------
exploded: (n,) Line entities
r   r8   r=   )r   )r   r   r>   r   ravelr?   r   )r   r   r   iexplodeds        r    rg   Line.explode2  sk     

OOT[[$++67==?"EMMgV 	 399&QD(&9 :s   A4c                     U R                   S   U R                   S   :  a  SU R                   R                  5       -   $ SU R                   S S S2   R                  5       -   $ )Nr   r8   s   Line)r   ru   r'   s    r    ro   Line._bytesC  sS    ;;q>DKKO+T[[00222T[[2.66888r#   r/   c                 d    U R                   R                  U R                  R                  5       S.$ )a~  
Returns a dictionary with all of the information
about the Line. `closed` is not additional information
for a Line like it is for Arc where the value determines
if it is a partial or complete circle. Rather it is a check
which indicates the first and last points are identical,
and thus should not be included in the export

Returns
-----------
as_dict
  Has keys 'type', 'points'
)r1   r   )r2   r3   r   r4   r'   s    r    r5   Line.to_dictJ  s+     NN++kk((*
 	
r#   rC   N      ?)r3   rw   rx   ry   r   r_   rz   r   r{   boolrI   rg   ro   r|   r5   r}   rH   r#   r    r   r     sk    3$ J J ]]8D 8 8 
 
"9
 
r#   r   c                   z    \ rS rSr\S 5       r\R                  S 5       r\S 5       rS rS r	SS jr
S rS	 rS
rg)Arci^  c                     [        U SS5      $ )z
A boolean flag for whether the arc is closed (a circle) or not.

Returns
----------
closed : bool
  If set True, Arc will be a closed circle
_closedF)getattrr'   s    r    r   
Arc.closed_  s     tY..r#   c                 $    [        U5      U l        g)z
Set the Arc to be closed or not, without
changing the control points

Parameters
------------
value : bool
  Should this Arc be a closed circle or not
N)r   r   r-   s     r    r   r   k  s     E{r#   c                 Z    [        [        R                  " U R                  5      5      S:H  $ )zy
Is the current Arc entity valid.

Returns
-----------
valid : bool
  Does the current Arc have exactly 3 control points
r   )r:   r   uniquer   r'   s    r    rI   Arc.is_validx  s!     299T[[)*a//r#   c                     [        U R                  S   U R                  S   :  5      S-  S-
  nS[        U R                  5      -   U R                  S S U2   R	                  5       -   $ )Nr   r8   r   r   s   Arc)r   r   bytesr   ru   )r   orders     r    ro   
Arc._bytes  sZ    DKKNT[[_459A=dkk**T[[5-A-I-I-KKKr#   c                     U R                   (       a1  U R                  USSS9n[        R                  UR                  -  S-  $ U R                  USSS9nUR
                  UR                  -  S-  $ )z
Return the arc length of the 3-point arc.

Parameter
----------
vertices : (n, d) float
  Vertices for overall drawing.

Returns
-----------
length : float
  Length of arc.
Freturn_normalreturn_angle   Tr   )r   r   r   piradiusspan)r   rZ   fits      r    rc   
Arc.length  se     ;; ++he%+PC553::%))kk(%dkKxx#**$q((r#   c                 b    U R                  [        XR                     U R                  US95      $ )a  
Discretize the arc entity into line sections.

Parameters
------------
vertices : (n, dimension) float
    Points in space
scale : float
    Size of overall scene for numerical comparisons

Returns
-------------
discrete : (m, dimension) float
  Path in space made up of line segments
)closer   )rR   r
   r   r   r   s      r    r_   Arc.discrete  s,    " ||8KK05Q
 	
r#   c                 2    [        XR                     40 UD6$ )z
Return the center information about the arc entity.

Parameters
-------------
vertices : (n, dimension) float
  Vertices in space

Returns
-------------
info : dict
  With keys: 'radius', 'center'
)r	   r   )r   rZ   r   s      r    r   
Arc.center  s     (;;/:6::r#   c                    [         R                  " US5      (       aw  U R                  (       af  U R                  USSS9n[        R
                  " UR                  UR                  -
  UR                  UR                  -   /[        R                  S9nU$ U R                  U5      n[        R
                  " UR                  SS9UR                  SS9/[        R                  S9nU$ )z
Return the AABB of the arc entity.

Parameters
-----------
vertices: (n, dimension) float
  Vertices in space

Returns
-----------
bounds : (2, dimension) float
  Coordinates of AABB in (min, max) form
r=   Fr   r   r   rU   )r   is_shaper   r   r   rW   r   float64r_   rX   rY   )r   rZ   infor[   r_   s        r    r[   
Arc.bounds  s     ==7++ ;;xu5;QDXXt{{*DKK$++,EFbjjF 	 }}X.HXX1%x|||';<BJJF r#   )r   Nr   )r3   rw   rx   ry   rz   r   r{   rI   ro   rc   r_   r   r[   r}   rH   r#   r    r   r   ^  sZ    	/ 	/ ]]
# 
# 	0 	0L
)0
*; r#   r   c                   (    \ rS rSrSr\S 5       rSrg)Curvei  z0
The parent class for all wild curves in space.
c                     U R                   [        U R                   5      S-     nU R                   S   U/XR                   S   //$ r   )r   r:   )r   mids     r    r@   Curve.nodes  sC     kk#dkk*a/0Q%[[_'=>>r#   rH   N)r3   rw   rx   ry   r   rz   r@   r}   rH   r#   r    r  r    s     ? ?r#   r  c                   "    \ rS rSrSrSS jrSrg)Bezieri  z 
An open or closed Bezier curve
Nc                 L    U R                  [        XR                     X2S95      $ )a#  
Discretize the Bezier curve.

Parameters
-------------
vertices : (n, 2) or (n, 3) float
  Points in space
scale : float
  Scale of overall drawings (for precision)
count : int
  Number of segments to return

Returns
-------------
discrete : (m, 2) or (m, 3) float
  Curve as line segments
)countr   )rR   r   r   )r   rZ   r   r  s       r    r_   Bezier.discrete  s&    $ ||h{{35N
 	
r#   rH   )r   N)r3   rw   rx   ry   r   r_   r}   rH   r#   r    r
  r
    s    
r#   r
  c                   @    \ rS rSrSrS
S jrSS jrS rS\4S jr	S	r
g)BSplinei  z
An open or closed B- Spline.
Nc                    [         R                  " U[         R                  S9U l        [         R                  " U[         R                  S9U l        Ub  X0l        Ub  U R                  R                  U5        0 U l	        X`l
        XPl        g r   )r   r   r   r   r  knotsr   r   r   r   r   r   )r   r   r  r   r   r   r   s          r    r!   BSpline.__init__  sb    mmF"((;]]5

;
JMM  *
r#   c                 f    [        XR                     U R                  X#S9nU R                  U5      $ )a%  
Discretize the B-Spline curve.

Parameters
-------------
vertices : (n, 2) or (n, 3) float
  Points in space
scale : float
  Scale of overall drawings (for precision)
count : int
  Number of segments to return

Returns
-------------
discrete : (m, 2) or (m, 3) float
  Curve as line segments
)controlr  r  r   )r   r   r  rR   )r   rZ   r  r   r_   s        r    r_   BSpline.discrete  s1    $ &[[)5
 ||H%%r#   c                 :   U R                   S   U R                   S   :  a8  SU R                  R                  5       -   U R                   R                  5       -   $ SU R                  S S S2   R                  5       -   U R                   S S S2   R                  5       -   $ )Nr   r8   s   BSpline)r   r  ru   r'   s    r    ro   BSpline._bytes5  s    ;;q>DKKO+

 2 2 44t{{7J7J7LLL

4R4 0 8 8 ::T[[2=N=V=V=XXXr#   r/   c                     U R                   R                  U R                  R                  5       U R                  R                  5       U R
                  S.$ )zD
Returns a dictionary with all of the information
about the entity.
)r1   r   r  r   )r2   r3   r   r4   r  r   r'   s    r    r5   BSpline.to_dict<  sB     NN++kk((*ZZ&&(kk	
 	
r#   )r   r   r  r   r   r   )NNN)Nr   )r3   rw   rx   ry   r   r!   r_   ro   r|   r5   r}   rH   r#   r    r  r    s#    	&.Y

 

r#   r  )r   rf   r   loggingr   numpyr    r   r   arcr	   r
   rQ   r   r   r3   r   r   r   r   r   r  r
  r  rH   r#   r    <module>r     s         + 8LYS LY^W6 Wt\
6 \
~E& EP	?F 	?
U 
88
e 8
r#   