
    Og}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j                  d      ZMed:d;d       ZNeNj                  e#      d<d       ZPeNj                  e$      d=d       ZQeNj                  e0      eNj                  e'      d>d              ZReNj                  e(      d?d       ZSeNj                  e&      d@d       ZTeNj                  e)      dAd       ZUeNj                  e*      dBd       ZVeNj                  e-      eNj                  e,      eNj                  e+      dCd                     ZWeNj                  e.      dDd       ZXeNj                  e1      eNj                  e/      dEd              ZYeNj                  e2      eNj                  e%      dFd               ZZefdGd!Z[efdGd"Z\dd ef	 	 	 	 	 	 	 	 	 dHd#Z]	 dI	 	 	 	 	 	 	 dJd$Z^	 	 dI	 	 	 	 	 	 	 dKd%Z_dLdMd&Z`eFeGedd'	 	 	 	 	 	 	 	 	 dNd(ZadOd)ZbeFeGedd'	 	 	 	 	 	 	 	 	 dPd*Zcd+eFeGeHedd,	 	 	 	 	 	 	 	 	 	 	 	 	 dQd-ZdeFeGedd'	 	 	 	 	 	 	 	 	 dRd.Ze	 	 	 	 	 	 	 	 	 	 	 	 dSd/Zf	 	 	 	 	 	 	 	 	 	 dTd0Zgedf	 	 	 	 	 	 	 	 	 dUd1ZheFeGdd2	 	 	 	 	 	 	 dVd3ZieFeGdd2	 	 	 	 	 	 	 dWd4Zjeeee   f   Zkd5eld6<   eHfdXd7ZmeHdd8	 	 	 	 	 dYd9Zny)Z    )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ezdxfc                :    t        d| j                                )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)entitysegmentslevels      Y/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/path/converter.pyr<   r<   ]   s    $ ,V^^-=,>?
@@    c                    t               }t        j                  || j                  d      | j                  | j                         | j                  j                  |j                  dd             |S )NxybrR   r7   closeocs	elevationrR   )	r8   r:   add_2d_polyline
get_pointsclosedrZ   dxfr[   get)
lwpolylinekwargspaths      rT   _from_lwpolylinerd   r   s]    6D	e$NN..**J* KrU   c                   | j                   s| j                  rt        d      t               }t	        | j
                        dk(  r|S | j                  r$t        | j                         | j                        S | j
                  D cg c]  }|j                  d       }}| j                         }| j                  j                  d      r*t        | j                  j                        j                   }n6t        | j
                  d   j                  j"                        j                   }t%        j&                  ||| j                  |||j)                  dd             |S c c}w )Nz-Unsupported DXF type PolyMesh or PolyFaceMeshr   rW   r[   rR   r7   rX   )is_polygon_meshis_poly_face_meshrO   r8   lenverticesis_3d_polylinerJ   points	is_closedformatrZ   r_   hasattrr   r[   zlocationr:   r\   r`   )polylinerb   rc   vertexrk   rZ   r[   s          rT   _from_polyliners      s!   8#=#=GHH6D
