
    'j}v                       U d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlZd dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dl m!Z! d dl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d d	l;m<Z< d
dl=m>Z> d
dl?m@Z@ d
dlAmBZB d
dlCmDZD g dZEdZFdZGdZH e
de%e2          ZIee3e>eJgdf         ZK ejL        d          ZMeddd            ZNeNO                    e#          dd            ZPeNO                    e$          dd             ZQeNO                    e0          eNO                    e'          dd#                        ZReNO                    e(          dd&            ZSeNO                    e&          dd)            ZTeNO                    e)          dd,            ZUeNO                    e*          dd/            ZVeNO                    e-          eNO                    e,          eNO                    e+          dd2                                    ZWeNO                    e.          dd5            ZXeNO                    e1          eNO                    e/          dd8                        ZYeNO                    e2          eNO                    e%          dd;                        ZZefdd@Z[efddAZ\dd efddHZ]	 dddJZ^	 	 dddMZ_dddQZ`eFeGeddRddYZadd\ZbeFeGeddRdd^Zcd_eFeGeHedd`ddeZdeFeGeddRddgZeddlZfddmZgedfddsZheFeGddtdduZieFeGddtddwZjeeee         f         Zkdxeldy<   eHfdd{ZmeHdd|dd~ZndS )    )annotations)ListIterableIteratorUnionOptionalCallableTypeTypeVar)	TypeAlias)singledispatchpartialN)ABS_TOLVec2Vec3NULLVECZ_AXISOCSBezier3PBezier4PConstructionEllipseBSpline have_bezier_curves_g1_continuityfit_points_to_cad_cvUVecMatrix44)const)
LWPolylinePolylineHatchLineSplineEllipseArcCircleSolidTraceFace3dViewportImageHelixWipeoutMPolygonBoundaryPathsAbstractBoundaryPathPolylinePathEdgePathLineEdgeArcEdgeEllipseEdge
SplineEdge)
DXFPolygon   )Path)Command)tools)group_paths)	make_pathto_linesto_polylines3dto_lwpolylinesto_polylines2d
to_hatchesto_mpolygonsto_bsplines_and_verticesto_splines_and_polylines
from_hatchfrom_hatch_ocsfrom_hatch_boundary_pathfrom_hatch_edge_pathfrom_hatch_polyline_pathfrom_verticesg{Gz?   g-C6?TPolygonezdxfsegmentsintlevelreturnr8   c                J    t          d|                                            )u9  Factory function to create a single :class:`Path` object from a DXF
    entity.

    Args:
        entity: DXF entity
        segments: minimal count of cubic Bézier-curves for elliptical arcs
        level: subdivide level for SPLINE approximation

    Raises:
        TypeError: for unsupported DXF types

    zunsupported DXF type: )	TypeErrordxftype)entityrN   rP   s      N/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/path/converter.pyr<   r<   ]   s%    $ ?V^^-=-=??
