
    h6                     J    S SK Jr  S SKJr  S SKJr  S SKJr   " S S\5      r	g)    )
prototypes)GEOSGeometry)GEOM_PTR)
LinearRingc                      ^  \ rS rSrSrU 4S jrS rS r\S 5       r	S r
S r SS	 jrS
 rS rS r\R"                  r\R&                  r\S 5       rS rS r\" \\5      r\r\S 5       r\r\S 5       rSrU =r$ )Polygon      c                   > U(       d"  [         TU ]  " U R                  SS5      40 UD6  gUtp4[        U5      nUS:X  aX  [	        US   [
        [        45      (       a:  US   (       d  SnSnO+[	        US   S   [        5      (       a  US   n[        U5      nU R                  US-   U/UQ5      n[         TU ]  " U40 UD6  g)ak  
Initialize on an exterior ring and a sequence of holes (both
instances may be either LinearRing instances, or a tuple/list
that may be constructed into a LinearRing).

Examples of initialization, where shell, hole1, and hole2 are
valid LinearRing geometries:
>>> from django.contrib.gis.geos import LinearRing, Polygon
>>> shell = hole1 = hole2 = LinearRing()
>>> poly = Polygon(shell, hole1, hole2)
>>> poly = Polygon(shell, (hole1, hole2))

>>> # Example where a tuple parameters are used:
>>> poly = Polygon(((0, 0), (0, 10), (10, 10), (10, 0), (0, 0)),
...                ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4)))
r   Nr
    )super__init___create_polygonlen
isinstancetuplelistr   )selfargskwargsext_ring
init_holesn_holespolygon	__class__s          Q/var/www/html/env/lib/python3.13/site-packages/django/contrib/gis/geos/polygon.pyr   Polygon.__init__
   s    " GT11!T:EfE !%j/ a<Jz!}udmDDa=
JqM!,j99']
j/&&w{X4K
4KL+F+    c              #   N   #    [        [        U 5      5       H	  nX   v   M     g7f)z&Iterate over each ring in the polygon.N)ranger   )r   is     r   __iter__Polygon.__iter__0   s     s4y!A'M "s   #%c                      U R                   S-   $ )z+Return the number of rings in this Polygon.r
   )num_interior_ringsr   s    r   __len__Polygon.__len__5   s    &&**r   c                     Uu  p#pEU HT  n[        U[        [        45      (       a  M   [        SU< SU< SU< SU< SU< SU< SU< SU< SU< SU< S35      s  $    [	        X#4X%4XE4XC4X#445      $ )z2Construct a Polygon from a bounding box (4-tuple).z	POLYGON(( z, z)))r   floatintr   r   )clsbboxx0y0x1y1zs          r   	from_bboxPolygon.from_bbox9   sq     Aa%..#2r2r2r2r2?   2(RHrhIJJr   c                    U(       d  [         R                  " 5       $ / nU HK  n[        U[        5      (       a  UR	                  U5        M+  UR	                  U R                  U5      5        MM     U R                  UR                  S5      5      nUS-
  nU(       a,  [        U-  " U Vs/ s H  o@R                  U5      PM     sn6 nOS n[         R                  " XWU5      $ s  snf )Nr   r
   )	capicreate_empty_polygonr   r   append_construct_ring_clonepopcreate_polygon)r   lengthitemsringsrshellr   holes_params           r   r   Polygon._create_polygonF   s    
 ,,..A!X&&QT11!45	  EIIaL)1*#g-0OAQ0OPKK""5w??	 1Ps   )C!c                     [        U[        5      (       a  [        R                  " U5      $ [        R                  " UR                  5      $ N)r   r   r7   
geom_cloneptr)r   gs     r   r;   Polygon._clone_   s1    a""??1%%??155))r   c                 z    [        U[        5      (       a  U$  [        U5      $ ! [         a    [        U5      ef = f)z1Try to construct a ring from the given parameter.)r   r   	TypeError)r   parammsgs      r   r:   Polygon._construct_ringe   s?     eZ((L	!e$$ 	!C. 	!s   
$ :c                     U R                   nU R                  nU R                  X5      U l         U(       a  X@l        [        R                  " U5        g rF   )rH   sridr   r7   destroy_geom)r   r>   r?   prev_ptrrQ   s        r   	_set_listPolygon._set_listu   s>     88yy''6I(#r   c                     US:X  a   [         R                  " U R                  5      $ [         R                  " U R                  US-
  5      $ )a  
Return the ring at the specified index. The first index, 0, will
always return the exterior ring.  Indices > 0 will return the
interior ring at the given index (e.g., poly[1] and poly[2] would
return the first and second interior ring, respectively).

CAREFUL: Internal/External are not the same as Interior/Exterior!
Return a pointer from the existing geometries for use internally by the
object's methods. _get_single_external() returns a clone of the same
geometry for use by external code.
r   r
   )r7   get_extringrH   get_intringr   indexs     r   _get_single_internalPolygon._get_single_internal   s=     A:##DHH-- ##DHHeai88r   c                 p    [        [        R                  " U R                  U5      5      U R                  S9$ )N)rQ   )r   r7   rG   r[   rQ   rY   s     r   _get_single_externalPolygon._get_single_external   s,    OOD55e<=DII
 	
r   c                 B    [         R                  " U R                  5      $ )z$Return the number of interior rings.)r7   
get_nringsrH   r&   s    r   r%   Polygon.num_interior_rings   s     txx((r   c                     U S   $ )z%Get the exterior ring of the Polygon.r   r   r&   s    r   _get_ext_ringPolygon._get_ext_ring   s    Awr   c                     XS'   g)z%Set the exterior ring of the Polygon.r   Nr   )r   rings     r   _set_ext_ringPolygon._set_ext_ring   s	    Qr   c                 R   ^  [        U 4S j[        [        T 5      5       5       5      $ )z,Get the tuple for each ring in this Polygon.c              3   B   >#    U  H  nTU   R                   v   M     g 7frF   )r   .0r!   r   s     r   	<genexpr> Polygon.tuple.<locals>.<genexpr>   s     =,<qT!W]],<s   )r   r    r   r&   s   `r   r   Polygon.tuple   s     =E#d),<===r   c                    ^  SR                  U 4S j[        T R                  5       5       5      nST S   R                  < SU< S3$ )z.Return the KML representation of this Polygon. c              3   N   >#    U  H  nS TUS-      R                   -  v   M     g7f)z%<innerBoundaryIs>%s</innerBoundaryIs>r
   N)kmlrl   s     r   rn   Polygon.kml.<locals>.<genexpr>   s)      
3 4d1q5kooE3s   "%z<Polygon><outerBoundaryIs>r   z</outerBoundaryIs>z
</Polygon>)joinr    r%   rt   )r   	inner_kmls   ` r   rt   Polygon.kml   sE     GG 
4223
 
	
 GKK
 	
r   )rH   rQ   )zYParameter must be a sequence of LinearRings or objects that can initialize to LinearRings) __name__
__module____qualname____firstlineno__
_minlengthr   r"   r'   classmethodr4   r   r;   r:   rT   r[   r^   r   _set_single_rebuild_set_single_assign_extended_slice_rebuild_assign_extended_slicepropertyr%   rd   rh   exterior_ringrB   r   coordsrt   __static_attributes____classcell__)r   s   @r   r   r      s    J$,L
+ 	K 	K@2*(	! $9$

 22K)HH ) )

 ]M:ME> > F	
 	
r   r   N)
django.contrib.gis.geosr   r7    django.contrib.gis.geos.geometryr   django.contrib.gis.geos.libgeosr   "django.contrib.gis.geos.linestringr   r   r   r   r   <module>r      s    6 9 4 9v
l v
r   