U
    7h                     @   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   O/var/www/formularioweb/env/lib/python3.8/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 NaNZ   )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rt 
|| }||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rt 	|| }||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rd| }|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   