@
@@    
lwpolyliner   c                    t                      }t          j        ||                     d          | j        |                                 | j        j        |                    dd                     |S )NxybrN   r7   closeocs	elevationrN   )	r8   r:   add_2d_polyline
get_pointsclosedr]   dxfr^   get)rX   kwargspaths      rV   _from_lwpolylinerf   r   sl    66D	e$$NN.*J**    KrW   polyliner   c                `   | j         s| j        rt          d          t                      }t	          | j                  dk    r|S | j        r't          |                                 | j	                  S d | j        D             }| 
                                }| j                            d          rt          | j        j                  j        }n)t          | j        d         j        j                  j        }t#          j        ||| j	        |||                    dd                     |S )Nz-Unsupported DXF type PolyMesh or PolyFaceMeshr   c                8    g | ]}|                     d           S )rZ   format).0vertexs     rV   
<listcomp>z"_from_polyline.<locals>.<listcomp>   s$    CCCvfmmE""CCCrW   r^   rN   r7   r[   )is_polygon_meshis_poly_face_meshrS   r8   lenverticesis_3d_polylinerJ   points	is_closedr]   rb   hasattrr   r^   zlocationr:   r_   rc   )rg   rd   re   rt   r]   r^   s         rV   _from_polylinery      s+    I8#= IGHHH66D
8"" DX__..0BCCCCC1BCCCF
,,..C|K(( >/002		 *1-1:;;=		 J**    KrW   spliner"   c                    |                     dd          }t                      }t          j        ||                                 |d           |S )NrP   rK   T)rP   reset)rc   r8   r:   
add_splineconstruction_tool)rz   rd   rP   re   s       rV   _from_spliner      sK     JJw""E66D	T63355U$OOOOKrW   ellipser#   c                    |                     dd          }t                      }t          j        ||                                 |d           |S )NrN   r7   TrN   r|   )rc   r8   r:   add_ellipser~   )r   rd   rN   re   s       rV   _from_ellipser      sJ    zz*a((H66D	dG5577(RVWWWWKrW   liner!   c                v    t          | j        j                  }|                    | j        j                   |S N)r8   rb   startline_toend)r   rd   re   s      rV   
_from_liner      s.    DLLKrW   arcr$   c                >   |                     dd          }t                      }t          | j        j                  }|dk    rYt          j        | j        j        || j        j        | j        j	        | j        j
                  }t          j        |||d           |S )NrN   r7   -q=centerradius	extrusionstart_angle	end_angleTr   )rc   r8   absrb   r   r   from_arcr   r   r   r   r:   r   )r   rd   rN   re   r   r   s         rV   	_from_arcr      s    zz*a((H66D  F~~%.7>g'+g'
 
 
 	$($GGGGKrW   circler%   c                   |                     dd          }t                      }t          | j        j                  }|dk    rCt          j        | j        j        || j        j                  }t          j
        |||d           |S )NrN   r7   r   )r   r   r   Tr   )rc   r8   r   rb   r   r   r   r   r   r:   r   )r   rd   rN   re   r   r   s         rV   _from_circler      s    zz*a((H66D"##F~~%.:$j*
 
 

 	$($GGGGKrW   solid'Solid'c                L    |                                  }t          |d          S NTr\   )wcs_verticesrJ   )r   rd   rr   s      rV   _from_quadrilateralr      s(     !!##H....rW   vp
'Viewport'c                    | j         rU| j        j        }|dk    rC| j        r<| j        j        }|r.| j        j                            |          }|rt          |fi |S t          |                                 d          S )N0Tr   )	has_extended_clipping_pathrb   clipping_boundary_handledocentitydbrc   r<   rJ   clipping_rect_corners)r   rd   handledbclipping_entitys        rV   _from_viewportr      s    	$ @0S==RV=B @"$&/"5"5f"="=" @$_?????11334@@@@rW   image'Image'c                H    t          |                                 d          S r   )rJ   boundary_path_wcs)r   rd   s     rV   _from_imager      s#     0022$????rW   hatchr    c                   |                                  | j        j        j        t          t          | t                    r | j                            dt                    	 fd| j        D             }nM# t          j
        $ r; t                              dt          |                       t                      cY S w xY wt          j        |          S )Noffset_vectorc                6    g | ]}t          |           S ))offset)rG   )rl   boundaryr^   r]   r   s     rV   rn   z_from_hatch.<locals>.<listcomp>   s:     
 
 
 %XsIfMMM
 
 
rW   zinvalid data in )r]   rb   r^   rw   r   
isinstancer-   rc   pathsr   DXFStructureErrorloggerwarningstrr8   r:   to_multi_path)r   rd   r   r^   r]   r   s      @@@rV   _from_hatchr      s     ))++C	#%IF%"" 988
 
 
 
 
 
!K
 
 
 "   6#e**66777vv
 u%%%s   &A< <ACCr6   r   r   Iterator[Path]c              #     K   |                                  }| j        j        j        }| j        D ];}t          ||||          }|j        r|                                E d{V  7|V  <dS )zgYield all HATCH/MPOLYGON boundary paths as separated :class:`Path` objects in WCS
    coordinates.
    r^   r   N)r]   rb   r^   rw   r   rG   has_sub_paths	sub_paths)r   r   r]   r^   r   ps         rV   rE   rE   	  s       ))++C	#%IK  $XsiPVWWW? 	{{}}$$$$$$$$GGGG rW   c              #     K   | j         j        j        }| j        D ]:}t	          |||          }|j        r|                                E d{V  6|V  ;dS )zYield all HATCH/MPOLYGON boundary paths as separated :class:`Path` objects in OCS
    coordinates. Elevation and offset is applied to all vertices.

    .. versionadded:: 1.1

    r   N)rb   r^   rw   r   rG   r   r   )r   r   r^   r   r   s        rV   rF   rF     s|       	#%IK  $X6RRR? 	{{}}$$$$$$$$GGGG rW   r   r/   r]   Optional[OCS]r^   floatc                   t          | t                    rt          | ||          }nCt          | t                    rt	          | ||          }nt          t          |                     |rc|a|                    |                    |                    }|	                    t          j        |j        |j        |j                            }t          j                            | j                  |_        |S )zeReturns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    polyline- or edge path.
    Nrw   )r   r1   rH   r0   rI   rS   typeto_wcsreplace	transformr   	translatexyrw   r   BoundaryPathState
from_flagspath_type_flags	user_data)r   r]   r^   r   r   s        rV   rG   rG   '  s     (H%% ( 3	::	Hl	+	+ ($XsI>>X''' J#/FNNYN7788KK*68VXvxHHII )44X5MNNAKHrW   r0   c                    t                      }t          j        || j        | j        |pt                      |           |S )z\Returns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    polyline path.
    )r\   r]   r^   )r8   r:   r_   rr   ru   r   )rg   r]   r^   re   s       rV   rI   rI   A  sK     66D	 L355    KrW   edgesr1   c                Z   dfd}dfd}dfd}dfd	}dfd
dddfddfddfdrj         nt          t                      }d}| D ]}	d}
t          |	t                    r ||	          }
nt          |	t
                    r)t          |	j                  t          k    r ||	          }
nwt          |	t                    r%t          |	j                  j        s ||	          }
n=t          |	t                    r ||	          }
nt          t          |	                    |
||
}|j                            |
j                  r|                    |
           |j                            |
j                  r)|                    |
                                           a|j                            |
j                  r|
                    |           |
}|j                            |
j                  r+|                                }|                    |
           |j        r|                    |           |
}|                    |
           |)|                                 |                    |           |S )zYReturns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    edge path.

    edger2   c                     | j                   } | j                  }t          |          }|                    |           |S r   )r   r   r8   r   )r   r   r   segmentwcss       rV   r   z"from_hatch_edge_path.<locals>.line\  sC    DJc$(mmu++rW   r3   c                    | j         ^}}}t          j        ||f| j        | j        | j                  }t                      }t          j        ||d           |S )Nr   Tr|   )	r   r   r   r   r   r   r8   r:   r   )r   r   r   _r   r   r^   r   s         rV   r   z!from_hatch_edge_path.<locals>.arcc  sn    ;1q
 &.q)$;(n
 
 
 &&'7$7777rW   r4   c           	     <   |                                  }t           |j                            t	                                         |j                  |j        |j        |j                  }t                      }t          j        ||d           |S )Nr   )r   
major_axisratior   start_param	end_paramTr   )r~   r   r   r   r   r   r   r   r   r8   r:   r   )r   ocs_ellipser   r   r^   r   r   wcs_tangents       rV   r   z%from_hatch_edge_path.<locals>.ellipset  s    ,,..
 &3{)11E)4D4D1EEFF"{;#9::##/!+
 
 
 &&'7$7777rW   r5   c                   fd| j         D             }t          |          dk    r1fd| j        D             }t          |          r | |          }nd S  | |          }t                      }t	          j        ||d           |S )Nc                &    g | ]} |          S  r   rl   r   r   s     rV   rn   z8from_hatch_edge_path.<locals>.spline.<locals>.<listcomp>  s!    >>>Q##a&&>>>rW   r   c                &    g | ]} |          S r   r   r   s     rV   rn   z8from_hatch_edge_path.<locals>.spline.<locals>.<listcomp>  s!    :::Q##a&&:::rW   Tr   )control_pointsrq   
fit_pointsr8   r:   r}   )r   r   r   bspliner   from_control_pointsfrom_fit_pointsr   s        rV   rz   z$from_hatch_edge_path.<locals>.spline  s    >>>>$*=>>>~!##::::$/:::J: )/$
;; ))$??G&&'6666rW   c                    d }| j         r'| j        r  | j                    | j                  f}t          ||          S )N)tangents)start_tangentend_tangentr   )r   r   r   r   s      rV   r   z-from_hatch_edge_path.<locals>.from_fit_points  sc     	$"2 	D.//D,--H $
 
 
 	
rW   c                ^    t          || j        dz   | j        | j        r| j        nd           S )Nr7   )r   orderknotsweights)r   degreeknot_valuesr   )r   r   s     rV   r   z1from_hatch_edge_path.<locals>.from_control_points  s;    )+/"$(L:DLLd	
 
 
 	
rW   rm   r   rQ   r   c                P     t          | d         | d                             S Nr   r7   r   )rm   _wcsr^   s    rV   r   z!from_hatch_edge_path.<locals>.wcs  s'    tDF1Iy99:::rW   c                P     t          | d         | d         d                    S r   r   )rm   r   s    rV   r   z)from_hatch_edge_path.<locals>.wcs_tangent  s'    tDF1Iq11222rW   vec3c                D    rj         r                    |           S | S r   )r   r   )r  r]   s    rV   r   z"from_hatch_edge_path.<locals>._wcs  s+     	3= 	::d###KrW   N)r   r2   )r   r3   )r   r4   )r   r5   )rm   r   rQ   r   )r  r   rQ   r   )uzr   r8   r   r2   r3   r   r   r   r4   r   r   is_nullr5   rS   r   r   iscloser   append_pathreversedru   extend_multi_pathr\   )r   r]   r^   r   r   r   rz   re   loopr   next_segmentr   r   r   r   r   r   s    ``        @@@@@@rV   rH   rH   R  s              "        $        

 

 

 

 

 


 
 
 
; ; ; ; ; ; ;3 3 3 3 3 3      )6I66DD */ */'+dH%% 	(4::LLg&& 		(4;'))"s4yyk** 	(((0 -&wt}}j)) 	(!6$<<LLDJJ'''<D8L.// 	/\****Xl.// 	/\22445555Z 011 	/$$T***DDZ 233 
	/==??D\****~ /&&t,,,#   ....

t$$$KrW   Frr   Iterable[UVec]c                @   t          j        |           }t          |          dk     rt                      S t          |d                   }|dd         D ]1}|j                            |          s|                    |           2|r|                                 |S )z9Returns a :class:`Path` object from the given `vertices`.   r   )r   r7   N)r   listrq   r8   r   r  r   r\   )rr   r\   	_verticesre   rm   s        rV   rJ   rJ     s    	(##I
9~~vvil###DABB- ! !x'' 	!LL    

KrW   )distancerN   r   
dxfattribsr   Iterable[Path]r  r   r   Iterator[LWPolyline]c             #    K   t          | t                    r| g} nt          |           } t          |           dk    rdS t	          |          }t	          | d         j                  }t          |pi           }t          j        |          s3t          ||          \  }}t          j        | |          } ||d<   ||d<   n|j        dk    r
|j        |d<   t          j        |           D ]Y}t          |          dk    rDt          j        |          }	|	                    |                    ||          d           |	V  ZdS )u  Convert the given `paths` into :class:`~ezdxf.entities.LWPolyline`
    entities.
    The `extrusion` vector is applied to all paths, all vertices are projected
    onto the plane normal to this extrusion vector. The default extrusion vector
    is the WCS z-axis. The plane elevation is the distance from the WCS origin
    to the start point of the first path.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve
        extrusion: extrusion vector for all paths
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.LWPolyline` objects

    r   Nr^   r   r  xyrj   )r   r8   r  rq   r   r   dictr   r  _get_ocsr:   transform_paths_to_ocsrw   single_pathsr   newappend_points
