a
    zJ5d*                     @   s"  d dl mZ d dlmZ d dlmZmZ d dlZdZG dd deeZ	G dd	 d	e
eZe	jd
e	jde	jde	jde	jde	jde	jde e	jde de  iZdd Ze
e
ee
e
f dddZdded dddZe
e
dddZdddddZd d! Zeddd"d#d$Zeddddd%d&d'ZeeZeeZz d dlZd(Z eeZ!eeZ"W n e#yp   d)Z Y n0 zFd dl$Z$e re$j%d(d*eZ!e$j&d(d*e"Z"e$&eZe$&eZW n e#y   Y n0 e	jd)d(fd+d,Z'e	jd)d)d(fd-d.Z(e	jfeee
f d/d0d1Z)e	jfd2d3Z*dS )4    )Enum)pi)UnionTupleNg4@@c                   @   s0   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
S )Unitz
    Enumeration of supported units.
    The full list can be checked by iterating over the class; e.g.
    the expression `tuple(Unit)`.
    kmmmiZnmiftinZraddegN)__name__
__module____qualname____doc__
KILOMETERSMETERSMILESNAUTICAL_MILESFEETINCHESRADIANSDEGREES r   r   O/var/www/html/django/DPS/env/lib/python3.9/site-packages/haversine/haversine.pyr      s   r   c                   @   sH   e Zd ZdZdZed Zed Zed ZeZ	ed Z
ed Zed Zd	S )
	Directionz
    Enumeration of supported directions.
    The full list can be checked by iterating over the class; e.g.
    the expression `tuple(Direction)`.
    Angles expressed in radians.
    g        g      ?      ?g      ?g      ?g      ?g      ?N)r   r   r   r   ZNORTHr   Z	NORTHEASTZEASTZ	SOUTHEASTZSOUTHZ	SOUTHWESTZWESTZ	NORTHWESTr   r   r   r   r      s   r   g      ?g     @@g!E?g)hD}SG?g@gp
B9@   g     f@c                 C   s   t t|   S N)_AVG_EARTH_RADIUS_KM_CONVERSIONS)unitr   r   r   get_avg_earth_radius;   s    r"   )latlonreturnc                 C   s@   | d d d } | dkr(d|  } |d7 }|d d d }| |fS )zJ
    Normalize point to [-90, 90] latitude and [-180, 180] longitude.
    Z   h     r   r#   r$   r   r   r   
_normalize?   s    r*   numpy.ndarray)r+   r+   c                 C   s^   | d d d } |d d d }| dk}t |rVd| |  | |< || d d ||< | |fS )zK
    Normalize points to [-90, 90] latitude and [-180, 180] longitude.
    r&   r'   r(   )numpyany)r#   r$   wrapr   r   r   _normalize_vectorK   s    
r/   r)   c                 C   sD   | dk s| dkr t d|  d|dk s0|dkr@t d| dd	S )
r
    Ensure that the given latitude and longitude have proper values. An exception is raised if they are not.
    ir&   z	Latitude z is out of range [-90, 90]iLr(   z
Longitude z is out of range [-180, 180]N)
ValueErrorr)   r   r   r   _ensure_lat_lonX   s    r2   c                 C   s8   t |  dkrtdt | dkr4tddS )r0   r&   z"Latitude(s) out of range [-90, 90]r(   z%Longitude(s) out of range [-180, 180]N)r,   absmaxr1   r)   r   r   r   _ensure_lat_lon_vectorb   s    r5   c                    s    fddS )Nc                    s    f i | j S r   )__dict__)opsfr   r   <lambda>m       z_explode_args.<locals>.<lambda>r   r8   r   r8   r   _explode_argsl   s    r<   )asinarcsinc                    s     p|  fdd}|S )Nc                    sp   | } |}|}|}||  }|| }|d d | | |d d   }d | S )z
        Compute the haversine distance on unit sphere.  Inputs are in degrees,
        either scalars (with ops==math) or arrays (with ops==numpy).
        r      r   )lat1lng1lat2lng2r#   lngdr=   cosradianssinsqrtr   r   _haversine_kernelt   s    z3_create_haversine_kernel.<locals>._haversine_kernelr   )r=   r>   rG   rH   rI   rJ   _rK   r   rF   r   _create_haversine_kernelp   s    rM   )r=   r>   atan2arctan2c        	            s*    p| p| fdd}
