
    'ji                        d dl mZ d dlmZmZmZ d dlZd dlmZm	Z	m
Z
mZmZ ddlmZ ej        j        r	 d dlmZ n# e$ r Y nw xY wddgZ	 dddZ	 dddZdS )    )annotations)IterableIteratorSequenceN)Vec2UVecVec3safe_normal_vectorOCS   )earcutmapbox_earcut_2dmapbox_earcut_3dexteriorIterable[UVec]holesIterable[Iterable[UVec]] | Nonereturnlist[Sequence[Vec2]]c                    t          j        |           }t          |          dk    rg S g }|rd |D             }t          ||          S )a:  Mapbox triangulation algorithm with hole support for 2D polygons.

    Implements a modified ear slicing algorithm, optimized by z-order
    curve hashing and extended to handle holes, twisted polygons, degeneracies
    and self-intersections in a way that doesn't guarantee correctness of
    triangulation, but attempts to always produce acceptable results for
    practical data.

    Source: https://github.com/mapbox/earcut

    Args:
        exterior: exterior polygon as iterable of :class:`Vec2` objects
        holes: iterable of holes as iterable of :class:`Vec2` objects, a hole
            with single point represents a `Steiner point`_.

    Returns:
        yields the result as 3-tuples of :class:`Vec2` objects

    .. _Steiner point: https://en.wikipedia.org/wiki/Steiner_point_(computational_geometry)

    r   c                6    g | ]}t          j        |          S  )r   list).0holes     R/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/triangulation.py
<listcomp>z$mapbox_earcut_2d.<locals>.<listcomp>3   s     444d$)D//444    )r   r   lenr   )r   r   pointsholes_s       r   r   r      sY    0 Yx  F
6{{a	!F 544e444&&!!!r   Iterator[Sequence[Vec3]]c              #    K   t          j        |           }t          |          dk    rdS |d                             |d                   r|                                 t          |          }|dk     rdS |dk    r|d         |d         |d         fV  dS t          t          |                                        |d                   j        t          	                    |                    }g }|rfd|D             }t          ||          D ]2}t                              fd|D                                 V  3dS )	aU  Mapbox triangulation algorithm with hole support for flat 3D polygons.

    Implements a modified ear slicing algorithm, optimized by z-order
    curve hashing and extended to handle holes, twisted polygons, degeneracies
    and self-intersections in a way that doesn't guarantee correctness of
    triangulation, but attempts to always produce acceptable results for
    practical data.

    Source: https://github.com/mapbox/earcut

    Args:
        exterior: exterior polygon as iterable of :class:`Vec3` objects
        holes: iterable of holes as iterable of :class:`Vec3` objects, a hole
            with single point represents a `Steiner point`_.

    Returns:
        yields the result as 3-tuples of :class:`Vec3` objects

    Raise:
        TypeError: invalid input data type
        ZeroDivisionError: normal vector calculation failed

    r   N   r      c                T    g | ]$}t                              |                    %S r   )r   points_from_wcs)r   r   ocss     r   r   z$mapbox_earcut_3d.<locals>.<listcomp>c   s/    GGGT#--d3344GGGr   c              3  N   K   | ]}t          |j        |j                  V   d S N)r	   xy)r   v	elevations     r   	<genexpr>z#mapbox_earcut_3d.<locals>.<genexpr>i   s3      JJAd13Y77JJJJJJr   )r	   r   r   isclosepopr   r
   from_wcszr(   r   tuplepoints_to_wcs)	r   r   polygoncountexterior_ocs	holes_ocstriangler/   r)   s	          @@r   r   r   7   s|     4 i!!G
7||qqz'"+&& LLEqyyzzaj'!*gaj0000
 ))
*
*CWQZ((*I++G4455L"$I HGGGGGGG	 <33 
 
JJJJJJJJJ
 
 	
 	
 	
 	

 
r   r+   )r   r   r   r   r   r   )r   r   r   r   r   r"   )
__future__r   typingr   r   r   ezdxf
ezdxf.mathr   r   r	   r
   r   _mapbox_earcutr   options	use_c_extezdxf.acc.mapbox_earcutImportError__all__r   r   r   r   r   <module>rF      s   # " " " " " / / / / / / / / / /  @ @ @ @ @ @ @ @ @ @ @ @ @ @ " " " " " "= 2222222     HL" " " " "D HL3
 3
 3
 3
 3
 3
 3
s   = AA