flattening
r   r  rN   r   r  reference_pointr]   r^   re   r   s
             rV   r?   r?     sN     4 % U
5zzQYI58>**Oj&B''J>)$$ 4!)_==Y,UC88"+
;"+
;		a		"1"3
;"5))  t99q==*555AOODOOHh??OMMMGGG	 rW   r   tuple[OCS, float]c                \    t          |           }|                    |          j        }||fS r   )r   from_wcsrw   )r   r   r]   r^   s       rV   r  r  +  s+    
i..C_--/I	>rW   Iterator[Polyline]c             #    K   t          | t                    r| g} nt          |           } t          |           dk    rdS t	          |          }t	          | d         j                  }t          |pi           }t          j        |          sBt          ||          \  }}t          j        | |          } t	          dd|          |d<   ||d<   n$|j        dk    rt	          dd|j                  |d<   t          j        |           D ]k}t          |          dk    rVt          j        |          }	|	                    |                    ||                     |	                                 |	V  ldS )u  Convert the given `paths` into 2D :class:`~ezdxf.entities.Polyline`
    entities.
    The `extrusion` vector is applied to all paths, all vertices are projected
    onto the plane normal to this extrusion vector. The default extrusion vector
    is the WCS z-axis. The plane elevation is the distance from the WCS origin
    to the start point of the first path.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve
        extrusion: extrusion vector for all paths
        dxfattribs: additional DXF attribs

    Returns:
        iterable of 2D :class:`~ezdxf.entities.Polyline` objects

    r   Nr^   r   r  )r   r8   r  rq   r   r   r  r   r  r  r:   r  rw   r  r   r  append_verticesr  