|
S )Nc                    s   | } |}|| }}| |  }}|| } || ||  }	||| |||	   }
|	|
fS )z
        Compute the inverse haversine on unit sphere.  lat/lng are in degrees,
        direction in radians; all inputs are either scalars (with ops==math) or
        arrays (with ops==numpy).
        r   )r#   rD   	directionrE   Zcos_dZsin_dZcos_latZsin_latZsin_d_cos_latZ
return_latZ
return_lngr=   rN   rG   degreesrH   rI   r   r   _inverse_haversine_kernel   s    zC_create_inverse_haversine_kernel.<locals>._inverse_haversine_kernelr   )r=   r>   rN   rO   rG   rR   rH   rI   rJ   rL   rS   r   rQ   r    _create_inverse_haversine_kernel   s    rT   TF)Zfastmathc           	      C   s`   | \}}|\}}|r2t ||\}}t ||\}}n|rJt|| t|| t|t|||| S )aK   Calculate the great-circle distance between two points on the Earth surface.

    Takes two 2-tuples, containing the latitude and longitude of each point in decimal degrees,
    and, optionally, a unit of length.

    :param point1: first point; tuple of (latitude, longitude) in decimal degrees
    :param point2: second point; tuple of (latitude, longitude) in decimal degrees
    :param unit: a member of haversine.Unit, or, equivalently, a string containing the
                 initials of its corresponding unit of measurement (i.e. miles = mi)
                 default 'km' (kilometers).
    :param normalize: if True, normalize the points to [-90, 90] latitude and [-180, 180] longitude.
    :param check: if True, check that points are normalized.

    Example: ``haversine((45.7597, 4.8422), (48.8567, 2.3508), unit=Unit.METERS)``

    Precondition: ``unit`` is a supported unit (supported units are listed in the `Unit` enum)

    :return: the distance between the two points in the requested unit, as a float.

    The default returned unit is kilometers. The default unit can be changed by
    setting the unit parameter to a member of ``haversine.Unit``
    (e.g. ``haversine.Unit.INCHES``), or, equivalently, to a string containing the
    corresponding abbreviation (e.g. 'in'). All available units can be found in the ``Unit`` enum.
    )r*   r2   r"   rK   )	Zpoint1Zpoint2r!   	normalizecheckr@   rA   rB   rC   r   r   r   	haversine   s    

rW   c           
      C   sN  t stdt| tjs"t| } t|tjs8t|}| jdkrNt| d} |jdkrdt|d}|s|| j|jkr|t	d| dddf | dddf  }}|dddf |dddf  }}	|rt
||\}}t
||	\}}	n|rt|| t||	 |r8tj|dd}tj|dd}tj|dd}tj|	dd}	t|t||||	 S )aD  
    The exact same function as "haversine", except that this
    version replaces math functions with numpy functions.
    This may make it slightly slower for computing the haversine
    distance between two points, but is much faster for computing
    the distance between two vectors of points due to vectorization.
    zTError, unable to import Numpy, consider using haversine instead of haversine_vector.r   r   zjWhen not in combination mode, arrays must be of same size. If mode is required, use comb=True as argument.N)Zaxis)	has_numpyRuntimeError
isinstancer,   Zndarrayarrayndimexpand_dimsshape
IndexErrorr/   r5   r"   _haversine_kernel_vector)
Zarray1Zarray2r!   combrU   rV   r@   rA   rB   rC   r   r   r   haversine_vector   s:    



""

rb   )rP   c                 C   s"   | \}}t |}t||||| S r   )r"   rS   )pointdistancerP   r!   r#   rD   rr   r   r   inverse_haversine  s    rf   c                 C   s   t stdttj| ||f\} }}| jdkr:t| d} | jdksv| jd dksv| jd t|ksv| jd t|kr~t	d| d d df | d d df  }}t
|}t||||| S )NzdError, unable to import Numpy, consider using inverse_haversine instead of inverse_haversine_vector.r   r   r?   zArrays must be of same size.)rX   rY   mapr,   Zasarrayr\   r]   r^   lenr_   r"    _inverse_haversine_kernel_vector)r[   rd   rP   r!   r#   rD   re   r   r   r   inverse_haversine_vector  s    
<"rj   )+enumr   mathr   typingr   r   r   strr   floatr   r   r   r   r   r   r   r   r   r    r"   r*   r/   r2   r5   r<   rM   rT   rK   rS   r,   rX   r`   ri   ModuleNotFoundErrorZnumbaZ	vectorizeZnjitrW   rb   rf   rj   r   r   r   r   <module>   s^   




)4