
    gNA              	           d Z ddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZmZmZmZmZ  ej&                  ddeeed	d
z  ej(                  ej*                  z        Zd Zd Z G d d      Zy)z!
:class:`.Point` data structure.
    N)islice)fmodisfinite)unitsutil)DEGREEDOUBLE_PRIMEPRIMEformat_degreesformat_distancea&  
    .*?
    (?P<latitude>
      (?P<latitude_direction_front>[NS])?[ ]*
        (?P<latitude_degrees>[+-]?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
        (?:(?P<latitude_arcminutes>%(FLOAT)s)[%(PRIME)s'm][ ]*)?
        (?:(?P<latitude_arcseconds>%(FLOAT)s)[%(DOUBLE_PRIME)s"s][ ]*)?
        )?(?P<latitude_direction_back>[NS])?)
    %(SEP)s
    (?P<longitude>
      (?P<longitude_direction_front>[EW])?[ ]*
      (?P<longitude_degrees>[+-]?%(FLOAT)s)(?:[%(DEGREE)sD\*\u00B0\s][ ]*
      (?:(?P<longitude_arcminutes>%(FLOAT)s)[%(PRIME)s'm][ ]*)?
      (?:(?P<longitude_arcseconds>%(FLOAT)s)[%(DOUBLE_PRIME)s"s][ ]*)?
      )?(?P<longitude_direction_back>[EW])?)(?:
    %(SEP)s
      (?P<altitude>
        (?P<altitude_distance>[+-]?%(FLOAT)s)[ ]*
        (?P<altitude_units>km|m|mi|ft|nm|nmi)))?
    \s*$
z\d+(?:\.\d+)?z\s*[,;/\s]\s*)FLOATr   r
   r	   SEPc                 Z    |dz  }t        | |      xs d}|| k  r||z   S ||k\  r||z
  S |S )zC
    Normalize angle `x` to be within `[-limit; limit)` range.
    g       @        )r   )xlimitdouble_limitmodulos       K/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/geopy/point.py_normalize_angler   +   sI     3;L!\")cF$$$$M    c                 V   t        | xs d      } t        |xs d      }t        |xs d      }t        d | ||fD              }|st        d| ||fd      t        |       dkD  r't	        j
                  dt        d       t        d	      t        |      d
kD  rt        |d      }| ||fS )Nr   c              3   2   K   | ]  }t        |        y wN)r   ).0r   s     r   	<genexpr>z)_normalize_coordinates.<locals>.<genexpr>=   s     M-L-Ls   z"Point coordinates must be finite. z  has been passed as coordinates.Z   a4  Latitude normalization has been prohibited in the newer versions of geopy, because the normalized value happened to be on a different pole, which is probably not what was meant. If you pass coordinates as positional args, please make sure that the order is (latitude, longitude) or (y, x) in Cartesian terms.   )
stacklevelz(Latitude must be in the [-90; 90] range.   g     f@)floatall
ValueErrorabswarningswarnUserWarningr   )latitude	longitudealtitudeis_all_finites       r   _normalize_coordinatesr,   8   s    X_%Hi&3'IX_%HMh	8-LMMM/7H.MP Q 	Q 8}r L "a	1 CDD
9~ %Y6	Y((r   c                        e Zd ZdZdZeZd fd	Zd Zd Zd Z	d Z
d Zd	 Zdd
ZddZddZddZd Zd Zd Zedd       Zed        Zed        Zed        Zed        Z xZS )Pointu?  
    A geodetic point with latitude, longitude, and altitude.

    Latitude and longitude are floating point values in degrees.
    Altitude is a floating point value in kilometers. The reference level
    is never considered and is thus application dependent, so be consistent!
    The default for all values is 0.

    Points can be created in a number of ways...

    With latitude, longitude, and altitude::

        >>> p1 = Point(41.5, -81, 0)
        >>> p2 = Point(latitude=41.5, longitude=-81)

    With a sequence of 2 to 3 values (latitude, longitude, altitude)::

        >>> p1 = Point([41.5, -81, 0])
        >>> p2 = Point((41.5, -81))

    Copy another `Point` instance::

        >>> p2 = Point(p1)
        >>> p2 == p1
        True
        >>> p2 is p1
        False

    Give a string containing at least latitude and longitude::

        >>> p = Point('41.5,-81.0')
        >>> p = Point('+41.5 -81.0')
        >>> p = Point('41.5 N -81.0 W')
        >>> p = Point('-41.5 S, 81.0 E, 2.5km')
        >>> p = Point('23 26m 22s N 23 27m 30s E 21.0mi')
        >>> p = Point('''3 26' 22" N 23 27' 30" E''')

    Point values can be accessed by name or by index::

        >>> p = Point(41.5, -81.0, 0)
        >>> p.latitude == p[0]
        True
        >>> p.longitude == p[1]
        True
        >>> p.altitude == p[2]
        True

    When unpacking (or iterating), a ``(latitude, longitude, altitude)`` tuple is
    returned::

        >>> latitude, longitude, altitude = p

    Textual representations::

        >>> p = Point(41.5, -81.0, 12.3)
        >>> str(p)  # same as `p.format()`
        '41 30m 0s N, 81 0m 0s W, 12.3km'
        >>> p.format_unicode()
        '41° 30′ 0″ N, 81° 0′ 0″ W, 12.3km'
        >>> repr(p)
        'Point(41.5, -81.0, 12.3)'
        >>> repr(tuple(p))
        '(41.5, -81.0, 12.3)'
    r(   r)   r*   c                    |duxr
 |du xr |du }|r{t        |t        j                        sa|}t        |t              r| j	                  |      S t        |t
              r| j                  |      S 	 t        |      }| j                  |      S |rt        d      t        |||      \  }}}t        | 5  |       }||_        ||_        ||_        |S # t        $ r t        d|d      w xY w)z
        :param float latitude: Latitude of point.
        :param float longitude: Longitude of point.
        :param float altitude: Altitude of point.
        Nz%Failed to create Point instance from .zA single number has been passed to the Point constructor. This is probably a mistake, because constructing a Point with just a latitude seems senseless. If this is exactly what was meant, then pass the zero longitude explicitly to get rid of this error.)