new_seqendr  s
             rV   r@   r@   1  sr     4 % U
5zzQYI58>**Oj&B''J>)$$ @!)_==Y,UC88"&q!Y"7"7
;"+
;		a		"&q!_->"?"?
;"5))  t99q==
333AdoohAABBBLLNNNGGG rW   T)	edge_pathr  rN   g1_tolr   r  r(  boolr)  Iterator[Hatch]c             #     K   |rt          t          |||          }nt          t          ||          }t          t          | |||          E d{V  dS )uU  Convert the given `paths` into :class:`~ezdxf.entities.Hatch` entities.
    Uses LWPOLYLINE paths for boundaries without curves and edge paths, build
    of LINE and SPLINE edges, as boundary paths for boundaries including curves.
    The `extrusion` vector is applied to all paths, all vertices are projected
    onto the plane normal to this extrusion vector. The default extrusion vector
    is the WCS z-axis. The plane elevation is the distance from the WCS origin
    to the start point of the first path.

    Args:
        paths: iterable of :class:`Path` objects
        edge_path: ``True`` for edge paths build of LINE and SPLINE edges,
            ``False`` for only LWPOLYLINE paths as boundary paths
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve to flatten LWPOLYLINE paths
        g1_tol: tolerance for G1 continuity check to separate SPLINE edges
        extrusion: extrusion vector to all paths
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.Hatch` objects

    )r  rN   r)  r  rN   N)r   build_edge_pathbuild_poly_path_polygon_converterr    )r   r(  r  rN   r)  r   r  boundary_factorys           rV   rA   rA   d  s      B  	
"h&
 
 

 #h
 
 
 "%0@)ZXXXXXXXXXXXrW   Iterator[MPolygon]c             #     K   t          t          ||          }t          |pi           }|                    dt          j                   t          t          | |||          E d{V  dS )uT  Convert the given `paths` into :class:`~ezdxf.entities.MPolygon` entities.
    In contrast to HATCH, MPOLYGON supports only polyline boundary paths.
    All curves will be approximated.

    The `extrusion` vector is applied to all paths, all vertices are projected
    onto the plane normal to this extrusion vector. The default extrusion vector
    is the WCS z-axis. The plane elevation is the distance from the WCS origin
    to the start point of the first path.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve to flatten LWPOLYLINE paths
        extrusion: extrusion vector to all paths
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.MPolygon` objects

    r-  
