o
    2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   K/var/www/html/gps/gps/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 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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    