o
    ÓèFhð  ã                   @   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   úN/var/www/html/loop/nvenv/lib/python3.10/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 rn 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r|nd||  }||fS )z#Error free transformation of a sum.r   ç        r   )ÚuÚvÚsÚupÚvppÚtr   r   r   Úsum/   s   zMath.sumc                 C   sL   t | dk rdn|| ƒ}| dkr$| d8 } |d7 }|| ||  }| dks|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s't|ƒdkr6t ||dkr2||  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rA|| }}n|dkrM| | }}n
|dkrW| |}}|d }|dkret  
|| ¡}||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r8|| }}n|dkrD| | }}n
|dkrN| |}}|d }|dkr\t  	|| ¡}||fS )zCCompute sine and cosine of (x + t) in degrees with x in [-180, 180]r-   r   r1   r   r2   r   r   )
r   r&   r5   r6   r7   r   r%   r8   r9   r	   )r   r   r:   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r4t d| ¡| }|S |dkr>d| }|S |dkrFd| }|S )z.compute atan2(y, x) with the result in degreesr2   r   r   r+   r-   r   i¦ÿÿÿ)r   r   ÚdegreesÚatan2r	   )r   r   r:   Úangr   r   r   Úatan2d”   s   þÿzMath.atan2dN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r#   r%   r'   r,   r.   r0   r<   r=   rA   r   r   r   r   r      s8    




	




	

r   )rE   r   r   r   r   r   r   r   Ú<module>   s    