
    hYC                    n   S SK Jr  S SK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  \(       a  S SKJr  S rS rSS	\R2                  S
-  S4         SS jjrSS	\R2                  S-  \R2                  S-  S4           SS jjr " S S5      r " S S5      r " S S5      rg)    )annotations)TYPE_CHECKINGIterableOptionalN)Vec3Vec2UVecMatrix44perlinBezier4Pglobal_bspline_interpolationBSplineopen_uniform_bsplineclosed_uniform_bsplineEulerSpiral)
BaseLayoutc                >    U S-  [         R                   " 5       U -  -
  $ N       @)random)	max_values    E/var/www/html/env/lib/python3.13/site-packages/ezdxf/render/curves.pyrndr      s    s?V]]_y888    c                l    [         R                  " UR                  UR                  5      nU S-  X -  -
  $ r   )r   snoise2xy)r   walkerrs      r   
rnd_perlinr!      s+    vxx*As?Q]**r   d   g      ?      c              #  0  ^#    X-  mU4S jn[        SS5      nU" 5       n[        U 5       He  nXs-  S:X  a	  Xd" 5       -   nXe-
  R                  nU[        X%5      -   n	U[        R                  " 5       -  n
U[         R
                  " X5      -   nUv   Mg     g7f)u=  Returns a random 2D path as iterable of :class:`~ezdxf.math.Vec2`
objects.

Args:
    steps: count of vertices to generate
    max_step_size: max step size
    max_heading: limit heading angle change per step to ± max_heading/2 in
        radians
    retarget: specifies steps before changing global walking target

c                 B   > [        [        T 5      [        T 5      45      $ N)r   r   max_s   r   next_global_target*random_2d_path.<locals>.next_global_target5   s    SYD	*++r   r   N)r   rangeangler!   r   
from_angle)stepsmax_step_sizemax_headingretargetr*   r   targetir-   headinglengthr)   s              @r   random_2d_pathr7   "   s     "  D, !QZF!F5\<1022F''*[990$//':: s   BBr   g       @c              #    ^#    X-  mU4S jn[        5       nU" 5       n[        U 5       H  nX-  S:X  a	  Xu" 5       -   nXv-
  R                  n	U[        R                  " 5       -  n
U	[	        X&5      -   n[         R
                  " X5      n[	        X65      nU[        R                  " U5      R                  U5      -  nUv   M     g7f)u  Returns a random 3D path as iterable of :class:`~ezdxf.math.Vec3`
objects.

Args:
    steps: count of vertices to generate
    max_step_size: max step size
    max_heading: limit heading angle change per step to ± max_heading/2,
        rotation about the z-axis in radians
    max_pitch: limit pitch angle change per step to ± max_pitch/2, rotation
        about the x-axis in radians
    retarget: specifies steps before changing global walking target

c                 V   > [        [        T 5      [        T 5      [        T 5      45      $ r'   )r   r   r(   s   r   r*   *random_3d_path.<locals>.next_global_targetZ   s!    SYD	3t9566r   r   N)	r   r,   r-   r   r!   r.   r
   x_rotate	transform)r/   r0   r1   	max_pitchr2   r*   r   r3   r4   r-   r6   heading_angle	next_steppitch_angler)   s                 @r   random_3d_pathrA   D   s     (  D7 VF!F5\<1022F''0
; ??OOM:	 3(##K0::9EE s   CCc                      \ rS rSrSr " S S5      rSS jrSS jr  S       SS jjrSS	 jr	  S     SS
 jjr
Srg)Bezierk   a  Render a bezier curve as 2D/3D :class:`~ezdxf.entities.Polyline`.

The :class:`Bezier` class is implemented with multiple segments, each
segment is an optimized 4 point bezier curve, the 4 control points of the
curve are: the start point (1) and the end point (4), point (2) is start
point + start vector and point (3) is end point + end vector. Each segment
has its own approximation count.

.. seealso::

    The new :mod:`ezdxf.path` package provides many advanced construction tools
    based on the :class:`~ezdxf.path.Path` class.

c                  <    \ rS rSr          SS jrSS jrSrg)Bezier.Segment{   c                    [        U5      U l        [        U5      U l        [        U5      U l        [        U5      U l        XPl        g r'   )r   startendstart_tangentend_tangentsegments)selfrI   rJ   rK   rL   rM   s         r   __init__Bezier.Segment.__init__|   s>     eDJCyDH!%"D  $K0D$Mr   c                    U R                   U R                   U R                  -   U R                  U R                  -   U R                  /n[	        U5      nUR                  U R                  5      $ r'   )rI   rK   rJ   rL   r   approximaterM   )rN   control_pointsbeziers      r   rR   Bezier.Segment.approximate   s\    



T///4+++	N n-F%%dmm44r   )rJ   rL   rM   rI   rK   N)
rI   r	   rJ   r	   rK   r	   rL   r	   rM   int)returnIterable[Vec3])__name__
__module____qualname____firstlineno__rO   rR   __static_attributes__ r   r   SegmentrF   {   s<    	%	% 	%  		%
 	% 	% 	5r   r_   c                    / U l         g r'   points)rN   s    r   rO   Bezier.__init__   s      	r   c                T    U R                   R                  [        U5      SUS45        g)zSet start point and start tangent.

Args:
    point: start point
    tangent: start tangent as vector, example: (5, 0, 0) means a
             horizontal tangent with a length of 5 drawing units
N)rb   appendr   )rN   pointtangents      r   rI   Bezier.start   s#     	DKw=>r   Nc                    [        U5      nUc  U* nO[        U5      nU R                  R                  [        U5      X#[        U5      45        g)a  Append a control point with two control tangents.

Args:
    point: control point
    tangent1: first tangent as vector "left" of the control point
    tangent2: second tangent as vector "right" of the control point,
        if omitted `tangent2` = `-tangent1`
    segments: count of line segments for the polyline approximation,
        count of line segments from the previous control point to the
        appended control point.

N)r   rb   re   rV   )rN   rf   tangent1tangent2rM   s        r   re   Bezier.append   sD    & > yHH~HDKS]KLr   c              #    #    [        U R                  5      S:  ab  [        U R                  S S U R                  SS  5       H7  u  pUS   nUS   nUS   nUS   nUS   n[        R	                  X5XFU5      v   M9     g [        S5      e7f)N   r   r#      zTwo or more points needed!)lenrb   ziprC   r_   
ValueError)rN   
from_pointto_pointstart_pointrK   	end_pointrL   counts           r   _build_bezier_segmentsBezier._build_bezier_segments   s     t{{a(+DKK,<dkk!"o(N$
(m *1$QK	&qk nnM  )O 9::s   BB	c                    / nU R                  5        H"  nUR                  UR                  5       5        M$     U(       d  [        S U 5       5      (       a  UR	                  XCS9  gUR                  XCS9  g)zRender Bezier curve as 2D/3D :class:`~ezdxf.entities.Polyline`.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    force3d: force 3D polyline rendering
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

c              3  *   #    U  H	  oS    v   M     g7f)r#   Nr^   ).0ps     r   	<genexpr> Bezier.render.<locals>.<genexpr>   s     /1A$s   
dxfattribsN)ry   extendrR   anyadd_polyline3dadd_polyline2d)rN   layoutforce3dr   rb   segments         r   renderBezier.render   sf      224GMM'--/0 5c////!!&!@!!&!@r   ra   )rW   None)rf   r	   rg   r	   rW   r   )Nr$   )rf   r	   rj   r	   rk   zOptional[UVec]rM   rV   )rW   zIterable[Segment])FN)r   r   r   boolrW   r   )rY   rZ   r[   r\   __doc__r_   rO   rI   re   ry   r   r]   r^   r   r   rC   rC   k   s    5 56? $(MM M !	M
 M4;" 	AA A
 
A Ar   rC   c                     \ rS rSrSr S   SS jjrSSS jjr   S         SS jjr\r S     SS jjr	 S     SS jjr
 S     SS	 jjr  S       SS
 jjr  S       SS jjr  S       SS jjrSrg)Spline   a	  This class can be used to render B-splines into DXF R12 files as
approximated :class:`~ezdxf.entities.Polyline` entities.
The advantage of this class over the :class:`R12Spline` class is,
that this is a real 3D curve, which means that the B-spline vertices do
have to be located in a flat plane, and no :ref:`UCS` class is needed to
place the curve in 3D space.

.. seealso::

    The newer :class:`~ezdxf.math.BSpline` class provides the
    advanced vertex interpolation method :meth:`~ezdxf.math.BSpline.flattening`.

Nc                d    Uc  / n[         R                  " U5      U l        [        U5      U l        g)z
Args:
    points: spline definition points
    segments: count of line segments for approximation, vertex count is
        `segments` + 1

N)r   listrb   rV   rM   )rN   rb   rM   s      r   rO   Spline.__init__   s)     >F"&))F"3Hr   c                D    [        U R                  5      S-
  U-  U l        g)a4  Calculate overall segment count, where segments is the sub-segment
count, `segments` = 4, means 4 line segments between two definition
points e.g. 4 definition points and 4 segments = 12 overall segments,
useful for fit point rendering.

Args:
    segments: sub-segments count between two definition points

rn   N)rq   rb   rM   )rN   rM   s     r   	subdivideSpline.subdivide  s     T[[)A-9r   c                    [        U R                  X#S9n[        UR                  U R                  5      5      n[        S U 5       5      (       a  UR                  XdS9  gUR                  XdS9  g)a<  Render a B-spline as 2D/3D :class:`~ezdxf.entities.Polyline`, where
the definition points are fit points.

   - 2D spline vertices uses: :meth:`~ezdxf.layouts.BaseLayout.add_polyline2d`
   - 3D spline vertices uses: :meth:`~ezdxf.layouts.BaseLayout.add_polyline3d`

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    degree: degree of B-spline (order = `degree` + 1)
    method: "uniform", "distance"/"chord", "centripetal"/"sqrt_chord" or
        "arc" calculation method for parameter t
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

)degreemethodc              3  >   #    U  H  oR                   S :g  v   M     g7f)g        N)z)r}   vertexs     r   r   .Spline.render_as_fit_points.<locals>.<genexpr>(  s     6X6xx3Xs   r   N)r   rb   r   rR   rM   r   r   r   )rN   r   r   r   r   splineverticess          r   render_as_fit_pointsSpline.render_as_fit_points  se    * .KK
 **4==9:6X666!!(!B!!(!Br   c                    [        U R                  US-   S9nUR                  [        UR	                  U R
                  5      5      US9  g)a(  Render an open uniform B-spline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   orderr   Nr   rb   r   r   rR   rM   rN   r   r   r   r   s        r   render_open_bsplineSpline.render_open_bspline/  sD     FQJ7##DMM23
 	 	
r   c                    [        U R                  US-   S9nUR                  [        UR	                  U R
                  5      5      US9  g)a"  Render a uniform B-spline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   r   r   N)r   rb   r   r   rR   rM   r   s        r   render_uniform_bsplineSpline.render_uniform_bspline@  sD     &dkk!D##DMM23
 	 	
r   c                    [        U R                  US-   S9nUR                  [        UR	                  U R
                  5      5      US9  g)a)  Render a closed uniform B-spline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   r   r   Nr   rb   r   r   rR   rM   r   s        r   render_closed_bsplineSpline.render_closed_bsplineQ  sD     (6A:F##DMM23
 	 	
r   c                    [        U R                  US-   US9nUR                  [        UR	                  U R
                  5      5      US9  g)a  Render a rational open uniform BSpline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    weights: list of weights, requires a weight value (float) for each
        definition point.
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   r   weightsr   Nr   rN   r   r   r   r   r   s         r   render_open_rbsplineSpline.render_open_rbsplineb  sF    $ FQJH##DMM23
 	 	
r   c                    [        U R                  US-   US9nUR                  [        UR	                  U R
                  5      5      US9  g)a  Render a rational uniform B-spline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    weights: list of weights, requires a weight value (float) for each
        definition point.
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   r   r   Nr   r   s         r   render_uniform_rbsplineSpline.render_uniform_rbspliney  K    $ (KKvz7
 	##DMM23
 	 	
r   c                    [        U R                  US-   US9nUR                  [        UR	                  U R
                  5      5      US9  g)a  Render a rational B-spline as 3D :class:`~ezdxf.entities.Polyline`.
Definition points are control points.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    weights: list of weights, requires a weight value (float) for each
        definition point.
    degree: degree of B-spline (order = `degree` + 1)
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

rn   r   r   Nr   r   s         r   render_closed_rbsplineSpline.render_closed_rbspline  r   r   )rb   rM   )Nr"   )rb   zOptional[Iterable[UVec]]rM   rV   )   )rM   rV   rW   r   )rp   chordN)
r   r   r   rV   r   strr   zOptional[dict]rW   r   )rp   N)r   r   r   rV   rW   r   )r   r   r   zIterable[float]r   rV   rW   r   )rY   rZ   r[   r\   r   rO   r   r   r   r   r   r   r   r   r   r]   r^   r   r   r   r      s|    HK&.&AD&
: %)CC C 	C
 #C 
C< "F ?C
 
*-
	
$ ?C
 
*-
	
$ ?C
 
*-
	
* 

 !
 	
 

6 

 !
 	
 

: 

 !
 	
 

 
r   r   c                  t    \ rS rSrSrSS	S jjr    S
       SS jjr     S         SS jjrSrg)r   i  zRender an `euler spiral <https://en.wikipedia.org/wiki/Euler_spiral>`_
as a 3D :class:`~ezdxf.entities.Polyline` or a
:class:`~ezdxf.entities.Spline` entity.

This is a parametric curve, which always starts at the origin (0, 0).

c                6    [        [        U5      5      U l        g)z+
Args:
    curvature: Radius of curvature

N)_EulerSpiralfloatspiral)rN   	curvatures     r   rO   EulerSpiral.__init__  s     #5#34r   Nc                    U R                   R                  X#5      nUb  UR                  U5      nUR                  [	        U5      US9$ )a  Render curve as :class:`~ezdxf.entities.Polyline`.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    length: length measured along the spiral curve from its initial position
    segments: count of line segments to use, vertex count is `segments` + 1
    matrix: transformation matrix as :class:`~ezdxf.math.Matrix44`
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Polyline`

Returns:
    :class:`~ezdxf.entities.Polyline`

r   )r   rR   transform_verticesr   r   )rN   r   r6   rM   matrixr   rb   s          r   render_polylineEulerSpiral.render_polyline  sH    * ((:..v6F$$T&\j$IIr   c                    U R                   R                  X#US9nUR                  nUb  UR                  U5      nUR	                  UUR
                  UR                  5       US9$ )a  
Render curve as :class:`~ezdxf.entities.Spline`.

Args:
    layout: :class:`~ezdxf.layouts.BaseLayout` object
    length: length measured along the spiral curve from its initial position
    fit_points: count of spline fit points to use
    degree: degree of B-spline
    matrix: transformation matrix as :class:`~ezdxf.math.Matrix44`
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.Spline`

Returns:
    :class:`~ezdxf.entities.Spline`

)r   )rS   r   knotsr   )r   bsplinerS   r   add_open_spliner   r   )	rN   r   r6   
fit_pointsr   r   r   r   rb   s	            r   render_splineEulerSpiral.render_spline  sl    0 $$V$G&&..v6F%%!==,,.!	 & 
 	
r   )r   )rn   )r   r   )rn   r"   NN)r   r   r6   r   rM   rV   r   Optional[Matrix44])rn   
   rp   NN)
r   r   r6   r   r   rV   r   rV   r   r   )	rY   rZ   r[   r\   r   rO   r   r   r]   r^   r   r   r   r     s    5 %)JJ J 	J
 #J: %)!
!
 !
 	!

 !
 #!
 !
r   r   )
r/   rV   r0   r   r1   r   r2   rV   rW   zIterable[Vec2])r/   rV   r0   r   r1   r   r=   r   r2   rV   rW   rX   )
__future__r   typingr   r   r   r   math
ezdxf.mathr   r   r	   r
   r   r   r   r   r   r   r   r   ezdxf.layoutsr   r   r!   pir7   rA   rC   r   r^   r   r   <module>r      s   # 4 4      (9+ 1	  	
 F 3ww}$$$ $ 	$
 $ $NwA wAtD
 D
NL
 L
r   