a
    î}cð  ã                   @   s&   d Z ddlZddlZG dd„ dƒZdS )z7geomath.py: transcription of GeographicLib::Math class.é    Nc                   @   s¬   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )ÚMathz1
  Additional math routines for GeographicLib.
  c                 C   s   | |  S )zSquare a number© ©Úxr   r   úQ/var/www/html/django/DPS/env/lib/python3.9/site-packages/geographiclib/geomath.pyÚsq   s    zMath.sqc                 C   s   t  t  t| ƒd¡| ¡S )zReal cube root of a numbergUUUUUUÕ?)ÚmathÚcopysignÚpowÚabsr   r   r   r   Úcbrt   s    z	Math.cbrtc                 C   sP   dt j  krdk r4n nt t | ¡t |¡ ¡n
t | |¡}| | || fS )z Private: Normalize a two-vector.)é   é   )r   é
   )ÚsysÚversion_infor   Úsqrtr   r   Úhypot)r   ÚyÚrr   r   r   Únorm"   s    	ûû$
úz	Math.normc                 C   sH   | | }|| }|| }|| 8 }||8 }|dkr4|n
d||  }||fS )z#Error free transformation of a sum.r   ç        r   )ÚuÚvÚsÚupZvppÚtr   r   r   Úsum/   s    zMath.sumc                 C   sF   t | dk rdn|| ƒ}| dkrB| d8 } |d7 }|| ||  }q|S )zEvaluate a polynomial.r   é   )Úfloat)ÚNÚpr   r   r   r   r   r   Úpolyval?   s
    zMath.polyvalc                 C   s,   d}t | ƒ}||k r |||  }t || ¡S )z?Private: Round an angle so that small values underflow to zero.g      °?)r   r   r	   )r   Úzr   r   r   r   ÚAngRoundI   s    	zMath.AngRoundc                 C   s   t  | ¡rt  | |¡S t jS )z*remainder of x/y in the range [-y/2, y/2].)r   ÚisfiniteÚ	remainderÚnan©r   r   r   r   r   r&   X   s    zMath.remainderc                 C   s(   t  | d¡}t|ƒdkr$t d| ¡S |S )zreduce angle to [-180,180]éh  é´   g     €f@)r   r&   r   r   r	   r(   r   r   r   ÚAngNormalize^   s    zMath.AngNormalizec                 C   s   t | ƒdkrtjS | S )z&replace angles outside [-90,90] by NaNéZ   )r   r   r'   r   r   r   r   ÚLatFixe   s    zMath.LatFixc                 C   st   t  t  |  d¡t  |d¡¡\}}t  t  |d¡|¡\}}|dksNt|ƒdkrlt ||dkrd||  n| ¡}||fS )z1compute y - x and reduce to [-180,180] accuratelyr)   r   r*   )r   r   r&   r   r   r	   )r   r   Údr   r   r   r   ÚAngDiffk   s
    "zMath.AngDiffc                 C   sÒ   t  | ¡rt  | d¡nt j}t  |¡r*dntt|d ƒƒ}|d| 8 }t  |¡}t  |¡}t  	|¡}|d }|dkr‚||  }}n,|dkrš| |  }}n|dkr®| | }}|d }|dkrÊt  
|| ¡}||fS )	z(Compute sine and cosine of x in degrees.r)   r   r,   é   r   é   r   r   )r   r%   Úfmodr'   ÚisnanÚintÚroundÚradiansÚsinÚcosr	   )r   r   Úqr   Úcr   r   r   Úsincosdu   s    zMath.sincosdc                 C   sÀ   t  | ¡rtt| d ƒƒnd}| d|  }t  t || ¡¡}t  |¡}t  |¡}|d }|dkrp||  }}n,|dkrˆ| |  }}n|dkrœ| | }}|d }|dkr¸t  	|| ¡}||fS )zCCompute sine and cosine of (x + t) in degrees with x in [-180, 180]r,   r   r0   r   r1   r   r   )
r   r%   r4   r5   r6   r   r$   r7   r8   r	   )r   r   r9   r   r   r:   r   r   r   Úsincosde…   s     zMath.sincosdec                 C   sŒ   t | ƒt |ƒkr d}| | }} nd}|dk r:|d7 }| }t t | |¡¡}|dkrft d| ¡| }n"|dkrxd| }n|dkrˆd| }|S )z.compute atan2(y, x) with the result in degreesr1   r   r   r*   r,   r   i¦ÿÿÿ)r   r   ÚdegreesÚatan2r	   )r   r   r9   Úangr   r   r   Úatan2d”   s    zMath.atan2dN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r"   r$   r&   r+   r-   r/   r;   r<   r@   r   r   r   r   r      s6   




	




	

r   )rD   r   r   r   r   r   r   r   Ú<module>   s   