
    h                       S SK Jr  S SKJrJrJrJrJr  S SKrS SK	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JrJrJrJrJrJrJr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*  \(       a  S SK"J#r#  S SK+J,r,  / SQr-Sr.Sr/Sr0Sr1S<S jr2S=S jr3S>S jr4S?S jr5SS.S@S jjr6SAS jr7  SB         SCS jjr8SDS jr9SDS jr:\.\/\SS.           SES jjr;SS\SS.           SES jjr<S\.\/\0\SS .               SFS! jjr=\.\/\SS.           SES" jjr>\.\/SS#.         SGS$ jjr?\.\/SS#.         SGS% jjr@\0SS&.       SHS' jjrA SI     SJS( jjrBSKS) jrCSLS* jrD SM             SNS+ jjrESOSPS, jjrFS-S.S/.     SQS0 jjrGSRS1 jrHSRS2 jrISSSTS3 jjrJSUS4 jrKSVS5 jrLSWS6 jrMSXSYS7 jjrNSZS8 jrOS[S9 jrP S\       S]S: jjrQS^S_S; jjrRg)`    )annotations)TYPE_CHECKINGIterableIteratorOptionalSequenceN)Vec2Vec3UVecZ_AXISOCSUCSMatrix44BoundingBoxConstructionEllipsecubic_bezier_from_ellipseBezier4PBezier3PBSplinereverse_bezier_curvesbulge_to_arclinear_vertex_spacinginscribe_circle_tangent_lengthcubic_bezier_arc_parameterscubic_bezier_bboxquadratic_bezier_bbox)mapbox_earcut_2d)EntityQuery   )Path)Command)	converternesting)GenericLayoutType)bboxprecise_bboxfit_paths_into_boxtransform_pathstransform_paths_to_ocsrender_lwpolylinesrender_polylines2drender_polylines3drender_linesrender_hatchesrender_mpolygonsrender_splines_and_polylinesadd_bezier4padd_bezier3padd_ellipseadd_2d_polyline
add_splineto_multi_pathsingle_pathshave_close_control_verticeslines_to_curve3lines_to_curve4filletpolygonal_filletchamferchamfer2triangulateis_rectangular{Gz?   g-C6?g|=c                N    [        5       nU  H  nUR                  U5        M     U$ )zxReturns a multi-path object from all given paths and their sub-paths.
Ignores paths without any commands (empty paths).
)r    extend_multi_path)paths
multi_pathps      B/var/www/html/env/lib/python3.13/site-packages/ezdxf/path/tools.pyr6   r6   U   s)     J$$Q'     c              #     #    U  H2  nUR                   (       a  UR                  5        Sh  vN   M.  Uv   M4     g N7f)zBYields all given paths and their sub-paths as single path objects.N)has_sub_paths	sub_paths)rE   rG   s     rH   r7   r7   _   s-     ??{{}$$G	 $s   *><>c                N    U  Vs/ s H  o"R                  U5      PM     sn$ s  snf )a  Transform multiple path objects at once by transformation
matrix `m`. Returns a list of the transformed path objects.