isinstancer   NUMBER_TYPESr.   
from_pointstrfrom_stringiterfrom_sequence	TypeErrorr#   r,   super__new__r(   r)   r*   )	clsr(   r)   r*   
single_argargseqself	__class__s	           r   r;   zPoint.__new__   s
    T)Ti4.?THPTDT
j43D3DEC#u%~~c**C%s++2s)C ,,S11,  #8YA 	&)X ws# " 1 ! #FIK s   3C C,c                     t        |       |   S r   tuple)r@   indexs     r   __getitem__zPoint.__getitem__   s    T{5!!r   c                 Z    t        |       }|||<   t        | \  | _        | _        | _        y r   )listr,   r(   r)   r*   )r@   rE   valuepoints       r   __setitem__zPoint.__setitem__   s-    T
e"E* 	5t~t}r   c                 Z    t        | j                  | j                  | j                  f      S r   )r7   r(   r)   r*   r@   s    r   __iter__zPoint.__iter__   s     T]]DNNDMMBCCr   c                     t        |       S r   rC   rM   s    r   __getstate__zPoint.__getstate__   s    T{r   c                 .    |\  | _         | _        | _        y r   r/   )r@   states     r   __setstate__zPoint.__setstate__   s    7<4t~t}r   c                     dt        |       z  S )NzPoint(%r, %r, %r)rC   rM   s    r   __repr__zPoint.__repr__   s    "U4[00r   c                    t        t        | j                        |||d      d| j                  dk\  xr dxs d}t        t        | j                        |||d      d| j                  dk\  xr dxs d}||g}|t	        | j
                        }|r2t        |t              sd	}|j                  | j                  |             d