8"X__.0B0BCC191B1BCvfmmE"CFC
,,.C||K(//022	 **1-11::;==		  J* K! Ds   E"c                    |j                  dd      }t               }t        j                  || j	                         |d       |S )NrS   rK   T)rS   reset)r`   r8   r:   
add_splineconstruction_tool)splinerb   rS   rc   s       rT   _from_splinery      s=     JJw"E6D	T6335U$OKrU   c                    |j                  dd      }t               }t        j                  || j	                         |d       |S )NrR   r7   TrR   ru   )r`   r8   r:   add_ellipserw   )ellipserb   rR   rc   s       rT   _from_ellipser~      s<    zz*a(H6D	dG557(RVWKrU   c                    t        | j                  j                        }|j                  | j                  j                         |S N)r8   r_   startline_toend)linerb   rc   s      rT   
_from_liner      s-    DLLKrU   c                   |j                  dd      }t               }t        | j                  j                        }|dkD  rt        j                  | j                  j                  || j                  j                  | j                  j                  | j                  j                        }t        j                  |||d       |S )NrR   r7   -q=centerradius	extrusionstart_angle	end_angleTr{   )r`   r8   absr_   r   r   from_arcr   r   r   r   r:   r|   )arcrb   rR   rc   r   r}   s         rT   	_from_arcr      s    zz*a(H6D F~%..77>>gg''++gg''
 	$($GKrU   c                8   |j                  dd      }t               }t        | j                  j                        }|dkD  rYt        j                  | j                  j                  || j                  j                        }t        j                  |||d       |S )NrR   r7   r   )r   r   r   Tr{   )r`   r8   r   r_   r   r   r   r   r   r:   r|   )circlerb   rR   rc   r   r}   s         rT   _from_circler      s|    zz*a(H6D""#F~%..::$$jj**

 	$($GKrU   c                <    | j                         }t        |d      S NTrY   )wcs_verticesrJ   )solidrb   ri   s      rT   _from_quadrilateralr      s     !!#H..rU   c                4   | j                   rr| j                  j                  }|dk7  rW| j                  rK| j                  j                  }|r3| j                  j                  j                  |      }|rt        |fi |S t        | j                         d      S )N0Tr   )	has_extended_clipping_pathr_   clipping_boundary_handledocentitydbr`   r<   rJ   clipping_rect_corners)vprb   handledbclipping_entitys        rT   _from_viewportr      sx    	$$00S=RVVB"$&&//"5"5f"="$_???1134@@rU   c                8    t        | j                         d      S r   )rJ   boundary_path_wcs)imagerb   s     rT   _from_imager      s     002$??rU   c           	        | j                         }| j                  j                  j                  }t        }t        | t              r | j                  j                  dt              }	 | j                  D cg c]  }t        ||||       }}t!        j"                  |      S c c}w # t        j                  $ r. t        j                  dt        |               t               cY S w xY w)Noffset_vector)offsetzinvalid data in )rZ   r_   r[   ro   r   
