
    hn                        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	J
r
Jr  SSKJr  S/rSS jr\" S	\\
5      r " S
 S\\   5      rg)    )annotations)IteratorSequenceOptionalGenericTypeVarN   )Vec3Vec2)Matrix44Bezier3Pc                8    SU s=::  a  S::  d  O  [        S5      eg )N              ?zt not in range [0 to 1])
ValueError)ts    F/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/_bezier3p.pycheck_if_in_valid_ranger      s    !?s?233     Tc                      \ rS rSrSrSrSS jr\SS j5       rSS jr	SS jr
SS j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rg)r      u2  Implements an optimized quadratic `Bézier curve`_ for exact 3 control
points.

The class supports points of type :class:`Vec2` and :class:`Vec3` as input, the
class instances are immutable.

Args:
    defpoints: sequence of definition points as :class:`Vec2` or
        :class:`Vec3` compatible objects.

_control_points_offsetc                   ^ [        U5      S:w  a  [        S5      eUS   R                  nUR                  S;  a  [	        SUR                   35      eUS   mTU l        [        U4S jU 5       5      U l        g )N   zThree control points required.r   )r   r
   zinvalid point type: c              3  ,   >#    U  H	  oT-
  v   M     g 7f)N ).0poffsets     r   	<genexpr>$Bezier3P.__init__.<locals>.<genexpr>8   s     3R	1J	s   )lenr   	__class____name__	TypeErrorr   tupler   )self	defpoints
point_typer"   s      @r   __init__Bezier3P.__init__-   sx    y>Q=>>q\++
""&662:3F3F2GHII aL .33R	3R.Rr   c                J    U R                   u  pnU R                  nXBU-   X4-   4$ )zBControl points as tuple of :class:`Vec3` or :class:`Vec2` objects.r   )r*   _p1p2r"   s        r   control_pointsBezier3P.control_points:   s-     ((	rF{BK//r   c                :    [        U5        U R                  U5      $ )u   Returns direction vector of tangent for location `t` at the
Bèzier-curve.

Args:
    t: curve position in the range ``[0, 1]``

)r   _get_curve_tangentr*   r   s     r   tangentBezier3P.tangentB   s     	 "&&q))r   c                :    [        U5        U R                  U5      $ )uk   Returns point for location `t` at the Bèzier-curve.

Args:
    t: curve position in the range ``[0, 1]``

)r   _get_curve_pointr7   s     r   pointBezier3P.pointM   s     	 "$$Q''r   c              #     #    US:  a  [        U5      eSU-  nU R                  nUS   v   [        SU5       H  nU R                  X$-  5      v   M     US   v   g7f)u   Approximate `Bézier curve`_ by vertices, yields `segments` + 1
vertices as ``(x, y[, z])`` tuples.

Args:
    segments: count of segments for approximation

r	   r   r      N)r   r3   ranger;   )r*   segmentsdelta_tcpsegments        r   approximateBezier3P.approximateW   sd      a<X&&x  eQ)G''(9:: *es   AAc                n    SnSnU R                  U5       H  nUb  X#R                  U5      -  nUnM     U$ )uO   Returns estimated length of Bèzier-curve as approximation by line
`segments`.
r   N)rE   distance)r*   rA   length
prev_pointr<   s        r   approximated_lengthBezier3P.approximated_lengthh   sH     "&
%%h/E%--e44J 0 r   c              #    #    / nSU-  nSnU R                   nUS   nUv   US:  a  XT-   n[        R                  " US5      (       a  US   n	SnOU R                  U5      n	 XX-   S-  n
U R                  U
5      nUR	                  U	5      nUR                  U5      nX:  a#  U	v   UnU	nU(       a  UR                  5       u  pOOUR                  X45        U
nUn	Mz  US:  a  M  gg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 quadratic (C2)
        curve to the center of the linear (C1) curve between two
        approximation points to determine if a segment should be
        subdivided.
    segments: minimum segment count

r   r   r   r?   g      ?N)r3   mathiscloser;   lerprH   popappend)r*   rH   rA   stackdtt0rC   start_pointt1	end_pointmid_t	mid_point	chk_pointds                 r   
flatteningBezier3P.flatteningt   s      (*(N  A 3hB||B$$qE	 11"5	 "3#44U;	*//	:	&&y1<#OB"+K(-		ILL"1B )I#  3hs   CC%#C%c                n    U R                   u  p#nSU-
  nSU-  U-  nX-  nX6-  XG-  -   U R                  -   $ )Nr          @r   )r*   r   r0   r1   r2   
_1_minus_tbcs           r   r;   Bezier3P._get_curve_point   sH     ((	r1W
!Gj Ev--r   c                L    U R                   u  p#nSSU-  -
  nSU-  nX5-  XF-  -   $ )Nr`   g      @)r   )r*   r   r0   r1   r2   rb   rc   s          r   r6   Bezier3P._get_curve_tangent   s7     ((	r#'M!Gvr   c                P    [        [        [        U R                  5      5      5      $ )u>   Returns a new Bèzier-curve with reversed control point order.)r   listreversedr3   )r*   s    r   reverseBezier3P.reverse   s    Xd&9&9:;<<r   c                    [         R                  " U R                  5      n[        [	        UR                  U5      5      5      $ )zGeneral transformation interface, returns a new :class:`Bezier3P`
curve and it is always a 3D curve.

Args:
     m: 4x4 transformation :class:`Matrix44`

)r
   generater3   r   r)   transform_vertices)r*   mr+   s      r   	transformBezier3P.transform   s3     MM$"5"56	a229=>??r   N)r+   Sequence[T])returnrr   )r   floatrs   r   )rA   intrs   Iterator[T])   )rA   ru   rs   rt   )   )rH   rt   rA   ru   rs   rv   )rs   zBezier3P[T])ro   r   rs   zBezier3P[Vec3])r'   
__module____qualname____firstlineno____doc__	__slots__r-   propertyr3   r8   r<   rE   rK   r]   r;   r6   rj   rp   __static_attributes__r   r   r   r   r      sW    
 /IS 0 0	*("
0*d	.=	@r   )r   rt   rs   None)
__future__r   typingr   r   r   r   r   rN   _vectorr
   r   	_matrix44r   __all__r   r   r   r   r   r   <module>r      sS    #      ,4
 Ctj@wqz j@r   