
    g6                     J    d dl mZ d dlmZ d dlmZ d dlmZ  G d de      Z	y)    )
prototypes)GEOSGeometry)GEOM_PTR)
LinearRingc                        e Zd ZdZ fdZd Zd Zed        Zd Z	d Z
	 ddZd	 Zd
 Zd Zej                   Zej$                  Zed        Zd Zd Z eee      ZeZed        ZeZed        Z xZS )Polygon   c                 V   |s!t        |   | j                  dd      fi | y|^}}t        |      }|dk(  rIt	        |d   t
        t        f      r0|d   sd}d}n&t	        |d   d   t              r|d   }t        |      }| j                  |dz   |g|      }t        |   |fi | y)a  
        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          w/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/contrib/gis/geos/polygon.pyr   zPolygon.__init__
   s    " GT11!T:EfE !%:j/ a<Jz!}udmDa=
JqM!,j9']
j/&&w{X4K
4KL+F+    c              #   L   K   t        t        |             D ]	  }| |     yw)z&Iterate over each ring in the polygon.N)ranger   )r   is     r   __iter__zPolygon.__iter__0   s"     s4y!Aq'M "s   "$c                      | j                   dz   S )z+Return the number of rings in this Polygon.r	   )num_interior_ringsr   s    r   __len__zPolygon.__len__5   s    &&**r   c                     |\  }}}}|D ]D  }t        |t        t        f      rt        d|d|d|d|d|d|d|d|d|d|d      c S  t	        ||f||f||f||f||ff      S )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_bboxzPolygon.from_bbox9   s|     BBAa%.#2r2r2r2r2?   R2r(RHr2hRIJJr   c                    |st        j                         S g }|D ]D  }t        |t              r|j	                  |       %|j	                  | j                  |             F | j                  |j                  d            }|dz
  }|r)t        |z  |D cg c]  }| j                  |       c} }nd }t        j                  |||      S c c}w )Nr   r	   )	capicreate_empty_polygonr   r   append_construct_ring_clonepopcreate_polygon)r   lengthitemsringsrshellr   holes_params           r   r   zPolygon._create_polygonF   s    
 ,,..A!X&QT11!45	  EIIaL)1*#g-0OAQ0OPKK""5+w??	 1Ps   Cc                     t        |t              rt        j                  |      S t        j                  |j                        S N)r   r   r2   
geom_cloneptr)r   gs     r   r6   zPolygon._clone_   s.    a"??1%%??155))r   c                 n    t        |t              r|S 	 t        |      S # t        $ r t        |      w xY w)z1Try to construct a ring from the given parameter.)r   r   	TypeError)r   parammsgs      r   r5   zPolygon._construct_ringe   s<     eZ(L	!e$$ 	!C. 	!s   
 4c                     | j                   }| j                  }| j                  ||      | _         |r|| _        t        j                  |       y r@   )rB   sridr   r2   destroy_geom)r   r9   r:   prev_ptrrI   s        r   	_set_listzPolygon._set_listu   sB     88yy''6DI(#r   c                     |dk(  rt        j                  | j                        S t        j                  | j                  |dz
        S )a7  
        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	   )r2   get_extringrB   get_intringr   indexs     r   _get_single_internalzPolygon._get_single_internal   s=     A:##DHH-- ##DHHeai88r   c                 t    t        t        j                  | j                  |            | j                        S )N)rI   )r   r2   rA   rR   rI   rP   s     r   _get_single_externalzPolygon._get_single_external   s,    OOD55e<=DII
 	
r   c                 @    t        j                  | j                        S )z$Return the number of interior rings.)r2   
get_nringsrB   r#   s    r   r"   zPolygon.num_interior_rings   s     txx((r   c                     | d   S )z%Get the exterior ring of the Polygon.r   r   r#   s    r   _get_ext_ringzPolygon._get_ext_ring   s    Awr   c                     || d<   y)z%Set the exterior ring of the Polygon.r   Nr   )r   rings     r   _set_ext_ringzPolygon._set_ext_ring   s    Qr   c                 P     t         fdt        t                     D              S )z,Get the tuple for each ring in this Polygon.c              3   <   K   | ]  }|   j                     y wr@   )r   .0r   r   s     r   	<genexpr>z Polygon.tuple.<locals>.<genexpr>   s     =,<qT!W]],<s   )r   r   r   r#   s   `r   r   zPolygon.tuple   s     =E#d),<===r   c                      dj                   fdt         j                        D              }d d   j                  d|dS )z.Return the KML representation of this Polygon. c              3   H   K   | ]  }d |dz      j                   z    yw)z%<innerBoundaryIs>%s</innerBoundaryIs>r	   N)kmlr^   s     r   r`   zPolygon.kml.<locals>.<genexpr>   s*      
3 4d1q5kooE3s   "z<Polygon><outerBoundaryIs>r   z</outerBoundaryIs>z
</Polygon>)joinr   r"   rd   )r   	inner_kmls   ` r   rd   zPolygon.kml   sE     GG 
4223
 
	
 GKK
 	
r   )zYParameter must be a sequence of LinearRings or objects that can initialize to LinearRings)__name__
__module____qualname__
_minlengthr   r    r$   classmethodr0   r   r6   r5   rL   rR   rT   r   _set_single_rebuild_set_single_assign_extended_slice_rebuild_assign_extended_slicepropertyr"   rX   r[   exterior_ringr=   r   coordsrd   __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   r2    django.contrib.gis.geos.geometryr   django.contrib.gis.geos.libgeosr   "django.contrib.gis.geos.linestringr   r   r   r   r   <module>rx      s    6 9 4 9v
l v
r   