
    Ogi                        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 ddgZ	 d	 	 	 	 	 dd	Z	 d	 	 	 	 	 dd
Zy# e$ r Y "w xY w)    )annotations)IterableIteratorSequenceN)Vec2UVecVec3safe_normal_vectorOCS   )earcutmapbox_earcut_2dmapbox_earcut_3dc                    t        j                  |       }t        |      dk(  rg S g }|r"|D cg c]  }t        j                  |       }}t        ||      S c c}w )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   )r   listlenr   )exteriorholespointsholes_holes        ]/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/triangulation.pyr   r      sX    0 YYx F
6{a	!F.34d$))D/44&&!! 5s   Ac              #  V  	K   t        j                  |       }t        |      dk(  ry|d   j                  |d         r|j	                          t        |      }|dk  ry|dk(  r|d   |d   |d   f yt        t        |            }|j                  |d         j                  	t        |j                  |            }g }|r'|D cg c]  }t        |j                  |             }}t        ||      D ]'  }t        |j                  	fd|D                     ) yc c}w w)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              3  `   K   | ]%  }t        |j                  |j                         ' y wN)r	   xy).0v	elevations     r   	<genexpr>z#mapbox_earcut_3d.<locals>.<genexpr>i   s"     JAd133Y7Js   +.)r	   r   r   isclosepopr   r
   from_wcszpoints_from_wcsr   tuplepoints_to_wcs)
r   r   polygoncountocsexterior_ocs	holes_ocsr   triangler#   s
            @r   r   r   7   s"    4 ii!G
7|qqz'"+&LEqyzaj'!*gaj00
 )
*CWQZ(**I++G45L"$IAFGT#--d34G	G <3 
JJJ
 	

	 Hs   CD)
!D$+>D)r   )r   Iterable[UVec]r   Iterable[Iterable[UVec]] | Nonereturnzlist[Sequence[Vec2]])r   r2   r   r3   r4   zIterator[Sequence[Vec3]])
__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   <module>rA      s    # / /  @ @ "==2
  HL""%D""D HL3
3
%D3
3
U  s    A! !A)(A)