fill_colorN)r   r/  r  
setdefaultr   BYLAYERr0  r-   )r   r  rN   r   r  r1  s         rV   rB   rB     s      : )0(X) ) ) j&B''J,666!%)9j          rW   
boundariesr.   re   flagsc                   |j         r|                     |          }t          ||          D ]y}t          |t                    r5|                    |j        |j        |                                           L|d         }|dd          D ]}	|	                    ||	           |	}zd S | 
                    t          j        |                    ||                    |           d S )N)r)  )r   r   r   r   r7   r8  )
has_curvesadd_edge_pathrC   r   r   r}   r   r   r   add_lineadd_polyline_pathr   generater  )
r7  re   r8  r  rN   r)  r(  r   prevr   s
             rV   r.  r.    s     
,,U33	,T&AAA 	 	D$(( 
$$#'#6; $

 %     Awabb  A&&tQ///DD	 	 	$$M$//(H==>>e 	% 	
 	
 	
 	
 	
rW   c                    |                      t          j        |                    ||                    |           d S )Nr:  )r>  r   r?  r  )r7  re   r8  r  rN   s        rV   r/  r/    sI       dooh99:: !     rW   clsType[TPolygon]add_boundaryBoundaryFactoryIterator[TPolygon]c              #    K   t          |t                    r|g}nt          |          }t          |          dk    rd S t	          |          }|d         j        }t          |pi           }t          j        |          sBt          ||          \  }}t          j        ||          }t	          dd|          |d<   ||d<   n$|j        dk    rt	          dd|j                  |d<   |                    dd           |                    dd           |                    dt          j                   t!          t          j        |                    D ]}	t          |	          dk    r|                     |	          }
|
j        }|	d         }|                                  |||d           |	dd          D ]#}|                                  |||d           $|
V  d S )
Nr   r^   r   
solid_fillr7   pattern_nameSOLIDcolorr  )r   r8   r  rq   r   r   r  r   r  r  r:   r  rw   r5  r   r6  r;   r  r  r   r\   )rB  r   rD  r   r  r   _dxfattribsr]   r^   grouppolygonr7  externalholes                 rV   r0  r0    s      % U
5zzQYIAhnOZ-2..K>)$$ A!)_==Y,UC88#'1i#8#8K #,K  		a		#'1o.?#@#@K <+++>73337EM222U/6677  u::??''['11]
8Z1---!""I 	. 	.DJJLLLLT1---- rW   )r  rN   r  c             #  z  K   t          | t                    r| g} t          |pi           }t          j        |d<   t          j        |           D ]k}t          |          dk    rVt          j	        |          }|
                    |                    ||                     |                                 |V  ldS )u  Convert the given `paths` into 3D :class:`~ezdxf.entities.Polyline`
    entities.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve
        dxfattribs: additional DXF attribs

    Returns:
        iterable of 3D :class:`~ezdxf.entities.Polyline` objects

    r8  r   r  N)r   r8   r  r   POLYLINE_3D_POLYLINEr:   r  rq   r   r  r&  r  r'  )r   r  rN   r  re   r   s         rV   r>   r>     s      ( % j&B''J4Jw"5))  t99q==
