
    hՉ              
      n   % S r SSKJr  SSKJrJrJrJrJr  SSK	J
r
  SSKrSSKrSSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&  / SQr'Sr(Sr)Sr*\RV                  r+\RX                  SUS j5       r-\-R]                  \R^                  5      SVS j5       r0\-R]                  \Rb                  5      SWS j5       r2\-R]                  \Rf                  5      SXS j5       r4\-R]                  \Rj                  5      SYS j5       r6\-R]                  \Rn                  5      SZS j5       r8\-R]                  \Rr                  5      S[S j5       r:\-R]                  \Rv                  5      S\S j5       r<\-R]                  \Rz                  5      \-R]                  \R|                  5      S]S j5       5       r?\RX                  SUS j5       r@\@R]                  \R                  5      S^S j5       rB\@R]                  \Rb                  5      \@R]                  \R^                  5      S_S j5       5       rC\@R]                  \Rf                  5      SXS j5       rD\@R]                  \Rj                  5      SYS j5       rE\@R]                  \Rn                  5      SZS j5       rF\@R]                  \Rr                  5      S[S j5       rG\@R]                  \Rv                  5      S\S  j5       rH\@R]                  \Rz                  5      \@R]                  \R|                  5      S]S! j5       5       rIS`S" jrJS`S# jrKS`S$ jrLSaS% jrM\RX                  \+S&.SbS' jj5       rN\NR]                  \R                  5      \+S&.ScS( jj5       rO\NR]                  \R^                  5      \+S&.SdS) jj5       rP\NR]                  \Rf                  5      \+S&.SeS* jj5       rQ\NR]                  \Rj                  5      \+S&.SfS+ jj5       rR\NR]                  \Rn                  5      \+S&.SgS, jj5       rS\NR]                  \Rr                  5      \+S&.ShS- jj5       rT\+S&.   SiS. jjrU\+S&.SjS/ jjrVSS0S1.       SkS2 jjrWSS0S1.       SlS3 jjrX\Y\Z\\[4      r\S4\]S5'   SmS6 jr^        SnS7 jr_SoS8 jr`SoS9 jraSpS: jrbSqS; jrcSoS< jrdSoS= jreSoS> jrfSrS? jrgSsS@ jrh\R^                  \`\Rf                  \a\Rj                  \d\Rn                  \e\Rr                  \f0riStSA jrjS0SBSCSD.       SuSE jjrkS0SCSF.       SvSG jjrl        SwSH jrm          SxSI jrn          SySJ jro        SzSK jrpS{SL jrq          S|SM jrrS}SN jrs " SO SP\5      rtS~SQ jru S       SSR jjrv\+S&.     SSS jjrw\+S&.SST jjrxg)z
EdgeSmith
=========

A module for creating entities like polylines and hatch boundary paths from linked edges.

The complementary module to ezdxf.edgeminer.

    )annotations)IteratorIterableSequenceAny
NamedTuple)	TypeAliasN)
itemgetter)	edgeminerentities)path)boundary_paths)upright_all)UVecVec2Vec3arc_angle_span_degellipse_param_spanbulge_from_arc_angleZ_AXISMatrix44intersection_line_line_2dis_point_in_polygon_2dBoundingBox2darea)bounding_box_2dchain_verticesedge_path_from_chainedges_from_entities_2dfilter_2d_entitiesfilter_edge_entitiesfilter_open_edgesintersecting_edges_2dis_closed_entityis_inside_polygon_2dis_pure_2d_entity	loop_arealwpolyline_from_chainmake_edge_2dpath2d_from_chainpolyline2d_from_chainpolyline_path_from_chaing&.>gHz>c                    g)a  Returns ``True`` if the given entity represents a closed loop.

Tests the following DXF entities:

    - CIRCLE (radius > 0)
    - ARC
    - ELLIPSE
    - SPLINE
    - LWPOLYLINE
    - POLYLINE
    - HATCH
    - SOLID
    - TRACE

