
    l0j<                         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     P/home/wildlama/miniconda3/envs/lam/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                    dD ]}|| j         vr| j         |                                         }d|v rdD ]}|                    |d          }|                                                                D ]M}|                    dd                              dd                                          }|t
          v r|c c S N|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
    )	file_namenamer   z_-. units z!no units and not allowed to guesszno units: guessing from scaleg      Y@millimetersinches)metadatar   replacer   r   r   r   r   debugr   scale)r#   r$   r    hintsdelimhints         r   units_from_metadatar4   T   s!   ( %    cl""S!''))U?? 2 2eS11++--    ||GR0088DDJJLL7??KKKKK #  ><===
 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)   r4   r   r/   r   apply_scale)r#   r   r$   
conversions       r   _convert_unitsr8      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
   boolr4   r8   r   r   r   <module>r?      s1                      )
3
4
4OS O3 O5 O O O O(	c 	 	 	 	# %    D/ /X /d /c / / / /d  3       r   