333AdoohAABBBLLNNNGGG rW   Iterator[Line]c             #  <  K   t          | t                    r| g} t          |pi           }d}t          j        |           D ]Y}t          |          dk    r|                    ||          D ]*}||}||d<   ||d<   t          j        |          V  |}+d}ZdS )uv  Convert the given `paths` into :class:`~ezdxf.entities.Line` entities.

    Args:
        paths: iterable of :class:`Path` objects
        distance:  maximum distance, see :meth:`Path.flattening`
        segments: minimum segment count per Bézier curve
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.Line` objects

    Nr   r   r   r  )	r   r8   r  r:   r  rq   r  r!   r  )r   r  rN   r  prev_vertexre   rm   s          rV   r=   r=   0  s      & % j&B''JK"5))  t99>>ooh99 	! 	!F"$"-Jw &Ju(j111111 KK rW   r   	PathPartsIterator[PathParts]c              #  @  	
K   ddl m	 
fd}	fd}g }t          j        | g          D ]} | j        }| D ]}|j        t          j        k    rt          ||j	        |j
        g          }n^|j        t          j        k    r#t          ||j        |j        |j
        g          }n&|j        t          j        k    r
||j
        f}nt           |                    |           |j
        }g g 
|D ]}t%          |t&                    r<r$ |            E d{V                                   
                    |           S
r  |            V  
                                                     |           r |            E d{V  
r |            V  dS dS )uq  Convert a :class:`Path` object into multiple cubic B-splines and
    polylines as lists of vertices. Breaks adjacent Bèzier without G1
    continuity into separated B-splines.

    Args:
        path: :class:`Path` objects
        g1_tol: tolerance for G1 continuity check

    Returns:
        :class:`~ezdxf.math.BSpline` and lists of :class:`~ezdxf.math.Vec3`

    r   )bezier_to_bsplinec                 f    d         d         g} D ]}|                      |d                    | S r   )append)rt   r   rg   s     rV   to_verticesz-to_bsplines_and_vertices.<locals>.to_verticesg  s@    1+a.! 	# 	#DMM$q'""""rW   c               3     K   d         } | g}dd          D ];}t          | |          r|                    |           n |          V  |g}|} <|r |          V  d S d S r   )r   r[  )b1_g1_continuity_curvesb2bezierrY  r)  s      rV   
to_bsplinez,to_bsplines_and_vertices.<locals>.to_bsplinem  s      AY!#* 	 	B/B?? -%,,R0000''(=>>>>>)+%BB  	;##$9:::::::	; 	;rW   N)
ezdxf.mathrY  r:   r  r   r   r9   	CURVE3_TOr   ctrlr   	CURVE4_TOr   ctrl1ctrl2LINE_TO
ValueErrorr[  r   tupleclear)re   r)  r\  rb  curvesr@  cmdcurvera  rY  rg   s    `      @@@rV   rC   rC   X  s1      -,,,,,    ; ; ; ; ; ; ; F"D6**  z 
	 
	Cx7,,, $#'!:;;W... $	39cg!FGGW_,,sw  MM%   7DD
	 FH 
