
    Mi                         S r SSKJr  SSKJr  SSKJr  \R                  " S5      rS\	S\	S\
4S	 jrS\4S
 jrS\	S\
4S jrSS\S\S\	4S jjrSS\S\	SS4S jjrg)z
units.py
--------------
Deal with physical unit systems (i.e. inches, mm)

Very basic conversions, and no requirement for
sympy.physics.units or pint.
   )	resources)log)Geometryzunits_to_inches.jsoncurrentdesiredreturnc                     [        U R                  5       R                  5       5      [        UR                  5       R                  5       5      -  $ )a6  
Calculate the conversion from one set of units to another.

Parameters
---------
current : str
    Unit system values are in now (eg 'millimeters')
desired : str
    Unit system we'd like values in (eg 'inches')

Returns
---------
conversion : float
    Number to multiply by to put values into desired units
)to_inchstriplower)r   r   s     g/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/units.pyunit_conversionr      s7    " 7==?((*+ggmmo6K6K6M.NNN    c                  <    [        [        R                  5       5      $ )z~
Return a set containing all currently valid units.

Returns
--------
keys
  All units with conversions i.e. {'in', 'm', ...}
)set_lookupkeys r   r   r   r   &   s     w||~r   unitc                 4   [         R                  U R                  5       R                  5       S5      nUb  U$  U R	                  S5      u  p#[         UR                  5          [        U5      -  $ ! [         a  nSU  SU S3n SnAOSnAff = f[        U5      e)aH  
Calculate the conversion to an arbitrary common unit.

Parameters
------------
unit
  Either a key in `units_to_inches.json` or in the simple
  `{float} * {str}` form, i.e. "1.2 * meters". We don't
  support arbitrary `eval` of any math string

Returns
----------
conversion
  Factor to multiply by to get to an `inch` system.
N*z:arbitrary units must be in the form "1.21 * meters", not "z" ())r   getr   r   splitfloatBaseException
ValueError)r   lookupvaluekeyEmessages         r   r
   r
   2   s    " [[++-t4F
ZZ_
syy{#eEl22 
 IcRSQTTUV 	
 W
s   5A/ /
B9	BBobjguessc                 r   U R                   R                  SS5      /nU R                  b%  UR                  U R                  R                  5        U H  nUc  M  UR                  5       R                  SS5      R                  SS5      nS H  nUR                  US5      nM     SR                  S U 5       5      nUR                  5       R                  5        H  nU[        ;   d  M  Us  s  $    M     U(       d  [        S	5      e[        R                  " S
5        [        U R                  5      S:  a  gg)a  
Try to extract hints from metadata and if that fails
guess based on the object scale.


Parameters
------------
obj
  A geometry object.
guess
  If metadata doesn't have units make a "best guess"

Returns
------------
units
 A guess of what the units might be
nameNunits r   z_-. c              3   4   #    U  H  oS ;  d  M
  Uv   M     g7f)
0123456789Nr   ).0cs     r   	<genexpr>&units_from_metadata.<locals>.<genexpr>s   s     @$Q<*?qq$s   		z"No units and not allowed to guess!zno units: guessing from scaleg      Y@millimetersinches)metadatar   sourceappend	file_namer   replacejoinr   r   r   r   r   debugr   scale)r#   r$   hintshintdelimhs         r   units_from_metadatar>   T   s    & \\fd+,E
zzSZZ))* <zz|##GS199&#FE<<s+D ww@$@@##%AG| &  =>>
 II-.SYY%r   Nc                     U R                   c  [        XS9U l         [        R                  " SU R                   U5        [	        U R                   U5      nU R                  U5        Xl         g)aK  
Given an object with scale and units try to scale
to different units via the object's `apply_scale`.

Parameters
---------
obj :  object
    With apply_scale method (i.e. Trimesh, Path2D, etc)
desired : str
    Units desired (eg 'inches')
guess:   bool
    Whether we are allowed to guess the units
    if they are not specified.
N)r$   zconverting units from %s to %s)r'   r>   r   r8   r   apply_scale)r#   r   r$   
conversions       r   _convert_unitsrB      sT     yy (9	II.		7C G4J OOJIr   )T)F)__doc__r)   r   	constantsr   parentr   get_jsonr   strr   r   r   r   r
   boolr>   rB   r   r   r   <module>rI      s       

3
4OS O3 O5 O(	c 	# % D0X 0d 0c 0f 3  r   