Returns ``False`` for all other DXF entities.
F entitys    A/var/www/html/env/lib/python3.13/site-packages/ezdxf/edgesmith.pyr%   r%   E   s    $     c                   [        U R                  R                  5      nU R                  R                  nU R                  R                  n[        X#5      n[        U5      [        :  =(       a    [        R                  " US[        S9$ )Ng     v@abs_tol)	absdxfradiusstart_angle	end_angler   LEN_TOLmathisclose)r1   r9   r:   r;   
angle_spans        r2   _is_closed_arcr@   Z   s_    ""#F**((K

$$I#K;Jv; UT\\*eW%UUr3   c                N    [        U R                  R                  5      [        :  $ N)r7   r8   r9   r<   r0   s    r2   _is_closed_circlerC   c   s    vzz  !G++r3   c                    U R                   R                  nU R                   R                  n[        X5      n[        R
                  " U[        R                  [        S9(       d  gg)Nr5   FT)r8   start_param	end_paramr   r=   r>   tauRAD_TOL)r1   rE   rF   spans       r2   _is_closed_ellipserJ   h   sD    **((K

$$Ik5D<<dhh8r3   c                     U R                  5       nUR                  n[        U5      S:  a  gUS   nUS   nUR	                  U[
        S9$ ! [         a     gf = f)NF   r   r5   )construction_tool
ValueErrorcontrol_pointslenr>   r<   )r1   bsplinerP   startends        r2   _is_closed_splinerU   r   sm    **, ++N
>Q1E

C==g=..  s   A 
AAc                    [        U 5      S:  a  gU R                  SL a  g[        U R                  S   S S 5      n[        U R                  S   S S 5      nUR	                  U[
        S9$ )N   FTr      rM   r5   )rQ   closedr   lwpointsr>   r<   )r1   rS   rT   s      r2   _is_closed_lwpolyliner[      sf    
6{Q}}#BQ'(E
vr"2A&
'C==g=..r3   c                <   U R                   (       d  U R                  (       az  U R                  n[        U5      S:  a  gU R                  (       a  gUS   R
                  R                  nUS   R
                  R                  nUR                  U[        S9(       a  gg)NrX   FTr   rM   r5   )	is_2d_polylineis_3d_polylineverticesrQ   	is_closedr8   locationr>   r<   )r1   r_   p0p1s       r2   _is_closed_polyline2drd      sw     5 5 ??x=1A;??++B<##,,::b':*r3   c                >    [        [        U R                  5      5      $ rB   )boolrQ   pathsr0   s    r2   _is_closed_hatchrh      s    FLL!""r3   c                    g)NTr/   r0   s    r2   _is_closed_solidrj      s     r3   c                    g)a]  Returns ``True`` if the given entity represents a pure 2D entity in the
xy-plane of the WCS.

- All vertices must be in the xy-plane of the WCS.
- Thickness must be 0.
- The extrusion vector must be (0, 0, 1).
- Entities with inverted extrusions vectors (0, 0, -1) are **not** pure 2D entities.
  The ezdxf.upright module can be used to revert inverted extrusion vectors
  back to (0, 0, 1).

Tests the following DXF entities:

    - LINE
    - CIRCLE
    - ARC
    - ELLIPSE
    - SPLINE
    - LWPOLYLINE
    - POLYLINE
    - HATCH
    - SOLID
    - TRACE

Returns ``False`` for all other DXF entities.

Fr/   r0   s    r2   r'   r'      s    8 r3   c                   [         R                  " U R                  R                  5      (       d  g[	        U R                  R
                  5      [        :  a  g[	        [        U R                  R                  5      R                  5      [        :  a  g[	        [        U R                  R                  5      R                  5      [        :  a  ggNFT)r   r>   r8   	extrusionr7   	thicknessr<   r   rS   zrT   r0   s    r2   _is_pure_2d_entityrq      s    >>&**..//
6:: 7*
4

  !##$w.
4

!!"W,r3   c                z   [         R                  " U R                  R                  5      (       d  g[	        [        U R                  R                  5      R                  5      [        :  a  g[	        U R                  R                  5      [        :  a  g[	        U R                  R                  5      [        :  a  ggrm   )r   r>   r8   rn   r7   r   centerrp   r<   	elevationro   r0   s    r2   _is_pure_2d_arcru      s|     >>&**..//
4

!!"$$%/
6:: 7*
6:: 7*r3   c                    [         R                  " U R                  R                  5      (       d  g[	        [        U R                  R                  5      R                  5      [        :  a  ggrm   )	r   r>   r8   rn   r7   r   rs   rp   r<   r0   s    r2   _is_pure_2d_ellipserw      sF    >>&**..//
4

!!"$$%/r3   c                    [         R                  " U R                  R                  5      (       d  g U R	                  5       n[        S UR                   5       5      (       a  gg! [
         a     gf = f)NFc              3  Z   #    U  H!  n[        UR                  5      [        :  v   M#     g 7frB   r7   rp   r<   .0vs     r2   	<genexpr>%_is_pure_2d_spline.<locals>.<genexpr>   s     
9'8!3qss8g'8   )+T)r   r>   r8   rn   rN   rO   anyrP   )r1   cts     r2   _is_pure_2d_spliner      sd    >>&**..//%%' 
9r'8'8
999	  s   A% %
A21A2c                   [         R                  " U R                  R                  5      (       d  g[	        U R                  R
                  5      [        :  a  g[	        U R                  R                  5      [        :  a  ggrm   )r   r>   r8   rn   r7   rt   r<   ro   r0   s    r2   _is_pure_2d_lwpolyliner      sU    >>&**..//
6:: 7*
6:: 7*r3   c                    U R                   (       d  U R                  (       a  g[        S U R                  5        5       5      (       a  g[	        U R
                  R                  5      [        :  a  gg)NFc              3  Z   #    U  H!  n[        UR                  5      [        :  v   M#     g 7frB   rz   r{   s     r2   r~   '_is_pure_2d_polyline.<locals>.<genexpr>  s     
>'=!3qss8g'=r   T)is_polygon_meshis_poly_face_meshr   points_in_wcsr7   r8   ro   r<   r0   s    r2   _is_pure_2d_polyliner     sP    !9!9

>v';';'=
>>>
6:: 7*r3   c                    [         R                  " U R                  R                  5      (       d  g[	        [        U R                  R                  5      R                  5      [        :  a  ggrm   )	r   r>   r8   rn   r7   r   rt   rp   r<   r0   s    r2   _is_pure_2d_hatchr     sF    >>&**..//
4

$$%''(72r3   c                P   [         R                  " U R                  R                  5      (       d  g[	        U R                  R
                  5      [        :  a  g[	        U R                  R                  5      [        :  a  g[        S U R                  5        5       5      (       a  gg)NFc              3  Z   #    U  H!  n[        UR                  5      [        :  v   M#     g 7frB   rz   r{   s     r2   r~   $_is_pure_2d_solid.<locals>.<genexpr>   s     
='<!3qss8g'<r   T)
r   r>   r8   rn   r7   rt   r<   ro   r   wcs_verticesr0   s    r2   _is_pure_2d_solidr     st     >>&**..//
6:: 7*
6:: 7*

=v':':'<
===r3   c                    S U  5       $ )a  Returns all entities that can be used to build edges in the context of
:mod:`ezdxf.edgeminer`.

Returns the following DXF entities:

    - LINE
    - ARC
    - ELLIPSE
    - SPLINE
    - LWPOLYLINE
    - POLYLINE

.. note::

    - CIRCLE, TRACE and SOLID are closed shapes by definition and cannot be used as
      edge in the context of :mod:`ezdxf.edgeminer` or :mod:`ezdxf.edgesmith`.
    - This filter is not limited to pure 2D entities!
    - Does not test if the entity is a closed loop!

c           
   3     #    U  Ht  n[        U[        R                  [        R                  [        R                  [        R
                  [        R                  [        R                  45      (       d  Mp  Uv   Mv     g 7frB   )
isinstanceetLineArcEllipseSpline
LWPolylinePolyline)r|   r1   s     r2   r~   'filter_edge_entities.<locals>.<genexpr>:  sS      F

		

 	s   A/A>5	A>r/   r   s    r2   r"   r"   %  s    * r3   c                    S U  5       $ )zReturns all pure 2D entities, ignores all entities placed outside or extending
beyond the xy-plane of the :ref:`WCS`. See :func:`is_pure_2d_entity` for more
information.

c              3  J   #    U  H  n[        U5      (       a  M  Uv   M     g 7frB   )r'   r|   es     r2   r~   %filter_2d_entities.<locals>.<genexpr>Q  s     <x!'8';AAx   #	#r/   r   s    r2   r!   r!   K  s     =x<<r3   c                *    [        U 5      nS U 5       $ )a9  Returns all open linear entities usable as edges in the context of
:mod:`ezdxf.edgeminer` or :mod:`ezdxf.edgesmith`.

Ignores all entities that represent closed loops like circles, closed arcs, closed
ellipses, closed splines and closed polylines.

.. note::

    This filter is not limited to pure 2D entities!

c              3  J   #    U  H  n[        U5      (       a  M  Uv   M     g 7frB   )r%   r   s     r2   r~   $filter_open_edges.<locals>.<genexpr>a  s     8u!$4Q$7AAur   )r"   )r   edgess     r2   r#   r#   T  s     !*E8u88r3   c                |    U R                   R                  U R                  5      U:  a  g U R                  U:  a  g U $ rB   )rS   distancerT   length)edgegap_tols     r2   _validate_edger   d  s4    zz488$w.{{WKr3   r   c                   g)a  Makes an Edge instance from the following DXF entity types:

    - LINE (length accurate)
    - ARC (length accurate)
    - ELLIPSE (length approximated)
    - SPLINE (length approximated as straight lines between control points)
    - LWPOLYLINE (length of bulges as straight line from start- to end point)
    - POLYLINE (length of bulges as straight line from start- to end point)

The start- and end points of the edge is projected onto the xy-plane. Returns
``None`` if the entity has a closed shape or cannot be represented as an edge.
Nr/   )r1   r   s     r2   r*   r*   m  s     r3   c          	         [        U R                  R                  5      n[        U R                  R                  5      nUR	                  U5      n[        [        R                  " X#X@S9U5      $ )Npayload)r   r8   rS   rT   r   r   em	make_edge)r1   r   rS   rT   r   s        r2   _edge_from_liner   ~  sP     !!"E
vzz~~
C^^C F",,u6JGTTr3   c          	        [        U R                  R                  5      nU[        :  a  g U R                  R                  nU R                  R
                  n[        X45      nX%-  S-  [        R                  -  nU R                  X445      u  px[        [        R                  " [        U5      [        U5      X`S9U5      $ )Ng     f@r   )r7   r8   r9   r<   r:   r;   r   r=   pir_   r   r   r   r   )	r1   r   r9   r:   r;   span_degr   speps	            r2   _edge_from_arcr     s    ""#F**((K

$$I!+9H&0F__k56FB
T"XtBx@ r3   c          	         U R                  5       nUR                  R                  [        :  d  UR
                  R                  [        :  a  g [        UR                  UR                  5      n[        S[        US-  5      5      n[        R                  " UR                  UR                  U5      5      5      n[        S [!        XUSS  5       5       5      n[#        [$        R&                  " US   US   X`S9U5      $ ! [         a     g f = f)NrL   gtV?c              3  H   #    U  H  u  pUR                  U5      v   M     g 7frB   r   r|   abs      r2   r~   %_edge_from_ellipse.<locals>.<genexpr>       C+B41A+B    "rW   r   rM   r   )rN   rO   
major_axis	magnituder<   
minor_axisr   rE   rF   maxroundr   listr_   paramssumzipr   r   r   )r1   r   ct1rI   numpointsr   s          r2   _edge_from_ellipser     s    &&( ~~')S^^-E-E-Ocoos}}=D
atf}%
&C YYs||CJJsO45FC3vabz+BCCF
VAYr
FCW   s   C? ?
DDc          	     ^    U R                  5       n[        UR                  S   5      n[        UR                  S   5      n[        R                  " UR                  5      n[        S [        XUSS  5       5       5      n[        [        R                  " X4X`S9U5      $ ! [         a     g f = f)Nr   rM   c              3  H   #    U  H  u  pUR                  U5      v   M     g 7frB   r   r   s      r2   r~   $_edge_from_spline.<locals>.<genexpr>  r   r   rW   r   )
rN   rO   r   rP   r   r   r   r   r   r   )r1   r   ct2rS   rT   r   r   s          r2   _edge_from_spliner     s    &&( ##A&'E
s!!"%
&CYYs))*FC3vabz+BCCF",,u6JGTT  s   B 
B,+B,c          	        [        U 5      (       a  g [        R                  " U R                  5       5      n[	        U5      S:  a  g US   nUS   n[        S [        X"SS  5       5       5      n[        [        R                  " X4XPS9U5      $ )NrX   r   rM   c              3  H   #    U  H  u  pUR                  U5      v   M     g 7frB   r   r   s      r2   r~   (_edge_from_lwpolyline.<locals>.<genexpr>  r   r   rW   r   )
r[   r   r   vertices_in_wcsrQ   r   r   r   r   r   r1   r   r   rS   rT   r   s         r2   _edge_from_lwpolyliner     sz    V$$YYv--/0F
6{Q1IE
*CC3vabz+BCCF",,u6JGTTr3   c          	     `   U R                   (       d  U R                  (       d  g [        U 5      (       a  g [        R                  " U R                  5       5      n[        U5      S:  a  g US   nUS   n[        S [        X"SS  5       5       5      n[        [        R                  " X4XPS9U5      $ )NrX   r   rM   c              3  H   #    U  H  u  pUR                  U5      v   M     g 7frB   r   r   s      r2   r~   &_edge_from_polyline.<locals>.<genexpr>  r   r   rW   r   )r]   r^   rd   r   r   r   rQ   r   r   r   r   r   r   s         r2   _edge_from_polyliner     s    !!V%:%:V$$YYv++-.F
6{Q1IE
*CC3vabz+BCCF",,u6JGTTr3   c             #  B   #    U  H  n[        X!S9nUc  M  Uv   M     g7f)zYields all DXF entities as 2D edges in the xy-plane of the :ref:`WCS`.

Skips all entities that have a closed shape or can not be represented as edge.
r   N)r*   )r   r   r1   r   s       r2   r    r      s&      F4J s   	c                  U (       d
  [        5       $ U S   R                  /nU  Ha  n[        R                  " US   UR                  US9(       d  UR	                  UR                  5        UR	                  UR
                  5        Mc     U$ )zReturns all vertices from a sequence of connected edges.

Adds line segments between edges when the gap is bigger than `gap_tol`.
r   rM   r   )tuplerS   r   r>   appendrT   )r   r   r_   r   s       r2   r   r     sg    
 w!!HNN+Hzz(2,

GDOODJJ'!  Or3   rM   )
dxfattribsmax_sagittac                   [         R                  R                  US9n[        U 5      S:X  a  U$ UR	                  [        X5      SS9  U$ )aX  Returns a new virtual :class:`~ezdxf.entities.LWPolyline` entity.

This function assumes the building blocks as simple DXF entities attached as payload
to the edges. The edges are processed in order of the input sequence and the start-
and end points of the edges should be connected. The output polyline is projected
onto the xy-plane of the :ref:`WCS`.

    - :class:`~ezdxf.entities.Line` as line segment
    - :class:`~ezdxf.entities.Arc` as bulge
    - :class:`~ezdxf.entities.Ellipse` as bulge or as flattened line segments
    - :class:`~ezdxf.entities.Spline` as flattened line segments
    - :class:`~ezdxf.entities.LWPolyline` and :class:`~ezdxf.entities.Polyline`
      will be merged
    - Everything else will be added as line segment from :attr:`Edge.start` to
      :attr:`Edge.end`
    - Gaps between edges are connected by line segments.

r   r   vbformat)r   r   newrQ   
set_points_make_polyline_pointsr   r   r   polylines       r2   r)   r)     sI    0 }}  J 7H
5zQ-eA$OOr3   c                   [         R                  R                  US9n[        U 5      S:X  a  U$ UR	                  [        X5      SS9  U$ )aF  Returns a new virtual :class:`Polyline` entity.

This function assumes the building blocks as simple DXF entities attached as payload
to the edges. The edges are processed in order of the input sequence and the start-
and end points of the edges should be connected. The output polyline is projected
onto the xy-plane of the :ref:`WCS`.

    - :class:`~ezdxf.entities.Line` as line segment
    - :class:`~ezdxf.entities.Arc` as bulge
    - :class:`~ezdxf.entities.Ellipse` as bulge or as flattened line segments
    - :class:`~ezdxf.entities.Spline` as flattened line segments
    - :class:`~ezdxf.entities.LWPolyline` and :class:`~ezdxf.entities.Polyline`
      will be merged
    - Everything else will be added as line segment from :attr:`Edge.start` to
      :attr:`Edge.end`
    - Gaps between edges are connected by line segments.

r   r   r   r   )r   r   r   rQ   append_formatted_verticesr   r   s       r2   r,   r,     sL    * {{*5H
5zQ&&e1$ '  Or3   r	   BulgePointsc                    U S:  a  US-  n U $ Nr   g      Y@r/   )r   r   s     r2   _adjust_max_sagittar   7  s    Qunr3   c                *   / n [         R                  " U 5      n[        X!5      nU[        :  a;  UR                  S [        R                  " UR                  U5      5       5       5        U(       a  UR                  5         U$ ! [         a    Us $ f = f)Nc              3  (   #    U  H  oS 4v   M
     g7f        Nr/   r|   ps     r2   r~   %_flatten_3d_entity.<locals>.<genexpr>G  s     W(V1#h(Vs   )
r   	make_path	TypeErrorr   r<   extendr   r   
flatteningreverse)r1   r   r   
is_reverser   entity_paths         r2   _flatten_3d_entityr  =  s     FnnV, &k:KWW		+2H2H2U(VWW 	M  s   B BBc                   U R                   n[        R                  " UR                  R                  5      (       a  [        UR                  R                  UR                  R                  5      nSnU[        :  a3  [        [        R                  " U5      5      nU R                  (       a  U* n[        U R                  5      U4[        U R                  5      S4/$ [!        X R"                  XR                  5      $ )Nr   )r   r   r>   r8   rn   r   r:   r;   DEG_TOLr   r=   radiansr  r   rS   rT   r  r   )r   r   arcrI   bulges        r2   _arc_to_bulge_pointsr  O  s    ,,C~~cgg''((!#''"5"5sww7H7HI'>(d);<E$**u%$((^S!
 	

 c;;__MMr3   c                H   U R                   n[        UR                  R                  5      n[	        UR                  R
                  UR                  R                  5      n[        R                  " US5      (       a  [        R                  " UR                  R                  5      (       aY  SnU[        :  a  [        U5      nU R                  (       a  U* n[        U R                  5      U4[        U R                   5      S4/$ [#        X R$                  XR                  5      $ )N      ?r   )r   r7   r8   ratior   rE   rF   r=   r>   r   rn   rH   r   r  r   rS   rT   r  r   )r   r   ellipser  rI   r  s         r2   _ellipse_to_bulge_pointsr  `  s    ,,G!!"Egkk55w{{7L7LMD||E3FNN7;;3H3H$I$I'>(.E$**u%$((^S!
 	

 g{{KQQr3   c           	     ^    [        U 5      S:  a  g[        S [        X SS  5       5       5      $ )NrX   r   c              3  H   #    U  H  u  pUR                  U5      v   M     g 7frB   r   )r|   rb   rc   s      r2   r~   !_sum_distances.<locals>.<genexpr>u  s     I-H62r{{2-Hr   rW   )rQ   r   r   )r_   s    r2   _sum_distancesr  r  s-    
8}qISAB<-HIIIr3   c                .    U S:  a  U $ [        U5      S-  $ r   )r  )r   rP   s     r2   _max_sagitta_spliner  x  s    Q.)E11r3   c                6   U R                   n/ n UR                  5       n[        XR                  5      nU[
        :  a'  UR                  S UR                  U5       5       5        U R                  (       a  UR                  5         U$ ! [         a    Us $ f = f)Nc              3  <   #    U  H  n[        U5      S 4v   M     g7fr   )r   r   s     r2   r~   *_spline_to_bulge_points.<locals>.<genexpr>  s     I.HtAwn.Hs   )
r   rN   rO   r  rP   r<   r  r  r  r  )r   r   spliner   r   s        r2   _spline_to_bulge_pointsr  ~  s    FF%%' &k3D3DEKWIbmmK.HII 	M  s   B	 	BBc           	     d   U R                   n[        R                  " UR                  R                  5      (       aO  UR                  SS9 VVVs/ s H  u  p4n[        X45      U4PM     nnnnU R                  (       a  [        U5      $ U$ [        X R                  XR                  5      $ s  snnnf )Nxybr   )r   r   r>   r8   rn   
get_pointsr   r  _revert_bulge_pointsr  r   )r   r   plxyr   r   s          r2   _lwpolyline_to_bulge_pointsr$    s    B~~bff&&''13e1LM1LgaA4:q/1LM??'//b++{OOLL	 Ns   B+c                   U R                   nUR                  (       a  [        R                  " UR                  R
                  5      (       am  UR                   Vs/ s H8  n[        UR                  R                  5      UR                  R                  4PM:     nnU R                  (       a  [        U5      $ U$ [        X R                  XR                  5      $ s  snf rB   )r   r]   r   r>   r8   rn   r_   r   ra   r  r  r   r  r   )r   r   r!  r}   r   s        r2   _polyline2d_to_bulge_pointsr&    s    llB	V^^BFF,<,<==?A{{K{!4'5{K??'//b++{OOLL	 Ls   ?Cc                   [        U 5      S:  a  U $ U R                  5         U  Vs/ s H  oS   PM	     nn[        U5      (       a>  UR                  S5      nUR	                  U5        [        [        S U  5       U5      5      $ U $ s  snf )NrX   rW   r   c              3  *   #    U  H	  oS    v   M     g7f)r   Nr/   )r|   pnts     r2   r~   '_revert_bulge_points.<locals>.<genexpr>  s     /3CQ3s   )rQ   r  r   popr   r   r   )ptsr)  bulgesfirsts       r2   r   r     su    
3x!|
KKM #$!fF$
6{{

1eC/3/899J %s   Bc                    [        U5      S:  a  U $  U S   u  p#US   u  pCUR                  U5      [        :  a  U R                  5         U R                  U5        U $ ! [         a    U R                  U5        U s $ f = f)NrX   rM   r   )rQ   
IndexErrorr  r   r<   r+  )r   	extensioncurrent_end_connection_points        r2   _extend_bulge_pointsr5    s    
9~
 $A,,-7


MM)M  i s   A A=<A=c                >   / n/ nU  H  nUR                  5         [        R                  [        UR                  5      5      nU(       a  U" XA5      n[        U5      S:  a.  [        UR                  5      S4[        UR                  5      S4/n[        X#5      nM     U$ )zKReturns the polyline points to create a LWPolyline or a 2D Polyline entity.rX   r   )
clearPOLYLINE_CONVERTERSgettyper   rQ   r   rS   rT   r5  )r   r   r   r1  r   	converters         r2   r   r     s    FI'++D,>?	!$4Iy>Adjj!3'dhh%I &f8  Mr3   TrW   )r   r`   flagsc          	     F   [         R                  " 5       n[        U5      Ul        U=R                  U-  sl        [        U 5      S:X  a  U$ [        X5      nUR                  U VVs/ s H  u  pgUR                  UR                  U4PM      snn5        SUl        U$ s  snnf )a  Returns a new :class:`~ezdxf.entities.PolylinePath` for :class:`~ezdxf.entities.Hatch`
entities.

This function assumes the building blocks as simple DXF entities attached as payload
to the edges. The edges are processed in order of the input sequence and the start-
and end points of the edges should be connected. The output path is projected onto
the xy-plane of the :ref:`WCS`.

    - :class:`~ezdxf.entities.Line` as line segment
    - :class:`~ezdxf.entities.Arc` as bulge
    - :class:`~ezdxf.entities.Ellipse` as bulge or flattened line segments
    - :class:`~ezdxf.entities.Spline` as flattened line segments
    - :class:`~ezdxf.entities.LWPolyline` and :class:`~ezdxf.entities.Polyline` are
      merged
    - Everything else will be added as line segment from :attr:`Edge.start` to
      :attr:`Edge.end`
    - Gaps between edges are connected by line segments.

Args:
    edges: Sequence of :class:`~ezdxf.edgeminer.Edge` instances with DXF primitives
        attached as payload
    max_sagitta (float): curve flattening parameter
    is_closed (bool): ``True`` if path is implicit closed
    flags (int): default(0), external(1), derived(4), textbox(8) or outermost(16)

r   T)
bpPolylinePathrf   r`   path_type_flagsrQ   r   set_verticesr"  r#  )r   r   r`   r<  polyline_pathbulge_pointsr   r   s           r2   r-   r-     s    : OO%M"9oM!!U*!
5zQ(<L,G,$!acc1,GH"M  Hs   '%B
)r   r<  c               &   [         R                  " 5       nU=R                  U-  sl        [        U 5      S:X  a  U$ U  GH  nUR                  n[        XR                  5      nUR                  n[        U[        R                  5      (       a  [        X5U5        M^  [        U[        R                  5      (       a  [        X5Xv5        M  [        U[        R                  5      (       a  [        X5Xv5        M  [        U[        R                   5      (       a  [#        X5U5        M  [        U[        R$                  5      (       aI  UR&                  (       d  UR(                  (       a'  [+        U[-        UR/                  5       5      Xq5        GMM  [        U[        R0                  5      (       a'  [+        U[-        UR/                  5       5      Xq5        GM  UR3                  UR4                  UR6                  5        GM     UR9                  [:        5        U$ )a  Returns a new :class:`~ezdxf.entities.EdgePath` for :class:`~ezdxf.entities.Hatch`
entities.

This function assumes the building blocks as simple DXF entities attached as payload
to the edges. The edges are processed in order of the input sequence and the start-
and end points of the edges should be connected. The output path is projected onto
the xy-plane of the :ref:`WCS`.

    - :class:`~ezdxf.entities.Line` as :class:`~ezdxf.entities.LineEdge`
    - :class:`~ezdxf.entities.Arc` as :class:`~ezdxf.entities.ArcEdge`
    - :class:`~ezdxf.entities.Ellipse` as :class:`~ezdxf.entities.EllipseEdge`
    - :class:`~ezdxf.entities.Spline` as :class:`~ezdxf.entities.SplineEdge`
    - :class:`~ezdxf.entities.LWPolyline` and :class:`~ezdxf.entities.Polyline` will
      be exploded and added as :class:`~ezdxf.entities.LineEdge` and
      :class:`~ezdxf.entities.ArcEdge`
    - Everything else will be added as line segment from :attr:`Edge.start` to
      :attr:`Edge.end`
    - Gaps between edges are connected by line segments.

Args:
    edges: Sequence of :class:`~ezdxf.edgeminer.Edge` instances with DXF primitives
        attached as payload
    max_sagitta (float): curve flattening parameter
    flags (int): default(0), external(1), derived(4), textbox(8) or outermost(16)

r   )r>  EdgePathr@  rQ   r   r   r   r  r   r   r   _add_line_to_edge_path_2dr   _add_arc_to_edge_path_2dr   _add_ellipse_to_edge_path_2dr   _add_spline_to_edge_path_2dr   r]   r^    _add_polyline_parts_to_edge_pathr   virtual_entitiesr   add_linerS   rT   
close_gapsr<   )r   r   r<  	edge_pathr   r1   r   r  s           r2   r   r     sf   : I&
5zQ&{KK@//fbgg&&%iA''$YJ

++(GN		**'	7C,,!!V%:%:,4 7 7 9:G ..,4 7 7 9:G tzz4884/ 0 !r3   c                    [        UR                  R                  5      n[        UR                  R                  5      nU(       a  XCpCU R	                  X45        g rB   )r   r8   rS   rT   rL  )rN  liner  rS   rT   s        r2   rF  rF  C  s>      E
txx||
Csu"r3   c                   [         R                  " UR                  R                  5      (       ar  U R	                  [        UR                  R                  5      UR                  R                  UR                  R                  UR                  R                  U(       + S9  g [
        R                  " UR                  U5      5      nU(       a  UR                  5         [        X5        g )N)rs   r9   r:   r;   ccw)r   r>   r8   rn   add_arcr   rs   r9   r:   r;   r   r  r  _add_vertices_to_edge_path_2d)rN  r
  r  r   r_   s        r2   rG  rG  M  s     ~~cgg''(('77>>++gg'' 	 	
 99S^^K89%i:r3   c           	     >   [         R                  " UR                  R                  5      (       a   UR	                  5       nU R                  [        UR                  5      [        UR                  5      UR                  [        R                  " UR                  5      [        R                  " UR                  5      U(       + S9  g [        R                  " UR!                  U5      5      nU(       a  UR#                  5         [%        X5        g ! [
         a     g f = f)N)rs   r   r  r:   r;   rR  )r   r>   r8   rn   rN   rO   add_ellipser   rs   r   r  r=   degreesrE   rF   r   r  r  rT  )rN  r  r  r   r   r_   s         r2   rH  rH  _  s     ~~gkk++,,	**,B 			?BMM*((R^^4ll2<<0 	 	
 99W//<=%i:  		s   D 
DDc                    UR                  5       n[        R                  " UR                  5      n[        UR                  5       5      n[        UR                  5       5      nU(       a0  UR                  5         UR                  5         UR                  5         U R                  UUU(       a  UOS UR                  S9  g ! [         a     g f = f)N)rP   knot_valuesweightsdegree)
rN   rO   r   r   rP   knotsrZ  r  
add_spliner[  )rN  r  r  r   rP   r\  rZ  s          r2   rI  rI  v  s    %%' YYr001NE2::< G %"yy	    s   C 
CCc                T    [        XSS  5       H  u  p#U R                  X#5        M     g )NrW   )r   rL  )rN  r_   rS   rT   s       r2   rT  rT    s'    (QRL1
5& 2r3   c                   [        U5        [        [        U5      5      n[        [        R                  " U5      5      nU(       a  [        R
                  " U5      nU H  nUR                  n[        U[        R                  5      (       a  [        XUR                  5        MF  [        U[        R                  5      (       d  Mg  [        X5R                  5      n[        XUR                  U5        M     g rB   )r   r   r    r   find_sequential_chainreverse_chainr   r   r   r   rF  r  r   r   r   rG  )rN  r   r  r   r   r   r1   r   s           r2   rJ  rJ    s      '12E))%01E  'fbgg&&%iI''*;DH$YR r3   c                   [         R                  " 5       n[        U 5      S:X  a  U$ [        R                  " SSS5      nU  Hg  n [         R
                  " UR                  5      nUR                  U5      nUR                  (       a  UR                  5       nUR                  U5        Mi     U$ ! [        [        4 a     M  f = f)uZ  Returns a new :class:`ezdxf.path.Path` entity.

This function assumes the building blocks as simple DXF entities attached as payload
to the edges. The edges are processed in order of the input sequence and the start-
and end points of the edges should be connected. The output is a 2D path projected
onto the xy-plane of the :ref:`WCS`.

    - :class:`~ezdxf.entities.Line` as line segment
    - :class:`~ezdxf.entities.Arc` as cubic Bézier curves
    - :class:`~ezdxf.entities.Ellipse` as cubic Bézier curves
    - :class:`~ezdxf.entities.Spine` cubic Bézier curves
    - :class:`~ezdxf.entities.LWPolyline` and :class:`~ezdxf.entities.Polyline`
      as line segments and cubic Bézier curves
    - Everything else will be added as line segment from :attr:`Edge.start` to
      :attr:`Edge.end`
    - Gaps between edges are connected by line segments.

r   r  r   )r   PathrQ   r   scaler   r   rO   r   	transformr  reversedappend_path)r   	main_pathmr   sub_paths        r2   r+   r+     s    & 		I
5zQ 	sC%A	~~dll3H %%a(??((*Hh'   I& 		s    B..CCc                  *    \ rS rSr% S\S'   S\S'   Srg)IntersectingEdgei  em.Edger   floatr   r/   N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r/   r3   r2   rl  rl    s    
MOr3   rl  c                Z    [        S U  5       5      nUR                  S U  5       5        U$ )zNReturns the :class:`~ezdxf.math.BoundingBox2d` of all start- and end vertices.c              3  8   #    U  H  oR                   v   M     g 7frB   rS   r   s     r2   r~   "bounding_box_2d.<locals>.<genexpr>  s     0%Q%   c              3  8   #    U  H  oR                   v   M     g 7frB   )rT   r   s     r2   r~   rx    s     %u!ury  )r   r  )r   bboxs     r2   r   r     s)    0%00DKK%u%%Kr3   c           	        / n[        U 5      S:X  a  U$ [        U5      nUc9  [        U 5      n[        UR                  R                  S-   UR
                  5      nO[        U5      nXF4nU  Hg  n[        UR                  5      n	[        UR                  5      n
[        XyU
4SS9nUc  M>  UR                  [        XR                  U5      5      5        Mi     UR                  [        S5      S9  U$ )a  Returns all edges that intersect a line from point `p1` to point `p2`.

If `p2` is ``None`` an arbitrary point outside the bounding box of all start- and
end vertices beyond extmax.x will be chosen.
The edges are handled as straight lines from start- to end vertex, projected onto
the xy-plane of the :ref:`WCS`. The result is sorted by the distance from
intersection point to point `p1`.
r   r  F)virtualrW   )key)rQ   r   r   extmaxr"  r#  rS   rT   r   r   rl  r   sortr
   )r   rc   p2intersectionsinner_pointr{  outer_point	test_liner   rS   rT   ips               r2   r$   r$     s     -/M
5zQr(K	zu%4;;==3.>2h*ITZZ 488n&y#,N>  !1$8L8LR8P!QR  :a=)r3   c                   [         R                  " XS9(       d  [        S5      e[        R                  " S U  5       5      n[        [        U5      U5      S:  $ )a  Returns ``True`` when `point` is inside the polygon.

The edges must be a closed loop. The polygon is build from edges as straight lines
from start- to end vertex, independently whatever the edges really represent.
A point at a boundary line is inside the polygon.

Args:
    edges: sequence of :class:`~ezdxf.edgeminer.Edge` representing a closed loop
    point: point to test
    gap_tol: maximum vertex distance to consider two edges as connected

Raises:
    ValueError: edges are not a closed loop

r   edges are not a closed loopc              3  8   #    U  H  oR                   v   M     g 7frB   rw  r   s     r2   r~   'is_inside_polygon_2d.<locals>.<genexpr>  s     /Ary  r   )r   is_looprO   r   r   r   )r   pointr   polygons       r2   r&   r&     sF    $ ::e-677ii///G!$u+w73>>r3   c               n    [         R                  " XS9(       d  [        S5      e[        S U  5       5      $ )zYReturns the area of a closed loop.

Raises:
    ValueError: edges are not a closed loop

r   r  c              3  8   #    U  H  oR                   v   M     g 7frB   rw  r   s     r2   r~   loop_area.<locals>.<genexpr>  s     'Ary  )r   r  rO   r   )r   r   s     r2   r(   r(     s-     ::e-677''''r3   )r1   et.DXFEntityreturnrf   )r1   et.Arcr  rf   )r1   z	et.Circler  rf   )r1   
et.Ellipser  rf   )r1   	et.Spliner  rf   )r1   et.LWPolyliner  rf   )r1   et.Polyliner  rf   )r1   zet.Hatchr  rf   )r1   zet.Solid | et.Tracer  rf   )r1   et.Liner  rf   )r1   zet.Circle | et.Arcr  rf   )r   Iterable[et.DXFEntity]r  zIterator[et.DXFEntity])r   rm  r   rn  r  em.Edge | None)r1   r  r  r  )r1   r  r  r  )r1   r  r  r  )r1   r  r  r  )r1   r  r  r  )r1   r  r  r  )r1   r  r  r  )r   r  r  zIterator[em.Edge])r   Sequence[em.Edge]r  Sequence[Vec3])r   r  r   r   r   rn  r  r  )r   r  r   r   r   rn  r  r  )r   rn  r   rn  r  rn  )r   rn  r   rn  r  rf   r  r   )r   rm  r   rn  r  r   )r_   r  r  rn  )r   rn  rP   r  )r,  r   r  r   )r   r   r1  r   r  r   )r   r  r   rn  r  r   )r   r  r   rn  r<  intr  zbp.PolylinePath)r   r  r   rn  r<  r  r  bp.EdgePath)rN  r  rP  r  r  rf   r  None)
rN  r  r
  r  r  rf   r   rn  r  r  )
rN  r  r  r  r  rf   r   rn  r  r  )rN  r  r  r  r  rf   r  r  )rN  r  r_   z
list[Vec2]r  r  )
rN  r  r   zlist[et.DXFGraphic]r  rf   r   rn  r  r  )r   r  r  z	path.Path)r   r  r  r   rB   )r   r  rc   r   r  zUVec | Noner  zlist[IntersectingEdge])r   r  r  r   r  rf   )r   r  r  rn  )y__doc__
__future__r   typingr   r   r   r   r   typing_extensionsr	   r=   	functoolsoperatorr
   ezdxfr   r   r   r   r   ezdxf.entitiesr   r>  ezdxf.uprightr   
ezdxf.mathr   r   r   r   r   r   r   r   r   r   r   r   __all__r<   r  rH   GAP_TOLsingledispatchr%   registerr   r@   CirclerC   r   rJ   r   rU   r   r[   r   rd   Hatchrh   TraceSolidrj   r'   r   rq   ru   rw   r   r   r   r   r   r"   r!   r#   r   r*   r   r   r   r   r   r   r    r   r)   r,   r   r   rn  r   rs  r   r  r  r  r  r  r  r$  r&  r   r5  r8  r   r-   r   rF  rG  rH  rI  rT  rJ  r+   rl  r   r$   r&   r(   r/   r3   r2   <module>r     s   # @ @ '    !    / %   * 


**  ( 266"V #V 299%, &, 2::& ' 299%
/ &
/ 2==)/ */ 2;;' (  288$# %# 288$288$ % %
  < BGG$	 %	 BII&BFF#	 $ '	 BJJ' ( BII&	 '	 BMM* + BKK( ) BHH% & BHH%BHH%	 & &	#L=9  29    rww07 U  U rvv.5    rzz"6=  #$ ryy!4; U "U r}}%<C U &U r{{#8? U $U$ 29
$

 9@ $ 	  	
 @ 48b-0FK< eD%K01Y 1(-;?$N"R$J2$MM
" FF JJ(II&MM.KK, & 79DWX%%.3%QT%%R 79q;;.3;AD;;|##")#48#	#;;!';26;EJ;	;$;;%/;:>;MR;	;.$-8<	.'
SS!S S 	S
 
S0"Jz 
 ;?"&,7D 7>??%)?	?2 4; 	( 	(r3   