Args:
    paths: iterable of :class:`Path` or :class:`Path2d` objects
    m: transformation matrix of type :class:`~ezdxf.math.Matrix44`

)	transform)rE   mrG   s      rH   r(   r(   h   s"     %**EqKKNE***s   "c                l    UR                   R                  5       nUR                  5         [        X5      $ )a   Transform multiple :class:`Path` objects at once from WCS to OCS.
Returns a list of the transformed :class:`Path` objects.

Args:
    paths: iterable of :class:`Path` or :class:`Path2d` objects
    ocs: OCS transformation of type :class:`~ezdxf.math.OCS`

)matrixcopy	transposer(   )rE   ocsts      rH   r)   r)   t   s(     	

AKKM5$$rI   Ffastc                  [        5       nU  Hp  nU(       a!  UR                  UR                  5       5        M+  [        U5      nUR                  (       d  MI  UR                  UR
                  UR                  45        Mr     U$ )u=  Returns the :class:`~ezdxf.math.BoundingBox` for the given paths.

Args:
    paths: iterable of :class:`Path` or :class:`Path2d` objects
    fast: calculates the precise bounding box of Bèzier curves if
        ``False``, otherwise uses the control points of Bézier curves to
        determine their bounding box.

)r   extendcontrol_verticesr&   has_dataextminextmax)rE   rW   boxrG   bbs        rH   r%   r%      s_     -CJJq))+,aB{{{

BIIryy12  JrI   c           	        [        U 5      S:X  a
  [        5       $ U R                  nU/nU R                  5        GH  nUR                  [
        R                  :X  a  UR                  UR                  5        GOBUR                  [
        R                  :X  al  [        [        XR                  UR                  UR                  45      5      nUR                  UR                  5        UR                  UR                  5        OUR                  [
        R                   :X  aa  [#        [%        XR&                  UR                  45      5      nUR                  UR                  5        UR                  UR                  5        O9UR                  [
        R(                  :X  a  UR                  UR                  5        UR                  nGM     [        U5      $ )zIReturns the precise :class:`~ezdxf.math.BoundingBox` for the given paths.r   )lenr   startcommandstyper!   LINE_TOappendend	CURVE4_TOr   r   ctrl1ctrl2r\   r]   	CURVE3_TOr   r   ctrlMOVE_TO)pathrb   pointscmdr_   s        rH   r&   r&      s2   
4yA~}JJEF}}88w&MM#''"XX***"%CIIsww?@B MM"))$MM"))$XX***&x#''0J'KLBMM"))$MM"))$XX(MM#''" " vrI   Tc                   [        U 5      n [        U 5      S:X  a  U $ Uc  [        U SS9nOUnUR                  (       a  UR                  S:X  a  U $ [        U5      nUS:X  d  [        U5      S:  a  [        S5      eU(       a  [        UR                  U5      u  pgnO[        UR                  U5      u  pgn[        R                  " XgU5      n	[        X	5      $ )a  Scale the given `paths` to fit into a box of the given `size`,
so that all path vertices are inside these borders.
If `source_box` is ``None`` the default source bounding box is calculated
from the control points of the `paths`.

`Note:` if the target size has a z-size of 0, the `paths` are
projected into the xy-plane, same is true for the x-size, projects into
the yz-plane and the y-size, projects into and xz-plane.

Args:
    paths: iterable of :class:`~ezdxf.path.Path` objects
    size: target box size as tuple of x-, y- and z-size values
    uniform: ``True`` for uniform scaling
    source_box: pass precalculated source bounding box, or ``None`` to
        calculate the default source bounding box from the control vertices

r   TrV   )r   r   r   zinvalid target size)listra   r%   r[   sizer
   min
ValueError_get_uniform_scaling_get_non_uniform_scalingr   scaler(   )
rE   rs   uniform
source_boxcurrent_boxtarget_sizesxsyszrO   s
             rH   r'   r'      s    . KE
5zQ5t, ;#3#3y#@t*Ki3{#3a#7.//)+*:*:KH
-k.>.>L
rr"A5$$rI   c                   Sn[         R                  nU R                  U:  a)  UR                  U:  a  UR                  U R                  -  n[         R                  nU R                  U:  a)  UR                  U:  a  UR                  U R                  -  n[         R                  nU R                  U:  a)  UR                  U:  a  UR                  U R                  -  n[        X4U5      nU[         R                  L a  [        S5      eUR                  U:  a  UOSnUR                  U:  a  UOSnUR                  U:  a  UOSnX4U4$ )Nư>zinternal errorr   )mathinfxyzrt   ArithmeticError)current_sizer|   TOLscale_xscale_yscale_zuniform_scales          rH   rv   rv      s   
ChhG~~ 3--,..0hhG~~ 3--,..0hhG~~ 3--,..0'2M .//*}}s2mG*}}s2mG*}}s2mGW$$rI   c                   SnSnU R                   U:  a  UR                   U R                   -  nSnU R                  U:  a  UR                  U R                  -  nSnU R                  U:  a  UR                  U R                  -  nX4U4$ )Nr   g      ?)r   r   r   )r   r|   r   r   r   r   s         rH   rw   rw      s{    
CG~~--,..0G~~--,..0G~~--,..0W$$rI   distancesegments	extrusion
dxfattribsc          
         [        [        R                  " UUUUUS95      nU H  nU R                  U5        M     [	        U5      $ )u  Render the given `paths` into `layout` as
: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:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path` or :class:`Path2d` 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:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_lwpolylines
add_entityr   )layoutrE   r   r   r   r   lwpolylines
lwpolylines           rH   r*   r*     P    8   !	
K "
*% "{##rI   c          
         [        [        R                  " UUUUUS95      nU H  nU R                  U5        M     [	        U5      $ )u  Render the given `paths` into `layout` as 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:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path` or :class:`Path2d` 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:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_polylines2dr   r   )r   rE   r   r   r   r   polylines2d
polyline2ds           rH   r+   r+   -  r   rI   	edge_pathr   r   g1_tolr   r   c                   [        [        R                  " UUUUUUUS95      nU H  n	U R                  U	5        M     [	        U5      $ )u  Render the given `paths` into `layout` as
:class:`~ezdxf.entities.Hatch` 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:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path` or :class:`Path2d`  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 polyline paths
    g1_tol: tolerance for G1 continuity check to separate SPLINE edges
    extrusion: extrusion vector for all paths
    dxfattribs: additional DXF attribs

Returns:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   
to_hatchesr   r   )
r   rE   r   r   r   r   r   r   hatcheshatchs
             rH   r.   r.   W  sW    B !	

G %  wrI   c          
         [        [        R                  " UUUUUS95      nU H  nU R                  U5        M     [	        U5      $ )uz  Render the given `paths` into `layout` as
:class:`~ezdxf.entities.MPolygon` entities. The MPOLYGON entity 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:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path` or :class:`Path2d` objects
    distance:  maximum distance, see :meth:`Path.flattening`
    segments: minimum segment count per Bézier curve to flatten polyline paths
    extrusion: extrusion vector for all paths
    dxfattribs: additional DXF attribs

Returns:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_mpolygonsr   r   )r   rE   r   r   r   r   polygonspolygons           rH   r/   r/     sP    < !	
H '" x  rI   r   r   r   c          	         [        [        R                  " UUUUS95      nU H  nU R                  U5        M     [	        U5      $ )u  Render the given `paths` into `layout` as 3D
:class:`~ezdxf.entities.Polyline` entities.

Args:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path`or :class:`Path2d` objects
    distance:  maximum distance, see :meth:`Path.flattening`
    segments: minimum segment count per Bézier curve
    dxfattribs: additional DXF attribs

Returns:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_polylines3dr   r   )r   rE   r   r   r   polylines3d
polyline3ds          rH   r,   r,     sM    .   !		
K "
*% "{##rI   c          	         [        [        R                  " UUUUS95      nU H  nU R                  U5        M     [	        U5      $ )u  Render the given `paths` into `layout` as
:class:`~ezdxf.entities.Line` entities.

Args:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path`or :class:`Path2d` objects
    distance:  maximum distance, see :meth:`Path.flattening`
    segments: minimum segment count per Bézier curve
    dxfattribs: additional DXF attribs

Returns:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_linesr   r   )r   rE   r   r   r   lineslines          rH   r-   r-     sM    , !		
E $ urI   r   r   c                   [        [        R                  " UUUS95      nU H  nU R                  U5        M     [	        U5      $ )a  Render the given `paths` into `layout` as :class:`~ezdxf.entities.Spline`
and 3D :class:`~ezdxf.entities.Polyline` entities.

Args:
    layout: the modelspace, a paperspace layout or a block definition
    paths: iterable of :class:`Path`or :class:`Path2d` objects
    g1_tol: tolerance for G1 continuity check
    dxfattribs: additional DXF attribs

Returns:
    created entities in an :class:`~ezdxf.query.EntityQuery` object

r   )rr   r"   to_splines_and_polylinesr   r   )r   rE   r   r   entitiesentitys         rH   r0   r0     sJ    ( **!	
H &! x  rI   c                    [        UR                  5      S:  a  g[        U 5      S:X  a  U(       a  UR                  U l        [        U [        X5      5        g)u  Add an elliptical arc as multiple cubic Bèzier-curves to the given
`path`, use :meth:`~ezdxf.math.ConstructionEllipse.from_arc` constructor
of class :class:`~ezdxf.math.ConstructionEllipse` to add circular arcs.

Auto-detect the connection point to the given `path`, if neither the start-
nor the end point of the ellipse is close to the path end point, a line from
the path end point to the ellipse start point will be added automatically
(see :func:`add_bezier4p`).

By default, the start of an **empty** path is set to the start point of
the ellipse, setting argument `reset` to ``False`` prevents this
behavior.

Args:
    path: :class:`~ezdxf.path.Path` object
    ellipse: ellipse parameters as :class:`~ezdxf.math.ConstructionEllipse`
        object
    segments: count of Bèzier-curve segments, at least one segment for
        each quarter (pi/2), ``1`` for as few as possible.
    reset: set start point to start of ellipse if path is empty

&.>Nr   )abs
param_spanra   start_pointrb   r1   r   )rn   ellipser   resets       rH   r3   r3     sD    2 7%
4yA~%((
0CDrI   c                   SnSn[        U5      n[        U5      (       d  gUS   R                  S   nU R                  R	                  U5      (       a  [        U5      nU H  nUR                  u  pgpUR	                  U R                  5      (       d  U R                  U5        UR	                  XrUS9(       a(  UR	                  XUS9(       a  U R                  U5        M  U R                  XGU5        M     g)u'  Add multiple cubic Bèzier-curves to the given `path`.

Auto-detect the connection point to the given `path`, if neither the start-
nor the end point of the curves is close to the path end point, a line from
the path end point to the start point of the first curve will be added
automatically.

V瞯<        Nrel_tolabs_tol)rr   ra   control_pointsrg   iscloser   line_to	curve4_to)	rn   curvesr   r   rg   curverb   ri   rj   s	            rH   r1   r1   ;  s     GG&\Fv;;
*
#
#B
'Cxx&v.#(#7#7 e}}TXX&&LL ===AckkG GR G
 LLNN3u- rI   c                   SnSn[        U5      n[        U5      (       d  gUS   R                  S   nU R                  R	                  U5      (       a  [        U5      nU H  nUR                  u  pgnUR	                  U R                  X#S9(       d  U R                  U5        UR	                  XrUS9(       d  UR	                  XrUS9(       a  U R                  U5        M  U R                  XG5        M     g)u+  Add multiple quadratic Bèzier-curves to the given `path`.

Auto-detect the connection point to the given `path`, if neither the start-
nor the end point of the curves is close to the path end point, a line from
the path end point to the start point of the first curve will be added
automatically.

r   r   Nr   r   )rr   ra   r   rg   r   r   r   	curve3_to)rn   r   r   r   rg   r   rb   rl   s           rH   r2   r2   \  s     GG&\Fv;;
*
#
#B
'Cxx&v. //S}}TXXw}HLL===@CKK7 EP E
 LLNN3% rI   c                P  ^  SU 4S jjn[        T 5      (       a  [        S5      eSnSnU HX  u  pn[        U5      S:  a  Sn[        X5      nUc  UT l        UnUnM2  U(       a
  U" X|X5        OT R                  U5        UnUnMZ     U(       ao  T R                  R                  T R                  [        SS9(       dA  U(       a  U" T R                  T R                  X5        OT R                  T R                  5        UR                  (       d  U(       a  T R                  X45        gg)zQInternal API to add 2D polylines which may include bulges to an
**empty** path.

c                  > U R                  U[        SS9(       a  g [        R                  " US-  5      n[	        XU5      u  pVpxU[        R
                  -  nU[        R
                  -  nXg:  a  U[        R
                  -  n[        [        R                  " XgUS-   5      5      n	/ n
[        U5       Hs  n[        R                  " UU[        [        R                  " X   5      [        R                  " XS-      5      5      nU
R                  [        [        U5      5      5        Mu     U
S   nUR                   S   nUR                  U[        SS9(       a  [#        U
5      n
[%        TU
5        g )Nr   r      r   )r   IS_CLOSE_TOLr   ceilr   taurr   nplinspaceranger   from_arcr   degreesrY   r   r   r   r1   )p1p2bulger   num_bezcenterstart_angle	end_angleradiusanglesr   ir   curve0cp0rn   s                  rH   bulge_to!add_2d_polyline.<locals>.bulge_to  s*   ::b,::))HqL)1=be1L.Y!DHH,(	"!Ibkk+'A+FGwA)22VY'VE]+G MM$8ABC   ##A&;;r<;;*62FT6"rI   zRequires an empty path.Nr   r   r   )r   r
   r   r
   r   floatr   int)ra   ru   r   r
   rb   r   r   rg   r   rN   to_wcs)rn   ro   closerT   	elevationr   r   
prev_point
prev_bulger   r   r   points   `            rH   r4   r4   |  s    #8 4yy233!%JJeu:EQ
DJJJZ
=LL

! $ TZZ'',PQ'RTXXtzz:@LL$
}}	C# "rI   c                R   [        U 5      S:X  a  U(       a  UR                  S5      U l        UR                  S:X  aL  UR                  (       d;  UR
                  (       a*  UR                  5        Vs/ s H  n[        U5      PM     nnOUR                  US9n[        X5        gs  snf )u  Add a B-spline as multiple cubic Bèzier-curves.

Non-rational B-splines of 3rd degree gets a perfect conversion to
cubic Bézier curves with a minimal count of curve segments, all other
B-spline require much more curve segments for approximation.

Auto-detect the connection point to the given `path`, if neither the start-
nor the end point of the B-spline is close to the path end point, a line
from the path end point to the start point of the B-spline will be added
automatically. (see :meth:`add_bezier4p`).

By default, the start of an **empty** path is set to the start point of
the spline, setting argument `reset` to ``False`` prevents this
behavior.

Args:
    path: :class:`~ezdxf.path.Path` object
    spline: B-spline parameters as :class:`~ezdxf.math.BSpline` object
    level: subdivision level of approximation segments
    reset: set start point to start of spline if path is empty

r   r   )levelN)
ra   r   rb   degreeis_rational
is_clampedbezier_decompositionr   cubic_bezier_approximationr1   )rn   spliner   r   ro   r   s         rH   r5   r5     s    . 4yA~%\\!_
}}&"4"49J9J171L1L1NO1Nv(6"1NO222? Ps   1B$r   -q=r   c               ~   ^^ [        UU4S j[        U R                  5       UR                  5       5       5       5      $ )zBReturns ``True`` if the control vertices of given paths are close.c              3  J   >#    U  H  u  pUR                  UTTS 9v   M     g7f)r   N)r   ).0cp_acp_br   r   s      rH   	<genexpr>.have_close_control_vertices.<locals>.<genexpr>  s)      IJD 	T7G<Is    #)allziprZ   )abr   r   s     ``rH   r8   r8     s8      a002A4F4F4HI  rI   c                    [        U SS9$ )uV   Replaces all lines by quadratic Bézier curves.
Returns a new :class:`Path` instance.
r   count_all_lines_to_curvern   s    rH   r9   r9          t1--rI   c                    [        U SS9$ )uR   Replaces all lines by cubic Bézier curves.
Returns a new :class:`Path` instance.
rB   r  r  r  s    rH   r:   r:     r	  rI   c                j   US:X  d  US:X  d
   SU 35       eU R                  5       n[        U5      nUS:X  a
  [        5       $ U R                  n[        R
                  n[        U R                  5      nU H  nUR                  U:X  a  UR                  UR                  5      (       a  US:X  a  UR                  U5        Us  $ O_[        XGR                  U5      nUS:X  a  UR                  US   US   S9  O,UR                  US   US   US   S9  OUR                  U5        UR                  nM     U$ )	NrB   r   zinvalid count: r   r      )rl   )ri   rj   )rc   ra   r    rb   r!   re   rd   r   rg   append_path_elementr   r   r   )	rn   r  cmdsrs   rb   r   new_pathrp   verticess	            rH   r  r    s)   A:!>ug%>>#==?Dt9DqyvJJEooGDJJH88w}}SWW%%19 005#O  1GA:&&x{!&E&& &qk&qk '  ((-1 2 OrI   c                   X-
  R                  5       nX!-
  R                  5       nUR                  U5      (       d  UR                  U* 5      (       a  [        eUR                  U5      n[	        XEU5      nXU-  -   nUR                  U5      n	U	R                  U* 5      R                  U5      n
X-   n[        X* U	S9nU[        R                  U-
  U4$ )N)originuxuz)		normalizer   ZeroDivisionErrorangle_betweenr   crossr   r   pi)p0r   r   r   dir1dir2angletangent_lengtharc_start_pointlocal_z_axis
radius_vec
arc_centerucss                rH   _get_local_fillet_ucsr$  %  s    G DG D||DT\\4%00 t$E3DGN>12O
 ::d#L##TE*44V<J -J
ZKL
ACDGGeOS00rI   c                `  ^ [        U 5      S:  a  [        S5      eTS::  a  [        ST 35      e[        X SS 5       VVs/ s H  u  p#X#4PM
     nnn[        U S   5      n[        XDSS 5       H  u  u  p#u  pg [	        X#UT5      u  pn
UR                  U5        [        SU	5       HC  n[        U
R                  U4S jU 5       5      5      nUR                  US   US   US	   5        ME     M     UR                  U S   5        U$ s  snnf ! [
         a    UR                  U5         M  f = f)
zReturns a :class:`Path` with circular fillets of given `radius` between
straight line segments.

Args:
    points: coordinates of the line segments
    radius: fillet radius

r   )at least 3 not coincident points requiredr   invalid radius: r   Nc              3  ,   >#    U  H	  oT-  v   M     g 7f)N )r   vr   s     rH   r   fillet.<locals>.<genexpr>V  s     0LVVVs   r   r  )ra   ru   r   r    r$  r  r   r   tuplepoints_to_wcsr   )ro   r   r  r   r   rG   r   p3r   r  r#  params
bez_pointss    `           rH   r;   r;   <  s/    6{QDEE{+F8455$'qr
$;<$;&"bX$;E<VAYA!%qr3(2	&;BB&O#K 	
		+1!U;Fs000LV0LLMJKK
2
1z!}E < 4 IIfRjH! =
 ! 	IIbM	s   D:DD-,D-c                l    [        SU5      n[        [        U [        R                  U-  -  5      S5      $ )NrB   r   )maxr   r   r   )r  r  s     rH   _segment_countr3  \  s-    5MEs5DHHu,-.22rI   c                N   [        U 5      S:  a  [        S5      eUS::  a  [        SU 35      e[        X SS 5       VVs/ s H  u  p4X44PM
     nnn[        U S   5      n[        XUSS 5       Hw  u  u  p4u  px [	        X4X5      u  pn[        X5      nX-  n[        US-   5       H<  n[        R                  " X-  U5      nUR                  UR                  U5      5        M>     My     UR                  U S   5        U$ s  snnf ! [
         a    UR                  U5         M  f = f)a@  
Returns a :class:`Path` with polygonal fillets of given `radius` between
straight line segments. The `count` argument defines the vertex count of the
fillet for a full circle.

Args:
    points: coordinates of the line segments
    radius: fillet radius
    count: polygon vertex count for a full circle, minimum is 4

r   r&  r   r'  r   Nr   )ra   ru   r   r    r$  r  r   r3  r   r
   
from_angler   )ro   r   r  r  r   r   rG   r   r.  _r  r#  r   deltar   r!  s                   rH   r<   r<   a  s#    6{QDEE{+F8455$'qr
$;<$;&"bX$;E<VAYA!%qr3(2	1""EMAc "%/ x!|$AF;JIIcjj,- % 4 IIfRjH! =
 ! 	IIbM	s    C?9DD$#D$c                   [        U 5      S:  a  [        S5      e[        X SS 5       VVs/ s H  u  p#X#4PM
     nnn[        U S   5      n[        XDSS 5       H  u  u  p#u  pg X#-
  R	                  5       nXv-
  R	                  5       n	UR                  U	5      (       d  UR                  U	* 5      (       a  [        eUR                  U	5      S-  n
[        US-  [        R                  " U
5      -  5      nUR                  X8U-  -   5        UR                  XiU-  -   5        M     UR                  U S   5        U$ s  snnf ! [         a    UR                  U5         GM  f = f)z
Returns a :class:`Path` with chamfers of given `length` between
straight line segments.

Args:
    points: coordinates of the line segments
    length: chamfer length

r   r&  r   Nr   g       @r   )ra   ru   r   r    r  r   r  r  r   r   sinr   )ro   lengthr  r   r   rG   r   r.  r  r  r  r  s               rH   r=   r=     sF    6{QDEE$'qr
$;<$;&"bX$;E<VAYA!%qr3(2		G&&(DG&&(D||D!!T\\4%%8%8''&&t,s2EVc\TXXe_45A 	
		"q/"			"q/" 4 IIfRjH# = ! 	IIbM	s   D;%BEE! E!c                V   [        U 5      S:  a  [        S5      e[        X SS 5       VVs/ s H  u  p4X44PM
     nnn[        U S   5      n[        XUSS 5       H  u  u  p4u  px X4-
  R	                  5       n	X-
  R	                  5       n
U	R                  U
5      (       d  U	R                  U
* 5      (       a  [        e UR                  XIU-  -   5        UR                  XzU-  -   5        M     UR                  U S   5        U$ s  snnf ! [         a    UR                  U5         M  f = f)a5  
Returns a :class:`Path` with chamfers at the given distances `a` and `b`
from the segment points between straight line segments.

Args:
    points: coordinates of the line segments
    a: distance of the chamfer start point to the segment point
    b: distance of the chamfer end point to the segment point

r   z)at least 3 non-coincident points requiredr   Nr   r   )ra   ru   r   r    r  r   r  r   )ro   r  r  r  r   r   rG   r   r.  r  r  s              rH   r>   r>     s    6{QDEE$'qr
$;<$;&"bX$;E<VAYA!%qr3(2	G&&(DG&&(D||D!!T\\4%%8%8'' &9
 	
		"q/"			"q/" 4 IIfRjH = ! 	IIbM	s   D%AD		D('D(c              #     #    [         R                  " [        U 5      5       HM  nUS   R                  X5      nUSS  Vs/ s H  oUR                  X5      PM     nn[	        XF5       Sh  vN   MO     gs  snf  N7f)u  Tessellate nested 2D paths into triangle-faces. For 3D paths the
projection onto the xy-plane will be triangulated.

Args:
    paths: iterable of nested Path instances
    max_sagitta: maximum distance from the center of the curve to the
        center of the line segment between two approximation points to determine if
        a segment should be subdivided.
    min_segments: minimum segment count per Bézier curve

r   r   N)r#   group_pathsr7   
flatteningr   )rE   max_sagittamin_segmentsr   exteriorrG   holess          rH   r?   r?     sj      &&|E':;1:((CBI!"+N+Qk8+N#H444 <N4s   >A; A4A;*A9+A;c                   U R                  5       n[        U5      S:  a  gUS   R                  US   5      (       a  UR                  5         [        U5      S:w  a  gU(       a>  US   US   -
  n[	        UR
                  5      S:  d  [	        UR                  5      S:  d  gUS   R                  US   5      nUS   R                  US   5      n[        R                  " XE5      (       d  gUS   R                  US   5      nUS   R                  US   5      n[        R                  " XE5      (       d  gUS   R                  US   5      nUS   R                  US   5      n[        R                  " XE5      (       d  gg	)
zReturns ``True`` if `path` is a rectangular quadrilateral (square or
rectangle). If the argument `aligned` is ``True`` all sides of the
quadrilateral have to be parallel to the x- and y-axis.
rB   Fr   r   r   r   r  r   T)	rZ   ra   r   popr   r   r   r   r   )rn   alignedro   
first_sidev1v2s         rH   r@   r@     sU   
 ""$F
6{Qay$$


6{aAY*
JLL!E)S->-F 
		F1I	&B			F1I	&B<<			F1I	&B			F1I	&B<<			F1I	&B			F1I	&B<<rI   )rE   Iterable[Path]returnr    )rE   rI  rJ  rI  )rE   rI  rO   r   rJ  
list[Path])rE   rI  rT   r   rJ  rK  )rE   rI  rJ  r   )rn   r    rJ  r   )TN)
rE   rI  rs   ztuple[float, float, float]ry   boolrz   zOptional[BoundingBox]rJ  rK  )r   r
   r|   r
   )r   r$   rE   rI  r   r   r   r   r   r   rJ  r   )r   r$   rE   rI  r   rL  r   r   r   r   r   r   r   r   rJ  r   )
r   r$   rE   rI  r   r   r   r   rJ  r   )r   r$   rE   rI  r   r   rJ  r   )r   T)rn   r    r   r   rJ  None)rn   r    r   zIterable[Bezier4P]rJ  rM  )rn   r    r   zIterable[Bezier3P]rJ  rM  )r   )rn   r    ro   zIterable[Sequence[float]]r   rL  rT   r   r   r   r   r   rJ  rM  )rB   T)rn   r    r   r   rJ  rM  )r  r    r  r    rJ  rL  )rn   r    rJ  r    )rB   )rn   r    r  r   rJ  r    )rJ  ztuple[Vec3, float, UCS])ro   Sequence[Vec3]r   r   rJ  r    )r  r   r  r   rJ  r   )    )ro   rN  r   r   r  r   rJ  r    )ro   rN  r:  r   rJ  r    )ro   rN  r  r   r  r   rJ  r    )rA      )rE   rI  r?  r   r@  r   rJ  zIterator[Sequence[Vec2]])T)rn   r    rJ  rL  )S
__future__r   typingr   r   r   r   r   r   numpyr   
ezdxf.mathr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ezdxf.math.triangulationr   ezdxf.queryr   rn   r    rc   r!    r"   r#   ezdxf.eztypesr$   __all__MAX_DISTANCEMIN_SEGMENTSG1_TOLr   r6   r7   r(   r)   r%   r&   r'   rv   rw   r*   r+   r.   r/   r,   r-   r0   r3   r1   r2   r4   r5   r8   r9   r:   r  r$  r;   r3  r<   r=   r>   r?   r@   r)  rI   rH   <module>r]     s   #        , 6 #    '/> 		+% ). *: (,	)%)%
$)% )% &	)%
 )%X%*%* # '$'$'$ 	'$
 '$ '$ '$\ '$'$'$ 	'$
 '$ '$ '$\ " . . .  	. 
 .  .  .  .  . j # )!)!)! 	)!
 )! )! )!` # !$!$!$ 	!$
 !$ !$P #     	 
    N !!! 	! !B AEE
E,E	E@.B&L G$
G$%G$ G$ 
	G$
 G$ G$ 
G$TD "&u	..#L1.@3
 F@@ KM55(-5DG55("rI   