! 
!eU## 		! %:<<'''''''OOE"""" !!kmm###   MM%      :<< kmm rW   )r)  r  !Iterator[Union[Spline, Polyline]]c             #    K   t          | t                    r| g} t          |pi           }t          j        |           D ]}t          ||          D ]}t          |t                    r/t          j        |          }|	                    |           |V  Ft          |          }t          j        |d<   t          j        |          }|                    |           |                                 |V  dS )a\  Convert the given `paths` into :class:`~ezdxf.entities.Spline` and 3D
    :class:`~ezdxf.entities.Polyline` entities.

    Args:
        paths: iterable of :class:`Path` objects
        g1_tol: tolerance for G1 continuity check
        dxfattribs: additional DXF attribs

    Returns:
        iterable of :class:`~ezdxf.entities.Line` objects

    r  r8  N)r   r8   r  r:   r  rC   r   r"   r  apply_construction_toolr   rR  r   r&  r'  )r   r)  r  re   datarz   attribsrg   s           rV   rD   rD     s     $ % j&B''J"5))  ,T6:: 	 	D$(( 
z:::..t444z**#(#= #<:>>>((...##%%%	 rW   )r7   rK   )rN   rO   rP   rO   rQ   r8   )rX   r   rQ   r8   )rg   r   rQ   r8   )rz   r"   rQ   r8   )r   r#   rQ   r8   )r   r!   rQ   r8   )r   r$   rQ   r8   )r   r%   rQ   r8   )r   r   rQ   r8   )r   r   rQ   r8   )r   r   rQ   r8   )r   r    rQ   r8   )r   r6   r   r   rQ   r   )
r   r/   r]   r   r^   r   r   r   rQ   r8   )Nr   )rg   r0   r]   r   r^   r   rQ   r8   )r   r1   r]   r   r^   r   rQ   r8   )F)rr   r  rQ   r8   )
r   r  r  r   rN   rO   r   r   rQ   r  )r   r   r   r   rQ   r!  )
r   r  r  r   rN   rO   r   r   rQ   r$  )r   r  r(  r*  r  r   rN   rO   r)  r   r   r   rQ   r+  )
r   r  r  r   rN   rO   r   r   rQ   r2  )r7  r.   re   r8   r8  rO   r  r   rN   rO   r)  r   )
r7  r.   re   r8   r8  rO   r  r   rN   rO   )
rB  rC  r   r  rD  rE  r   r   rQ   rF  )r   r  r  r   rN   rO   rQ   r$  )r   r  r  r   rN   rO   rQ   rS  )re   r8   r)  r   rQ   rW  )r   r  r)  r   rQ   rp  )o
__future__r   typingr   r   r   r   r   r	   r
   r   typing_extensionsr   	functoolsr   r   loggingrc  r   r   r   r   r   r   r   r   r   r   r   r   r   r   ezdxf.lldxfr   ezdxf.entitiesr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   ezdxf.entities.polygonr6   re   r8   commandsr9    r:   nestingr;   __all__MAX_DISTANCEMIN_SEGMENTSG1_TOLrL   rO   rE  	getLoggerr   r<   registerrf   ry   r   r   r   r   r   r   r   r   r   rE   rF   rG   rI   rH   rJ   r?   r  r@   rA   rB   r.  r/  r0  r>   r=   rV  __annotations__rC   rD   r   rW   rV   <module>r     s   # " " " " " "	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ( ' ' ' ' ' - - - - - - - -                                                                                          4 . - - - - -                                $ 	7:uh//M45t;<		7	#	# A A A A A( J
 
 
  
 H   < E
F     G    D    C     F    F
E
E/ / /   /
 HA A A A G
E@ @ @  @ H
E& & &  && 29      6=     $ 	    6 KL    & V V V V Vr    " # / / / / / /d    # 0 0 0 0 0 0l " ,Y ,Y ,Y ,Y ,Y ,Yd # % % % % % %P
 
 
 
8   $ ' ' ' ' 'Z #      H # " " " " " "J Wd4j01	 1 1 1 1 :@ C C C C CR 	" " " " " " " "rW   