
    hZ#                        S SK Jr  S SKJrJr  S SKJr  S SKrS SKr	S SK
JrJrJrJr  S/r  " S S5      rSS jr\" SS	9SS
 j5       rg)    )annotations)IterableSequence)	lru_cacheN)Vec3NULLVECMatrix44UVecBezierc                      \ rS rSrSrSS jr\SS j5       rSSS jjrSSS jjr	SS jr
SS jrSS	 jrSS
 jr    SS jrSS jrSS jrSrg)r   L   u  Generic `Bézier curve`_ of any degree.

A `Bézier curve`_ is a parametric curve used in computer graphics and
related fields. Bézier curves are used to model smooth curves that can be
scaled indefinitely. "Paths", as they are commonly referred to in image
manipulation programs, are combinations of linked Bézier curves.
Paths are not bound by the limits of rasterized images and are intuitive to
modify. (Source: Wikipedia)

This is a generic implementation which works with any count of definition
points greater than 2, but it is a simple and slow implementation. For more
performance look at the specialized :class:`Bezier4P` and :class:`Bezier3P`
classes.

Objects are immutable.

Args:
    defpoints: iterable of definition points as :class:`Vec3` compatible objects.

c                :    [         R                  " U5      U l        g N)r   tuple
_defpoints)self	defpointss     C/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/bezier.py__init__Bezier.__init__b   s    *.**Y*?    c                    U R                   $ )z1Control points as tuple of :class:`Vec3` objects.r   r   s    r   control_pointsBezier.control_pointse   s     r   c                B    U R                  U R                  U5      5      $ )zXApproximates curve by vertices as :class:`Vec3` objects, vertices
count = segments + 1.
)pointsparamsr   segmentss     r   approximateBezier.approximatej   s     {{4;;x011r   c              #  ,  ^ ^^#    SUU U4S jjmSU-  nSnT R                   S   nUv   US:  aa  XC-   n[        R                  " US5      (       a  T R                   S   nSnOT R                  U5      nT" XWXF5       Sh  vN   UnUnUS:  a  M`  gg N7f)a  Adaptive recursive flattening. The argument `segments` is the
minimum count of approximation segments, if the distance from the center
of the approximation segment to the curve is bigger than `distance` the
segment will be subdivided.

Args:
    distance: maximum distance from the center of the curve (Cn)
        to the center of the linear (C1) curve between two
        approximation points to determine if a segment should be
        subdivided.
    segments: minimum segment count

c              3     >#    X#-   S-  nTR                  U5      nU R                  U5      nUR                  U5      T:  a  Uv   g T	" XX$5       S h  vN   T	" XQXC5       S h  vN   g  N N7f)Ng      ?)pointlerpdistance)
start_point	end_pointstart_tend_tmid_t	mid_point	chk_pointr(   r   subdivs
          r   r0   !Bezier.flattening.<locals>.subdiv   ss     _+E

5)I#((3I !!),x7!+'III!)EEE JEs$   AA.A*A.$A,%A.,A.      ?        r   N)r+   floatr,   r5   )r   mathiscloser&   )	r   r(   r!   dtt0r)   t1r*   r0   s	   ``      @r   
flatteningBezier.flatteningp   s     
	F 
	F 8^ooa(3hB||B$$ OOB/	 JJrN	kb===B#K 3h >s   A:B?B BBc              #  V   #    [         R                  " SSUS-   5       Sh  vN   g N7f)zCYield evenly spaced parameters from 0 to 1 for given segment count.r3   r2      N)nplinspacer    s     r   r   Bezier.params   s     ;;sCA666s   )')c                    US:  d  US:  a  [        S5      eSU-
  S:  a  Sn[        nU R                  n[        U5      n[	        U5       H  nU[        US-
  XQ5      X5   -  -  nM     U$ )zKReturns a point for parameter `t` in range [0, 1] as :class:`Vec3`
object.
r3   r2   Parameter t not in range [0, 1]h㈵>r>   )
ValueErrorr   r   lenrangebernstein_basis)r   tr&   ptsnis         r   r&   Bezier.point   st     s7a#g>??!GtAooHqA_QUA1CF::E r   c              #  D   #    U H  nU R                  U5      v   M     g7f)zuYields multiple points for parameters in vector `t` as :class:`Vec3`
objects. Parameters have to be in range [0, 1].
N)r&   r   rI   us      r   r   Bezier.points   s      A**Q-     c                f   US:  d  US:  a  [        S5      eSU-
  S:  a  SnU R                  n[        U5      nUS-
  n[        n[        n[        nX-  nUS-
  n	US:X  a&  XBS   US   -
  -  nXI-  US   SUS   -  -
  US   -   -  n[	        U5       H  n
[        XJU5      nX[X*   -  -  nSUs=:  a  S:  aH  O  OESU-
  nXU-  -
  nXmX-  -  U-  X*   -  -  nUX-  XH-  -
  U
SSU-  -
  -  -
  X-  U-  -  U-  X*   -  -  nUS:X  d  Mu  XBU   X)   -
  -  nXI-  X$   SX)   -  -
  X$S-
     -   -  nM     XVU4$ )	zrReturns (point, 1st derivative, 2nd derivative) tuple for parameter `t`
in range [0, 1] as :class:`Vec3` objects.
r3   r2   rC   rD   r>   r   g       @   )rE   r   rF   r   rG   rH   )r   rI   rJ   rK   n0r&   d1d2t2n0_1rL   tmp_bas_1_ti_n0_ts                 r   
derivativeBezier.derivative   s    s7a#g>??!GtAooHUUAv81vA'Bc!fsSV|3c!f<=BqA%bQ/Gsv%%EQ}}Qw!V)G3cf<<_rw.cC!Gm1DDy4') f Cxr7SY./Y#'A	M"9CQK"GH   "}r   c              #  D   #    U H  nU R                  U5      v   M     g7f)zReturns multiple (point, 1st derivative, 2nd derivative) tuples for
parameter vector  `t` as :class:`Vec3` objects.
Parameters in range [0, 1]
N)r]   rO   s      r   derivativesBezier.derivatives   s       A//!$$ rR   c                P    [        [        [        U R                  5      5      5      $ )u>   Returns a new Bèzier-curve with reversed control point order.)r   listreversedr   r   s    r   reverseBezier.reverse   s    d8D$7$789::r   c                `    [        UR                  U R                  5      5      n[        U5      $ )zGeneral transformation interface, returns a new :class:`Bezier` curve.

Args:
     m: 4x4 transformation matrix (:class:`ezdxf.math.Matrix44`)

)r   transform_verticesr   r   )r   mr   s      r   	transformBezier.transform   s*     !..t/B/BCD	i  r   r   N)r   zIterable[UVec])returnzSequence[Vec3])   )r!   intrl   Iterable[Vec3])   )r(   r5   r!   rn   rl   ro   )r!   rn   rl   Iterable[float])rI   r5   rl   r   )rI   rq   rl   ro   )rI   r5   rl   ztuple[Vec3, Vec3, Vec3])rI   rq   rl   z!Iterable[tuple[Vec3, Vec3, Vec3]])rl   r   )ri   r	   rl   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r"   r;   r   r&   r   r]   r`   re   rj   __static_attributes__ r   r   r   r   L   s`    *@  2($T7  $L% %	*%;!r   c                    US:X  a	  US:X  a  SnO[        X!5      nX:X  a	  US:X  a  SnO[        SU-
  X-
  5      n[        U 5      [        U5      [        X-
  5      -  -  nXS-  U-  $ )Nr3   r   r2   )pow	factorial)rK   rL   rI   titniNis         r   rH   rH      si    CxAFYv!s(37ae%	11	!%(88	9B7S=r   )maxsizec                .    [         R                  " U 5      $ r   )r6   r|   )rK   s    r   r|   r|     s    >>!r   )rK   rn   rL   rn   rI   r5   rl   r5   )rK   rn   )
__future__r   typingr   r   	functoolsr   r6   numpyr?   
ezdxf.mathr   r   r	   r
   __all__r   rH   r|   ry   r   r   <module>r      sV    # %    4 4 *:ze! e!P 4 r   