isinstancer-   r`   pathsrG   r   DXFStructureErrorloggerwarningstrr8   r:   to_multi_path)hatchrb   rZ   r[   r   boundaryr   s          rT   _from_hatchr      s     ))+C		##%%IF%"8 "KK
 %XsIfM
 
 u%%
 "" )#e*67vs$   (B( 6B#B( #B( (>C)(C)c              #    K   | j                         }| j                  j                  j                  }| j                  D ]:  }t        ||||      }|j                  r|j                         E d{    7| < y7 w)zgYield all HATCH/MPOLYGON boundary paths as separated :class:`Path` objects in WCS
    coordinates.
    r[   r   N)rZ   r_   r[   ro   r   rG   has_sub_paths	sub_paths)r   r   rZ   r[   r   ps         rT   rE   rE   	  sl      ))+C		##%%IKK $XsiPVW??{{}$$G %s   A.A?0A=1A?c              #     K   | j                   j                  j                  }| j                  D ]9  }t	        |||      }|j
                  r|j                         E d{    6| ; y7 w)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)r_   r[   ro   r   rG   r   r   )r   r   r[   r   r   s        rT   rF   rF     s^      		##%%IKK $X6R??{{}$$G %s   AA.A, A.c                   t        | t              rt        | ||      }n2t        | t              rt	        | ||      }nt        t        |             |rg|e|j                  |j                  |            }|j                  t        j                  |j                  |j                  |j                              }t        j                   j#                  | j$                        |_        |S )zeReturns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    polyline- or edge path.
    ro   )r   r1   rH   r0   rI   rO   typeto_wcsreplace	transformr   	translatexyro   r   BoundaryPathState
from_flagspath_type_flags	user_data)r   rZ   r[   r   r   s        rT   rG   rG   '  s     (H% 3	:	Hl	+$XsI>X''#/FNNYN78KK**688VXXvxxHI ))44X5M5MNAKHrU   c                    t               }t        j                  || j                  | j                  |xs
 t               |       |S )z\Returns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    polyline path.
    )rY   rZ   r[   )r8   r:   r\   ri   rl   r   )rq   rZ   r[   rc   s       rT   rI   rI   A  sA     6D	  L35 KrU   c                    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        kD  rn ||	      }
net        |	t              r(t        |	j                        j                  s6 ||	      }
n-t        |	t              r	 ||	      }
nt        t        |	            |
||
}|j                   j#                  |
j$                        r|j'                  |
       |j                   j#                  |
j                         r!|j'                  |
j)                                >|j$                  j#                  |
j                         r|
j'                  |       |
}x|j$                  j#                  |
j$                        r#|j)                         }|j'                  |
       |j*                  r|j-                  |       |
}|j'                  |
        |!|j/                          |j-                  |       |S )zYReturns a :class:`Path` object from a :class:`~ezdxf.entities.Hatch`
    edge path.

    c                     | j                         } | j                        }t        |      }|j                  |       |S r   )r   r   r8   r   )edger   r   segmentwcss       rT   r   z"from_hatch_edge_path.<locals>.line\  s7    DJJ$((mu+rU   c                    | j                   ^}}}t        j                  ||f| j                  | j                  | j
                        }t               }t        j                  ||d       |S )Nr   Tru   )	r   r   r   r   r   r   r8   r:   r|   )r   r   r   _r}   r   r[   r   s         rT   r   z!from_hatch_edge_path.<locals>.arcc  sh    ;;1q
 &..q)$;;((nn
 &'7$7rU   c           	     <   | j                         }t         |j                  j                  t	                           |j
                        |j                  |j                  |j                        }t               }t        j                  ||d       |S )Nr   )r   
major_axisratior   start_param	end_paramTr   )rw   r   r   r   floatr   r   r   r   r8   r:   r|   )r   ocs_ellipser}   r   r[   r   r   wcs_tangents       rT   r}   z%from_hatch_edge_path.<locals>.ellipset  s    ,,.
 &{))11E)4D1EF";#9#9:###//!++
 &'7$7rU   c                6   | j                   D cg c]
  } |       }}t        |      dk(  r5| j                  D cg c]
  } |       }}t        |      r
 | |      }n
y  | |      }t               }t	        j
                  ||d       |S c c}w c c}w )Nr   Tr   )control_pointsrh   
fit_pointsr8   r:   rv   )	r   r   r   r   bspliner   from_control_pointsfrom_fit_pointsr   s	         rT   rx   z$from_hatch_edge_path.<locals>.spline  s    *.*=*=>Q#a&>>~!#*.//:Q#a&:J::)$
; )$?G&'6 ?:s
   BBc                    d }| j                   r0| j                  r$ | j                          | j                        f}t        ||      S )N)tangents)start_tangentend_tangentr   )r   r   r   r   s      rT   r   z-from_hatch_edge_path.<locals>.from_fit_points  sQ    $"2"2D../D,,-H $
 	
rU   c                    t        || j                  dz   | j                  | j                  r| j                        S d       S )Nr7   )r   orderknotsweights)r   degreeknot_valuesr   )r   r   s     rT   r   z1from_hatch_edge_path.<locals>.from_control_points  sB    )++/""$(LLDLL	
 	
 7;	
 	
rU   c                6     t        | d   | d               S Nr   r7   r   )rr   _wcsr[   s    rT   r   z!from_hatch_edge_path.<locals>.wcs  s    DF1Iy9::rU   c                6     t        | d   | d   d            S r   r   )rr   r   s    rT   r   z)from_hatch_edge_path.<locals>.wcs_tangent  s    DF1Iq122rU   c                F    rj                   rj                  |       S | S r   )r   r   )vec3rZ   s    rT   r   z"from_hatch_edge_path.<locals>._wcs  s     3==::d##KrU   N)r   r2   )r   r3   )r   r4   )r   r5   )rr   r   returnr   )r   r   r   r   )uzr   r8   r   r2   r3   r   r   r   r4   r   r   is_nullr5   rO   r   r   iscloser   append_pathreversedrl   extend_multi_pathrY   )edgesrZ   r[   r   r   r}   rx   rc   loopr   next_segmentr   r   r   r   r   r   s    ``        @@@@@@rT   rH   rH   R  s   " $ 


;3 6I6DD */'+dH%:Lg&4;;')"4yk*(00&t}j)!$<LDJ''<D88L../\*XXl../\2245ZZ 0 01$$T*DZZ 2 23==?D\*~~&&t,#   .U*/X 

t$KrU   c                   t        j                  |       }t        |      dk  r
t               S t        |d         }|dd D ]/  }|j                  j                  |      r|j                  |       1 |r|j                          |S )z9Returns a :class:`Path` object from the given `vertices`.   r   )r   r7   N)r   listrh   r8   r   r   r   rY   )ri   rY   	_verticesrc   rr   s        rT   rJ   rJ     sw    		(#I
9~vil#DAB- !xx'LL ! 

KrU   )distancerR   r   
dxfattribsc             #  ^  K   t        | t              r| g} nt        |       } t        |       dk(  ryt	        |      }t	        | d   j
                        }t        |xs i       }t        j                  |      s0t        ||      \  }}t        j                  | |      } ||d<   ||d<   n|j                  dk7  r|j                  |d<   t        j                  |       D ]N  }t        |      dkD  st        j                  |      }	|	j!                  |j#                  ||      d       |	 P yw)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  xy)rm   )r   r8   r   rh   r   r   dictr   r   _get_ocsr:   transform_paths_to_ocsro   single_pathsr   newappend_points
flattening
r   r  rR   r   r  reference_pointrZ   r[   rc   r   s
             rT   r?   r?     s    4 %U
5zQYI58>>*Oj&B'J>>)$!)_=Y,,UC8"+
;"+
;			a	"1"3"3
;""5) t9q=*5AOODOOHh?OMG	s   C*D--A D-c                V    t        |       }|j                  |      j                  }||fS r   )r   from_wcsro   )r   r  rZ   r[   s       rT   r  r  +  s)    
i.C_-//I	>rU   c             #    K   t        | t              r| g} nt        |       } t        |       dk(  ryt	        |      }t	        | d   j
                        }t        |xs i       }t        j                  |      s;t        ||      \  }}t        j                  | |      } t	        dd|      |d<   ||d<   n)|j                  dk7  rt	        dd|j                        |d<   t        j                  |       D ]\  }t        |      dkD  st        j                  |      }	|	j!                  |j#                  ||             |	j%                          |	 ^ yw)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   rh   r   r   r  r   r   r  r:   r  ro   r	  r   r
  append_verticesr  
new_seqendr  s
             rT   r@   r@   1  s&    4 %U
5zQYI58>>*Oj&B'J>>)$!)_=Y,,UC8"&q!Y"7
;"+
;			a	"&q!_->->"?
;""5) t9q=
3AdoohABLLNGs   D EAET)	edge_pathr  rR   g1_tolr   r  c             #     K   |rt        t        |||      }nt        t        ||      }t        t        | |||      E d{    y7 w)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  rR   r  r  rR   N)r   build_edge_pathbuild_poly_path_polygon_converterr    )r   r  r  rR   r  r   r  boundary_factorys           rT   rA   rA   d  sM     B "h&

 #h
 "%0@)ZXXXs   ?A	AA	c             #     K   t        t        ||      }t        |xs i       }|j                  dt        j
                         t        t        | |||      E d{    y7 w)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   BYLAYERr  r-   )r   r  rR   r   r  r  s         rT   rB   rB     s]     : )0(X) j&B'J,6!%)9j  s   AA"A A"c                   |j                   r| j                  |      }t        ||      D ]l  }t        |t              r7|j                  |j                  |j                  |j                                J|d   }|dd  D ]  }	|j                  ||	       |	} n y | j                  t        j                  |j                  ||            |       y )N)r  )r   r   r   r   r7   flags)
has_curvesadd_edge_pathrC   r   r   rv   r   r   r   add_lineadd_polyline_pathr   generater  )

boundariesrc   r"  r  rR   r  r  r   prevr   s
             rT   r  r    s     ,,U3	,T&A 	D$($$#'#6#6;; $

 %  Awab A&&tQ/D	 	$$MM$//(H=>e 	% 	
rU   c                p    | j                  t        j                  |j                  ||            |       y )Nr!  )r&  r   r'  r  )r(  rc   r"  r  rR   s        rT   r  r    s1       dooh9: ! rU   c              #  b  K   t        |t              r|g}nt        |      }t        |      dk(  ry t	        |      }|d   j
                  }t        |xs i       }t        j                  |      s;t        ||      \  }}t        j                  ||      }t	        dd|      |d<   ||d<   n)|j                  dk7  rt	        dd|j                        |d<   |j                  dd       |j                  dd       |j                  dt        j                         t!        t        j"                  |            D ]v  }	t        |	      dk(  r| j%                  |	      }
|
j&                  }|	d   }|j)                           |||d       |	dd  D ]  }|j)                           |||d        |
 x y w)
Nr   r[   r   
solid_fillr7   pattern_nameSOLIDcolorr  )r   r8   r   rh   r   r   r  r   r   r  r:   r  ro   r  r   r  r;   r	  r
  r   rY   )clsr   add_boundaryr   r  r  _dxfattribsrZ   r[   grouppolygonr(  externalholes                 rT   r  r    s     %U
5zQYIAhnnOZ-2.K>>)$!)_=Y,,UC8#'1i#8K #,K 			a	#'1o.?.?#@K <+>737EMM2U//67 u:?''['1]]
8Z1-!"I 	.DJJLT1-	. s   F-F/)r  rR   r  c             #  ^  K   t        | t              r| g} t        |xs i       }t        j                  |d<   t        j                  |       D ]\  }t        |      dkD  st        j                  |      }|j                  |j                  ||             |j                          | ^ yw)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

    r"  r   r  N)r   r8   r  r   POLYLINE_3D_POLYLINEr:   r	  rh   r   r
  r  r  r  )r   r  rR   r  rc   r   s         rT   r>   r>     s     ( %j&B'J44Jw""5) t9q=
3AdoohABLLNGs   AB-AB-c             #  *  K   t        | t              r| g} t        |xs i       }d}t        j                  |       D ]S  }t        |      dk(  r|j                  ||      D ]+  }||}||d<   ||d<   t        j                  |       |}- d}U yw)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	  rh   r  r!   r
  )r   r  rR   r  prev_vertexrc   rr   s          rT   r=   r=   0  s     & %j&B'JK""5) t9>ooh9 	!F"$"-Jw &Ju((j11 K	! s   BBr   	PathPartsc              #    	
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      }n2|j
                  t        j                  k(  r||j                  f}nt         |j#                  |       |j                  }  g g 
|D ]q  }t%        |t&              r3r |       E d{    j)                          
j#                  |       F
r |        
j)                          j#                  |       s r |       E d{    
r
 |        yy7 r7 w)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                 P    d   d   g} D ]  }| j                  |d           | S r   )append)rk   r   rq   s     rT   to_verticesz-to_bsplines_and_vertices.<locals>.to_verticesg  s7    1+a.! 	#DMM$q'"	#rU   c               3     K   d   } | g}dd  D ]0  }t        | |      r|j                  |       n |       |g}|} 2 |r |       y y wr   )r   r?  )b1_g1_continuity_curvesb2bezierr=  r  s      rT   
to_bsplinez,to_bsplines_and_vertices.<locals>.to_bsplinem  sv     AY!#* 	B/B?%,,R0'(=>>)+%B	 !#$9:: !s   AAN)
ezdxf.mathr=  r:   r	  r   r   r9   	CURVE3_TOr   ctrlr   	CURVE4_TOr   ctrl1ctrl2LINE_TO
ValueErrorr?  r   tupleclear)rc   r  r@  rF  curvesr)  cmdcurverE  r=  rq   s    `      @@@rT   rC   rC   X  sy     -; F""D6* zz 
	Cxx7,,, $#''!:;W... $		399cgg!FGW__,sww  MM% 77D
	 FH 
