
    Vh                     B    d dl mZ d dlmZmZ d dlmZ  G d de      Zy)    )
WKTAdapter)GeometryCollectionPolygon)oracledbc                   \    e Zd Zej                  Zd Zed        Ze	dd       Z
e	d        Zy)OracleSpatialAdapterc                     t        |t              r# j                  |      rG j                  |      }n5t        |t              r%t         fd|D              r j                  |      }|j                   _        |j                   _        y)a  
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        c              3   d   K   | ]'  }t        |t              xr j                  |       ) y wN)
isinstancer   _polygon_must_be_fixed).0gselfs     ]/home/dcms/DCMS/lib/python3.12/site-packages/django/contrib/gis/db/backends/oracle/adapter.py	<genexpr>z0OracleSpatialAdapter.__init__.<locals>.<genexpr>   s0      NO
1g&I4+F+Fq+IIs   -0N)	r   r   r   _fix_polygonr   any_fix_geometry_collectionwktsrid)r   geoms   ` r   __init__zOracleSpatialAdapter.__init__	   su     dG$**40((.01 SW  44T:88II	    c                 v    | j                    xr+ | j                  j                   xs t        d | D              S )Nc              3   4   K   | ]  }|j                     y wr   )is_counterclockwise)r   xs     r   r   z>OracleSpatialAdapter._polygon_must_be_fixed.<locals>.<genexpr>!   s     7Q1((7s   )emptyexterior_ringr   r   )polys    r   r   z+OracleSpatialAdapter._polygon_must_be_fixed   s:    ::~ 
""666 87$77	
r   c                 $   |r|j                         }|j                  j                  s#t        t	        |j                              |_        t        dt        |            D ],  }||   j                  st        t	        ||               ||<   . |S )z:Fix single polygon orientation as described in __init__().   )cloner    r   listreversedrangelen)clsr!   r$   is       r   r   z!OracleSpatialAdapter._fix_polygon$   s~     ::<D!!55!%ht/A/A&B!CDq#d)$ 	2AAw**xQ01Q	2 r   c                     |j                         }t        |      D ],  \  }}t        |t              s| j	                  |d      ||<   . |S )zf
        Fix polygon orientations in geometry collections as described in
        __init__().
        F)r$   )r$   	enumerater   r   r   )r)   collr*   r   s       r   r   z-OracleSpatialAdapter._fix_geometry_collection3   sP     zz|  	>GAt$(**4u*=Q	> r   N)T)__name__
__module____qualname__r   CLOB
input_sizer   staticmethodr   classmethodr   r    r   r   r   r      sL    J( 
 
   	 	r   r   N)+django.contrib.gis.db.backends.base.adapterr   django.contrib.gis.geosr   r   &django.db.backends.oracle.oracledb_anyr   r   r5   r   r   <module>r9      s    B ? ;7: 7r   