j                  |      S )a  
        Format decimal degrees (DD) to degrees minutes seconds (DMS)::

            >>> p = Point(41.5, -81.0, 12.3)
            >>> p.format()
            '41 30m 0s N, 81 0m 0s W, 12.3km'
            >>> p = Point(41.5, 0, 0)
            >>> p.format()
            '41 30m 0s N, 0 0m 0s E'

        See also :meth:`.format_unicode`.

        :param bool altitude: Whether to include ``altitude`` value.
            By default it is automatically included if it is non-zero.
        )degarcminarcsec)symbols r   NSEWkm, )r   r$   r(   r)   boolr*   r2   r5   appendformat_altitudejoin)r@   r*   deg_charmin_charsec_charr(   r)   coordinatess           r   formatzPoint.format   s    " 3t}}-8x8  MMQ&3-#-	
 3t~~.8x9  NNa'C.3.	
	  +DMM*Hh,t33H=>yy%%r   c                 B    | j                  |t        t        t              S )u~  
        :meth:`.format` with pretty unicode chars for degrees,
        minutes and seconds::

            >>> p = Point(41.5, -81.0, 12.3)
            >>> p.format_unicode()
            '41° 30′ 0″ N, 81° 0′ 0″ W, 12.3km'

        :param bool altitude: Whether to include ``altitude`` value.
            By default it is automatically included if it is non-zero.
        )rj   r   r
   r	   )r@   r*   s     r   format_unicodezPoint.format_unicode   s     {{fe\
 	
r   c                    t        | j                        t        | j                        g}|t        | j                        }|r2t        |t               sd}|j                  | j                  |             dj                  |      S )a  
        Format decimal degrees with altitude::

            >>> p = Point(41.5, -81.0, 12.3)
            >>> p.format_decimal()
            '41.5, -81.0, 12.3km'
            >>> p = Point(41.5, 0, 0)
            >>> p.format_decimal()
            '41.5, 0.0'

        :param bool altitude: Whether to include ``altitude`` value.
            By default it is automatically included if it is non-zero.
        r`   ra   )	r5   r(   r)   rb   r*   r2   rc   rd   re   )r@   r*   ri   s      r   format_decimalzPoint.format_decimal  sn     4==)3t~~+>?DMM*Hh,t33H=>yy%%r   c                 0    t        | j                  |      S )am  
        Format altitude with unit::

            >>> p = Point(41.5, -81.0, 12.3)
            >>> p.format_altitude()
            '12.3km'
            >>> p = Point(41.5, -81.0, 0)
            >>> p.format_altitude()
            '0.0km'

        :param str unit: Resulting altitude unit. Supported units
            are listed in :meth:`.from_string` doc.
        )unit)r   r*   )r@   rp   s     r   rd   zPoint.format_altitude)  s     t}}488r   c                 "    | j                         S r   )rj   rM   s    r   __str__zPoint.__str__9  s    {{}r   c                     t        |t        j                  j                        st        S t        |       t        |      k(  S r   )r2   collectionsabcIterableNotImplementedrD   r@   others     r   __eq__zPoint.__eq__<  s/    %!9!9:!!T{eEl**r   c                     | |k(   S r    rx   s     r   __ne__zPoint.__ne__A  s    EM""r   c                     t        |      }|dk  }t        |      }t        |      }|s|r$t        j                  ||      }|r||z  }n||z  }|dv r|S |dv r| S t        d      )z
        Convert degrees, minutes, seconds and direction (N, S, E, W)
        to a single degrees number.

        :rtype: float
        r   )
arcminutes
arcseconds)Nr\   r^   )r]   r_   z+Invalid direction! Should be one of [NSEW].)r!   r   degreesr#   )r<   r   r   r   	directionnegativemores          r   parse_degreeszPoint.parse_degreesD  s}     .Q;:&
:&
==J:ND44((N*$8OJKKr   c                     |&t        |      }d d d d d d d}	  ||   |      S |S # t        $ r t        d|j                         z        w xY w)	a  
        Parse altitude managing units conversion::

            >>> Point.parse_altitude(712, 'm')
            0.712
            >>> Point.parse_altitude(712, 'km')
            712.0
            >>> Point.parse_altitude(712, 'mi')
            1145.852928

        :param float distance: Numeric value of altitude.
        :param str unit: ``distance`` unit. Supported units
            are listed in :meth:`.from_string` doc.
        c                     | S r   r|   ds    r   <lambda>z&Point.parse_altitude.<locals>.<lambda>r  s    r   c                 .    t        j                  |       S )N)metersr   
kilometersr   s    r   r   z&Point.parse_altitude.<locals>.<lambda>s  s    u//q9r   c                 .    t        j                  |       S )N)milesr   r   s    r   r   z&Point.parse_altitude.<locals>.<lambda>t  s     0 0q 9r   c                 .    t        j                  |       S )N)feetr   r   s    r   r   z&Point.parse_altitude.<locals>.<lambda>u  s     0 0a 8r   c                 .    t        j                  |       S N)nauticalr   r   s    r   r   z&Point.parse_altitude.<locals>.<lambda>v  s     0 0! <r   c                 .    t        j                  |       S r   r   r   s    r   r   z&Point.parse_altitude.<locals>.<lambda>w  s    !1!11!=r   )r`   mmiftnmnmiz*Bad distance unit specified, valid are: %r)r!   KeyErrorNotImplementedErrorkeys)r<   distancerp   
CONVERTERSs       r   parse_altitudezPoint.parse_altitude_  sz      XH!998<=J'z$'11 O  )@OO%& s	   
+ &Ac                 L   t        j                  | j                  t        j                  dd|            }|rbd}|j	                  d      r|j	                  d      }n"|j	                  d      r|j	                  d      }d}|j	                  d      r|j	                  d      }n"|j	                  d      r|j	                  d      }| j                  |j	                  d      xs d	|j	                  d
      xs d	|j	                  d      xs d	|      }| j                  |j	                  d      xs d	|j	                  d      xs d	|j	                  d      xs d	|      }| j                  |j	                  d      |j	                  d            } | |||      S t        d      )u=  
        Create and return a ``Point`` instance from a string containing
        latitude and longitude, and optionally, altitude.

        Latitude and longitude must be in degrees and may be in decimal form
        or indicate arcminutes and arcseconds (labeled with Unicode prime and
        double prime, ASCII quote and double quote or 'm' and 's'). The degree
        symbol is optional and may be included after the decimal places (in
        decimal form) and before the arcminutes and arcseconds otherwise.
        Coordinates given from south and west (indicated by S and W suffixes)
        will be converted to north and east by switching their signs. If no
        (or partial) cardinal directions are given, north and east are the
        assumed directions. Latitude and longitude must be separated by at
        least whitespace, a comma, or a semicolon (each with optional
        surrounding whitespace).

        Altitude, if supplied, must be a decimal number with given units.
        The following unit abbrevations (case-insensitive) are supported:

            - ``km`` (kilometers)
            - ``m`` (meters)
            - ``mi`` (miles)
            - ``ft`` (feet)
            - ``nm``, ``nmi`` (nautical miles)

        Some example strings that will work include:

            - ``41.5;-81.0``
            - ``41.5,-81.0``
            - ``41.5 -81.0``
            - ``41.5 N -81.0 W``
            - ``-41.5 S;81.0 E``
            - ``23 26m 22s N 23 27m 30s E``
            - ``23 26' 22" N 23 27' 30" E``
            - ``UT: N 39°20' 0'' / W 74°35' 0''``

        z''"Nlatitude_direction_frontlatitude_direction_backlongitude_direction_frontlongitude_direction_backlatitude_degreesr   latitude_arcminuteslatitude_arcsecondslongitude_degreeslongitude_arcminuteslongitude_arcsecondsaltitude_distancealtitude_unitsz<Failed to create Point instance from string: unknown format.)rematchPOINT_PATTERNsubgroupr   r   r#   )r<   stringr   latitude_directionlongitude_directionr(   r)   r*   s           r   r6   zPoint.from_string  s   N **BFF5$,GH!%{{56%*[[1K%L"67%*[[1J%K""&{{67&+kk2M&N#78&+kk2L&M#((./63129c129c"	H ))/07C23:s23:s#	I ))/0,-H xH55N r   c                 h    t        t        |d            }t        |      dkD  rt        d       | | S )z
        Create and return a new ``Point`` instance from any iterable with 2 to
        3 elements.  The elements, if present, must be latitude, longitude,
        and altitude, respectively.
           r   zHWhen creating a Point from sequence, it must not have more than 3 items.)rD   r   lenr#   )r<   r?   argss      r   r8   zPoint.from_sequence  s>     VC^$t9q= @ A ADzr   c                 R     | |j                   |j                  |j                        S )ze
        Create and return a new ``Point`` instance from another ``Point``
        instance.
        r/   )r<   rJ   s     r   r4   zPoint.from_point  s     5>>5??ENNCCr   )NNN)N r   sr   )r`   )__name__
__module____qualname____doc__	__slots__r   r;   rF   rK   rN   rP   rS   rU   rj   rl   rn   rd   rr   rz   r}   classmethodr   r   r6   r8   r4   __classcell__)rA   s   @r   r.   r.   T   s    ?B 6I!M(T"+D=1%&N
 &29 +
# L L4 ! !F G GR 
 
 D Dr   r.   )r   collections.abcrt   r   r%   	itertoolsr   mathr   r   geopyr   r   geopy.formatr   r	   r
   r   r   compileVERBOSEUNICODEr   r   r,   r.   r|   r   r   <module>r      s~     	     U U

 *  )4 ::

5:
)8LD LDr   