
    Oi.                     P    d Z ddlZddlmZ ddlmZ ddlmZ  G d d          ZdS )a  Define the :class:`~geographiclib.polygonarea.PolygonArea` class

The constructor initializes a empty polygon.  The available methods are

  * :meth:`~geographiclib.polygonarea.PolygonArea.Clear` reset the
    polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.AddPoint` add a vertex
    to the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.AddEdge` add an edge
    to the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.Compute` compute the
    properties of the polygon
  * :meth:`~geographiclib.polygonarea.PolygonArea.TestPoint` compute the
    properties of the polygon with a tentative additional vertex
  * :meth:`~geographiclib.polygonarea.PolygonArea.TestEdge` compute the
    properties of the polygon with a tentative additional edge

The public attributes for this class are

  * :attr:`~geographiclib.polygonarea.PolygonArea.earth`
    :attr:`~geographiclib.polygonarea.PolygonArea.polyline`
    :attr:`~geographiclib.polygonarea.PolygonArea.area0`
    :attr:`~geographiclib.polygonarea.PolygonArea.num`
    :attr:`~geographiclib.polygonarea.PolygonArea.lat1`
    :attr:`~geographiclib.polygonarea.PolygonArea.lon1`

    N)Math)Accumulator)Geodesicc                       e Zd ZdZed             Zed             Zed             Zed             ZddZ	d Z
d	 Zd
 ZddZddZddZdS )PolygonAreazArea of a geodesic polygonc                     t          j        | |          \  }}t          j        |           } t          j        |          }|dk    r| dcxk     r|k    sn | dk    r|dk    rdn|dk     r|dcxk     r| k    rn ndndS )z/Count crossings of prime meridian for AddPoint.r      )r   AngDiffAngNormalize)lon1lon2lon12_s       Q/srv/django_bis/venv311/lib/python3.11/site-packages/geographiclib/polygonarea.py_transitzPolygonArea._transit7   s     |D$''HE1T""DT""D!1!1!1!1T!1!1!1!1!%daii A		dQ&6&6&6&6$&6&6&6&6&6""A@    c                     t          j        | d          } t          j        |d          }d|cxk    rdk     rn ndndd| cxk    rdk     rn ndndz
  S )z.Count crossings of prime meridian for AddEdge.g     @r   ih  r	   r   	remainder)r   r   s     r   _transitdirectzPolygonArea._transitdirectD   sm    
 >$&&Dt~dE/J/J????s?????aa????s?????aa+ -r   c                 ~   |                      |           |dz  r5|                     |                                 dk     rdnd|z  dz             |s|                                  |rd|                                 |dz  k    r|                     |            n|                                 | dz  k    r|                     |           n\|                                 |k    r|                     |            n-|                                 dk     r|                     |           d|                                 z   S )z)Reduce accumulator area to allowed range.r	   r   r
              )	RemainderAddSumNegateareaarea0	crossingsreversesigns        r   _areareduceAzPolygonArea._areareduceAM   s(    	NN51} :
hhdhhjj1nn"5a7999 !DKKMMM 		eAg		5&88::%!!5	u		5&88::>>5r   c                     t          j        | |          } |dz  r| | dk     rdnd|z  dz  z  } |s| dz  } |r| |dz  k    r| |z  } n'| | dz  k    r| |z  } n| |k    r| |z  } n| dk     r| |z  } d| z   S )z$Reduce double area to allowed range.r	   r   r
   r   r   r   r   s        r   _areareduceBzPolygonArea._areareduceBd   s     >$&&D1} 0
D1HHqq"-a//d DBJD 		aE6!8	!88:r   Fc                     || _         	 || _        	 dt          j        z  |j        z  | _        	 t          j        t          j        z  t          j	        z  | j        rt          j
        nt          j        t          j        z  z  | _        | j        st                      | _        t                      | _        d| _        	 t          j        | _        	 t          j        | _        	 d| _        t          j        x| _        | _        dS )zConstruct a PolygonArea object

    :param earth: a :class:`~geographiclib.geodesic.Geodesic` object
    :param polyline: if true, treat object as a polyline instead of a polygon

    Initially the polygon has no vertices.
       r   N)earthpolylinemathpi_c2r!   r   LATITUDE	LONGITUDEDISTANCEEMPTYAREALONG_UNROLL_maskr   _areasum_perimetersumnumnanlat1r   
_crossings_lat0_lon0)selfr*   r+   s      r   __init__zPolygonArea.__init__{   s     DJ(DM(TWuy(DJ?#h&88#$%)] 88>>=8#779DJ =7+--$-$DDH@DI4DI5DO"h&DJr   c                     d| _         d| _        | j        s| j                            d           | j                            d           t          j        x| _        x| _	        x| _
        | _        dS )zReset to empty polygon.r   N)r8   r;   r+   r6   Setr7   r,   r9   r<   r=   r:   r   )r>   s    r   ClearzPolygonArea.Clear   sf    DHDO=.$-++A...16:h>DJ>>di$)))r   c           
         | j         dk    r|x| _        | _        |x| _        | _        n| j                            | j        | j        ||| j                  \
  }}}}}}}}}}| j        	                    |           | j
        sH| j        	                    |           | xj        t                              | j        |          z  c_        || _        || _        | xj         dz  c_         dS )zAdd the next vertex to the polygon

    :param lat: the latitude of the point in degrees
    :param lon: the longitude of the point in degrees

    This adds an edge from the current vertex to the new vertex.
    r   r	   N)r8   r<   r:   r=   r   r*   _GenInverser5   r7   r   r+   r6   r;   r   r   )r>   latlonr   s12S12s         r   AddPointzPolygonArea.AddPoint   s     x1}}""dj49""dj499)-)?)?	49c3
*4 *4&aaAq!Q3
S!!!] @#;//	3???didiHHMHHHHr   c           	         | j         dk    r| j                            | j        | j        |d|| j                  \	  }}}}}}}}}| j                            |           | j        sH| j	                            |           | xj
        t                              | j        |          z  c_
        || _        || _        | xj         dz  c_         dS dS )zAdd the next edge to the polygon

    :param azi: the azimuth at the current the point in degrees
    :param s: the length of the edge in meters

    This specifies the new vertex in terms of the edge from the current
    vertex.

    r   Fr	   N)r8   r*   
_GenDirectr:   r   r5   r7   r   r+   r6   r;   r   r   )r>   azisr   rE   rF   rH   s          r   AddEdgezPolygonArea.AddEdge   s     x1}}(,
(=(=	49c5!TZ)9 )9%ac1aAq#
Q] F#;55diEEEdidi
hh!mhhhh }r   Tc           
      l   t           j        }| j        dk     rd}| j        sd}| j        ||fS | j        r#| j                                        }| j        ||fS | j                            | j        | j	        | j
        | j        | j                  \
  }}}}}}}}}}| j                            |          }t          | j                  }|                    |           | j        t"                              | j	        | j                  z   }	t"                              || j        |	||          }| j        ||fS )a  Compute the properties of the polygon

    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    Arbitrarily complex polygons are allowed.  In the case of
    self-intersecting polygons the area is accumulated "algebraically",
    e.g., the areas of the 2 loops in a figure-8 polygon will partially
    cancel.

    If the object is a polygon (and not a polyline), the perimeter
    includes the length of a final edge connecting the current point to
    the initial point.  If the object is a polyline, then area is nan.

    More points can be added to the polygon after this call.

    r   r   )r,   r9   r8   r+   r7   r   r*   rD   r:   r   r<   r=   r5   r   r6   r   r;   r   r   r%   r!   )
r>   r#   r$   r    	perimeterr   rG   rH   tempsumr"   s
             r   ComputezPolygonArea.Compute   s.   , 8Dx!||i]&3DXy$&&} '$((**iXy$&&'+z'='=
iDJ
DJ(@ (@$AsAq!Q1a"&&s++I$-((GKK+"6"6ty$*"M"MMI##GTZ$+T3 3D8Y$$r   c                    t           j        }| j        dk    rd}| j        sd}d||fS | j                                        }| j        rdn| j                                        }| j        }| j        dz   }	| j        rdgnddgD ]}
| j        	                    |
dk    r| j
        n||
dk    r| j        n||
dk    r| j        n||
dk    r| j        n|| j                  \
  }}}}}}}}}}||z  }| j        s=||z  }|t                              |
dk    r| j        n||
dk    r| j        n|          z  }| j        r|	||fS t                              || j        |||          }|	||fS )a  Compute the properties for a tentative additional vertex

    :param lat: the latitude of the point in degrees
    :param lon: the longitude of the point in degrees
    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    r   r   r	   )r,   r9   r8   r+   r7   r   r6   r;   r*   rD   r:   r   r<   r=   r5   r   r   r'   r!   )r>   rE   rF   r#   r$   r    rP   rQ   r"   r8   ir   rG   rH   s                 r   	TestPointzPolygonArea.TestPoint   s    8Dx1}}i]&3D	4"&&((I];cc(9(9(;(;GItx!|].qccA 	H 	H)-)?)?!VV		166diis1ff

#Q!VVtzz
* *&aaAq!Q3 3i] H3[))qAvv$))378Avv3H H 	H	 } ")T!!##GTZ$+T3 3D	4r   c           
         | j         dk    rdt          j        t          j        fS | j         dz   }| j                                        |z   }| j        r||t          j        fS | j                                        }| j        }| j        	                    | j
        | j        |d|| j                  \	  }	}
}}	}	}	}	}	}||z  }|t                              | j        |          z  }| j                            |
|| j        | j        | j                  \
  }	}}	}	}	}	}	}	}	}||z  }||z  }|t                              || j                  z  }t                              || j        |||          }|||fS )a  Compute the properties for a tentative additional edge

    :param azi: the azimuth at the current the point in degrees
    :param s: the length of the edge in meters
    :param reverse: if true then clockwise (instead of
      counter-clockwise) traversal counts as a positive area
    :param sign: if true then return a signed result for the area if the
      polygon is traversed in the "wrong" direction instead of returning
      the area for the rest of the earth
    :return: a tuple of number, perimeter (meters), area (meters^2)

    r   r	   F)r8   r,   r9   r7   r   r+   r6   r;   r*   rK   r:   r   r5   r   r   rD   r<   r=   r   r'   r!   )r>   rL   rM   r#   r$   r8   rP   rQ   r"   r   rE   rF   rH   rG   r    s                  r   TestEdgezPolygonArea.TestEdge#  st    x1}}$(""
(Q,C"&&((1,I} &)TX%%}  ""GI&*j&;&;
iC4:'7 '7#AsCAq!QsNG++DIs;;;I'+z'='=	3
DJ
(4 (4$AsAq!Q1aIsNG%%c4:666I##GTZ$+T3 3D	4r   N)F)FT)__name__
__module____qualname____doc__staticmethodr   r   r%   r'   r?   rB   rI   rN   rR   rU   rW    r   r   r   r   4   s       ""
@ 
@ <
@ - - <-   <,   <,' ' ' '<? ? ?  .  .(% (% (% (%V&  &  &  & R#  #  #  #  #  # r   r   )	r[   r,   geographiclib.geomathr   geographiclib.accumulatorr   geographiclib.geodesicr   r   r]   r   r   <module>ra      s    \  & & & & & & 1 1 1 1 1 1 + + + + + +R  R  R  R  R  R  R  R  R  R r   