3
$ßL]o  ã               @   s    d Z ddlZG dd„ deƒZdS )zUnitDbl module.é    Nc            	   @   sô   e Zd ZdZd?d@dAdBdCdDdEdFdœZddddœZdd„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ ZdGd9d:„ZeeƒZd;d<„ Zd=d>„ Zd8S )HÚUnitDblz"Class UnitDbl in development.
    çü©ñÒMbP?Úkmé   ç 8€~ß¿ù?Úradç:�R¢Fß‘?Úsecç      N@é  )Úmr   Zmiler   Údegr	   ÚminÚhourZdistanceZangleÚtime)r   r   r	   c             C   s4   | j |ƒ | j| }t||d  ƒ| _|d | _dS )a@  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.
        r   r   N)Ú
checkUnitsÚallowedÚfloatÚ_valueÚ_units)ÚselfÚvalueÚunitsÚdata© r   úL/tmp/pip-install-edjban26/matplotlib/matplotlib/testing/jpl_units/UnitDbl.pyÚ__init__    s    

zUnitDbl.__init__c             C   sX   | j |kr| jS | j|ƒ | j| }| j |d krJdt| ƒ|f }t|ƒ‚| 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   zoError trying to convert to different units.
    Invalid conversion requested.
    UnitDbl: %s
    Units:    %s
r   )r   r   r   r   ÚstrÚ
ValueError)r   r   r   Úmsgr   r   r   Úconvert6   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__R   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__V   s    zUnitDbl.__neg__c             C   s
   t | jƒS )z$Return the truth value of a UnitDbl.)Úboolr   )r   r   r   r   Ú__bool__Z   s    zUnitDbl.__bool__c             C   s   | j |tjƒS )N)Ú_cmpÚoperatorÚeq)r   Úrhsr   r   r   Ú__eq__^   s    zUnitDbl.__eq__c             C   s   | j |tjƒS )N)r&   r'   Úne)r   r)   r   r   r   Ú__ne__a   s    zUnitDbl.__ne__c             C   s   | j |tjƒS )N)r&   r'   Últ)r   r)   r   r   r   Ú__lt__d   s    zUnitDbl.__lt__c             C   s   | j |tjƒS )N)r&   r'   Úle)r   r)   r   r   r   Ú__le__g   s    zUnitDbl.__le__c             C   s   | j |tjƒS )N)r&   r'   Úgt)r   r)   r   r   r   Ú__gt__j   s    zUnitDbl.__gt__c             C   s   | j |tjƒS )N)r&   r'   Úge)r   r)   r   r   r   Ú__ge__m   s    zUnitDbl.__ge__c             C   s   | j |dƒ || j|jƒS )aR  Compare two UnitDbl's.

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

        = INPUT VARIABLES
        - rhs     The UnitDbl to compare against.
        - op      The function to do the comparison

        = RETURN VALUE
        - Returns op(self, rhs)
        Úcompare)ÚcheckSameUnitsr   )r   r)   Úopr   r   r   r&   p   s    zUnitDbl._cmpc             C   s    | j |dƒ t| j|j | jƒS )a,  Add two UnitDbl's.

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

        = INPUT VARIABLES
        - rhs     The UnitDbl to add.

        = RETURN VALUE
        - Returns the sum of ourselves and the input UnitDbl.
        Úadd)r6   r   r   r   )r   r)   r   r   r   Ú__add__�   s    zUnitDbl.__add__c             C   s    | j |dƒ t| j|j | jƒS )a=  Subtract two UnitDbl's.

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

        = INPUT VARIABLES
        - rhs     The UnitDbl to subtract.

        = RETURN VALUE
        - Returns the difference of ourselves and the input UnitDbl.
        Úsubtract)r6   r   r   r   )r   r)   r   r   r   Ú__sub__‘   s    zUnitDbl.__sub__c             C   s   t | j| | jƒS )zªScale a UnitDbl by a value.

        = INPUT VARIABLES
        - rhs     The scalar to multiply by.

        = RETURN VALUE
        - Returns the scaled UnitDbl.
        )r   r   r   )r   r)   r   r   r   Ú__mul__¡   s    	zUnitDbl.__mul__c             C   s   t | j| | jƒS )zªScale a UnitDbl by a value.

        = INPUT VARIABLES
        - lhs     The scalar to multiply by.

        = RETURN VALUE
        - Returns the scaled UnitDbl.
        )r   r   r   )r   Úlhsr   r   r   Ú__rmul__¬   s    	zUnitDbl.__rmul__c             C   s   t | j| | jƒS )z©Divide a UnitDbl by a value.

        = INPUT VARIABLES
        - rhs     The scalar to divide by.

        = RETURN VALUE
        - Returns the scaled UnitDbl.
        )r   r   r   )r   r)   r   r   r   Ú__div__·   s    	zUnitDbl.__div__c             C   s   d| j | jf S )zPrint the UnitDbl.z%g *%s)r   r   )r   r   r   r   Ú__str__Â   s    zUnitDbl.__str__c             C   s   d| j | jf S )zPrint the UnitDbl.zUnitDbl(%g, '%s'))r   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   sN   |dkrt d| jƒ}g }d}x,| ||  }||kr4P |j|ƒ |d7 }qW |S )a6  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 kr$td|t| j jƒ ƒf ƒ‚dS )zîCheck to see if some units are valid.

        = 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 check.
        z9Input units '%s' are not one of the supported types of %sN)r   r   ÚlistÚkeys)r   r   r   r   r   r   ð   s    	
zUnitDbl.checkUnitsc             C   s*   | j |j kr&d|| j |j f }t|ƒ‚dS )a@  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.
        z3Cannot %s units of different types.
LHS: %s
RHS: %sN)r   r   )r   r)   Úfuncr   r   r   r   r6   þ   s    zUnitDbl.checkSameUnits)r   r   )r   r   )r   r   )r   r   )r   r   )r   r	   )r
   r	   )r   r	   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rB   r   r    r"   r#   r%   r*   r,   r.   r0   r2   r4   r&   r9   r;   r<   r>   r?   r@   rA   rC   rK   Ústaticmethodr   r6   r   r   r   r   r      sH   
 r   )rR   r'   Úobjectr   r   r   r   r   Ú<module>   s   