
    Ti                         d Z ddlmZ ddlmZ ddlmZ  ej        d          Zde	de	de
fd	Zdefd
Zde	de
fdZddedede	fdZddede	ddfdZdS )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                     t          |                                                                           t          |                                                                          z  S )af  
    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/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/units.pyunit_conversionr      sG    " 7==??((**++ggmmoo6K6K6M6M.N.NNN    c                  N    t          t                                                    S )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                 v   t                               |                                                                 d          }||S 	 |                     d          \  }}t           |                                         t          |          z  S # t          $ r}d|  d| d}Y d}~nd}~ww xY wt          |          )ax  
    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44F
ZZ__
ssyy{{#eEll22 
 
 
 WVVRSVVV 	
 W

s   AB 
B)	B$$B)Tobjguessc                 t   | j                             dd          g}| j        |                    | j        j                   |D ]}||                                                    dd                              dd          }dD ]}|                    |d          }d                    d |D                       }|                                	                                D ]}|t          v r|c c S |st          d	          t          j        d
           t          | j                  dk    rdS dS )a9  
    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   "   K   | ]
}|d v|V  dS )
0123456789Nr   ).0cs     r   	<genexpr>z&units_from_metadata.<locals>.<genexpr>s   s,      @@Q!<*?*?q*?*?*?*?@@r   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   sU   & \fd++,E
zSZ)***   <zz||##GS1199&#FF 	, 	,E<<s++DDww@@$@@@@@##%% 	 	AG|| 	
  ?=>>>
 I-...SY%}xr   FNc                     | j         t          | |          | _         t          j        d| j         |           t	          | j         |          }|                     |           || _         dS )a{  
    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   r7   r   apply_scale)r#   r   r$   
conversions       r   _convert_unitsrA      si     y (5999	I.	7CCC G44J OOJCIIIr   )T)F)__doc__r)   r   	constantsr   parentr   get_jsonr   strr   r   r   r   r
   boolr=   rA   r   r   r   <module>rH      s1                      )
3
4
4OS O3 O5 O O O O(	c 	 	 	 	# %    D0 0X 0d 0c 0 0 0 0f  3       r   