a
    ëÝEb  ã                   @   s2   d Z ddlZddlZddlmZ G dd„ dƒZdS )zUnitDbl module.é    N)Ú_apic                	   @   s,  e Zd ZdZdddddddd	d
œZddddœZdd„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Ze eej¡Ze eej¡Ze eej¡Ze eej¡Ze eej¡Ze eej¡Zdd„ Ze eej¡Ze eej¡Zdd„ Z e e ej!¡Z"e e ej!¡Z#dd „ Z$d!d"„ Z%d#d$„ Z&e'd*d&d'„ƒZ(d(d)„ Z)d%S )+ÚUnitDblzClass UnitDbl in development.)gü©ñÒMbP?Úkm)é   r   )g 8€~ß¿ù?r   )r   Úrad)g:�R¢Fß‘?r   )r   Úsec)g      N@r   )i  r   )Úmr   Zmiler   Údegr   ÚminÚhourZdistanceZangleÚtime)r   r   r   c                 C   s0   t j| j|d�}t||d  ƒ| _|d | _dS )aI  
        Create a new UnitDbl object.

        Units are internally converted to km, rad, and sec.  The only
        valid inputs for units are [m, km, mile, rad, deg, sec, min, hour].

        The field UnitDbl.value will contain the converted value.  Use
        the convert() method to get a specific type of units back.

        = ERROR CONDITIONS
        - If the input units are not in the allowed list, an error is thrown.

        = INPUT VARIABLES
        - value     The numeric value of the UnitDbl.
        - units     The string name of the units the value is in.
        ©Úunitsr   r   N)r   Úcheck_getitemÚallowedÚfloatÚ_valueÚ_units)ÚselfÚvaluer   Údata© r   úd/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/matplotlib/testing/jpl_units/UnitDbl.pyÚ__init__#   s    zUnitDbl.__init__c                 C   sR   | j |kr| jS tj| j|d�}| j |d krDtd| › d|› d�ƒ‚| j|d  S )a†  
        Convert the UnitDbl to a specific set of units.

        = ERROR CONDITIONS
        - If the input units are not in the allowed list, an error is thrown.

        = INPUT VARIABLES
        - units     The string name of the units to convert to.

        = RETURN VALUE
        - Returns the value of the UnitDbl in the requested units as a floating
          point number.
        r   r   z[Error trying to convert to different units.
    Invalid conversion requested.
    UnitDbl: z
    Units:   Ú
r   )r   r   r   r   r   Ú
ValueError)r   r   r   r   r   r   Úconvert8   s    
þý
zUnitDbl.convertc                 C   s   t t| jƒ| jƒS )z*Return the absolute value of this UnitDbl.)r   Úabsr   r   ©r   r   r   r   Ú__abs__P   s    zUnitDbl.__abs__c                 C   s   t | j | jƒS )z*Return the negative value of this UnitDbl.©r   r   r   r   r   r   r   Ú__neg__T   s    zUnitDbl.__neg__c                 C   s
   t | jƒS )z$Return the truth value of a UnitDbl.)Úboolr   r   r   r   r   Ú__bool__X   s    zUnitDbl.__bool__c                 C   s   |   |d¡ || j|jƒS )zACheck that *self* and *rhs* share units; compare them using *op*.Úcompare)ÚcheckSameUnitsr   ©r   ÚopÚrhsr   r   r   Ú_cmp\   s    zUnitDbl._cmpc                 C   s$   |   ||j¡ t|| j|jƒ| jƒS )zACheck that *self* and *rhs* share units; combine them using *op*.)r%   Ú__name__r   r   r   r&   r   r   r   Ú_binop_unit_unith   s    zUnitDbl._binop_unit_unitc                 C   s   t || j|ƒ| jƒS )z'Combine *self* and *scalar* using *op*.r    )r   r'   Zscalarr   r   r   Ú_binop_unit_scalarp   s    zUnitDbl._binop_unit_scalarc                 C   s   d| j | jf S )úPrint the UnitDbl.z%g *%s©r   r   r   r   r   r   Ú__str__w   s    zUnitDbl.__str__c                 C   s   d| j | jf S )r-   zUnitDbl(%g, '%s')r.   r   r   r   r   Ú__repr__{   s    zUnitDbl.__repr__c                 C   s   | j | j S )z Return the type of UnitDbl data.)Ú_typesr   r   r   r   r   Útype   s    zUnitDbl.typeNc                 C   sJ   |du rt d| jƒ}g }d}| ||  }||kr2qF| |¡ |d7 }q|S )a?  
        Generate a range of UnitDbl objects.

        Similar to the Python range() method.  Returns the range [
        start, stop) at the requested step.  Each element will be a
        UnitDbl object.

        = INPUT VARIABLES
        - start     The starting value of the range.
        - stop      The stop value of the range.
        - step      Optional step to use.  If set to None, then a UnitDbl of
                      value 1 w/ the units of the start is used.

        = RETURN VALUE
        - Returns a list containing the requested UnitDbl values.
        Nr   r   )r   r   Úappend)ÚstartÚstopÚstepÚelemsÚiÚdr   r   r   Úrangeƒ   s    

zUnitDbl.rangec                 C   s.   | j |j kr*td|› d| j › d|j › �ƒ‚dS )aI  
        Check to see if units are the same.

        = ERROR CONDITIONS
        - If the units of the rhs UnitDbl are not the same as our units,
          an error is thrown.

        = INPUT VARIABLES
        - rhs     The UnitDbl to check for the same units
        - func    The name of the function doing the check.
        zCannot z  units of different types.
LHS: z
RHS: N)r   r   )r   r(   Úfuncr   r   r   r%   ¥   s    
ÿþzUnitDbl.checkSameUnits)N)*r*   Ú
__module__Ú__qualname__Ú__doc__r   r1   r   r   r   r!   r#   r)   Ú	functoolsÚpartialmethodÚoperatorÚeqÚ__eq__ÚneÚ__ne__ÚltÚ__lt__ÚleÚ__le__ÚgtÚ__gt__ÚgeÚ__ge__r+   ÚaddÚ__add__ÚsubÚ__sub__r,   ÚmulÚ__mul__Ú__rmul__r/   r0   r2   Ústaticmethodr:   r%   r   r   r   r   r   	   sL   öý!r   )r>   r?   rA   Z
matplotlibr   r   r   r   r   r   Ú<module>   s   