!eU#%<''OOE"!m# MM% 
! <m  ( 	 s%   EF?F;	A F?)F=*F?=F?)r  r  c             #    K   t        | t              r| g} t        |xs i       }t        j                  |       D ]  }t        ||      D ]  }t        |t              r,t        j                  |      }|j                  |       | ?t        |      }t        j                  |d<   t        j                  |      }|j                  |       |j                          |   yw)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  r"  N)r   r8   r  r:   r	  rC   r   r"   r
  apply_construction_toolr   r8  r   r  r  )r   r  r  rc   datarx   attribsrq   s           rT   rD   rD     s     $ %j&B'J""5) ,T6: 	D$(z:..t4z*#(#=#= #<<:>((.##%	s   C$C&)r7   rK   )rR   intrS   rX  r   r8   )ra   r   r   r8   )rq   r   r   r8   )rx   r"   r   r8   )r}   r#   r   r8   )r   r!   r   r8   )r   r$   r   r8   )r   r%   r   r8   )r   z'Solid'r   r8   )r   z
'Viewport'r   r8   )r   z'Image'r   r8   )r   r    r   r8   )r   r6   r   r   r   zIterator[Path])
r   r/   rZ   Optional[OCS]r[   r   r   r   r   r8   )Nr   )rq   r0   rZ   rY  r[   r   r   r8   )r   r1   rZ   rY  r[   r   r   r8   )F)ri   zIterable[UVec]r   r8   )
r   Iterable[Path]r  r   rR   rX  r   r   r   zIterator[LWPolyline])r   r   r  r   r   ztuple[OCS, float])
r   rZ  r  r   rR   rX  r   r   r   Iterator[Polyline])r   rZ  r  boolr  r   rR   rX  r  r   r   r   r   zIterator[Hatch])
r   rZ  r  r   rR   rX  r   r   r   zIterator[MPolygon])r(  r.   rc   r8   r"  rX  r  r   rR   rX  r  r   )
r(  r.   rc   r8   r"  rX  r  r   rR   rX  )
r0  zType[TPolygon]r   rZ  r1  BoundaryFactoryr   r   r   zIterator[TPolygon])r   rZ  r  r   rR   rX  r   r[  )r   rZ  r  r   rR   rX  r   zIterator[Line])rc   r8   r  r   r   zIterator[PathParts])r   rZ  r  r   r   z!Iterator[Union[Spline, Polyline]])o
__future__r   typingr   r   r   r   r   r	   r
   r   typing_extensionsr   	functoolsr   r   loggingrG  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   rc   r8   commandsr9    r:   nestingr;   __all__MAX_DISTANCEMIN_SEGMENTSG1_TOLrL   rX  r]  	getLoggerr   r<   registerrd   rs   ry   r~   r   r   r   r   r   r   r   rE   rF   rG   rI   rH   rJ   r?   r  r@   rA   rB   r  r  r  r>   r=   r;  __annotations__rC   rD    rU   rT   <module>rq     s   #	 	 	 ( -            4 .     $ 	:uh/M45t;<			7	# A A( J
  
 H < E
F   G  D  C   F  F
E
E/   /
 HA A G
E@  @ H
E&  && 29  6= $ 	"	  	
 
6 KL!.BG	& VV	V V 
	Vr" # // / 	/
 / /d # 00 0 	0
 0 0l " ,Y,Y ,Y 	,Y
 ,Y ,Y ,Y ,Yd # %% % 	%
 % %P



 
 	

 
 
8
  	
 $ '	'' "' 	' 'Z #   	 H # "" " 	" "J Wd4j01	9 1 :@ CR 	"" "
 '"rU   