
    Ogn                        d dl mZ d dlmZmZmZmZmZ d dlZddl	m
Z
mZ ddlmZ dgZddZ ed	ee
      Z G d
 dee         Zy)    )annotations)IteratorSequenceOptionalGenericTypeVarN   )Vec3Vec2)Matrix44Bezier3Pc                H    d| cxk  rdk  st        d       t        d      y )N              ?zt not in range [0 to 1])
ValueError)ts    Y/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/_bezier3p.pycheck_if_in_valid_ranger      s/    !?s?233 233     Tc                  z    e Zd ZdZdZddZedd       ZddZddZ	ddZ
dddZddd	Zdd
ZddZddZddZy)r   uN  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                    t        |      dk7  rt        d      |d   j                  }|j                  dvrt	        d|j                         |d   | _        t        fd|D              | _        y )N   zThree control points required.r   )r   r
   zinvalid point type: c              3  (   K   | ]	  }|z
    y w)N ).0poffsets     r   	<genexpr>z$Bezier3P.__init__.<locals>.<genexpr>8   s     3R1AJ3Rs   )lenr   	__class____name__	TypeErrorr   tupler   )self	defpoints
point_typer!   s      @r   __init__zBezier3P.__init__-   sx    y>Q=>>q\++
""&662:3F3F2GHII aL .33R	3R.Rr   c                P    | j                   \  }}}| j                  }|||z   ||z   fS )zBControl points as tuple of :class:`Vec3` or :class:`Vec2` objects.r   )r(   _p1p2r!   s        r   control_pointszBezier3P.control_points:   s3     ((	2rrF{BK//r   c                :    t        |       | j                  |      S )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   tangentzBezier3P.tangentB   s     	 "&&q))r   c                :    t        |       | j                  |      S )u   Returns point for location `t` at the Bèzier-curve.

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

        )r   _get_curve_pointr3   s     r   pointzBezier3P.pointM   s     	 "$$Q''r   c              #     K   |dk  rt        |      d|z  }| j                  }|d    t        d|      D ]  }| j                  ||z          |d    yw)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   r0   ranger6   )r(   segmentsdelta_tcpsegments        r   approximatezBezier3P.approximateW   sl      a<X&&x  eQ) 	;G'''(9::	;es   AAc                j    d}d}| j                  |      D ]  }|||j                  |      z  }|} |S )u_   Returns estimated length of Bèzier-curve as approximation by line
        `segments`.
        r   N)r?   distance)r(   r;   length
prev_pointr7   s        r   approximated_lengthzBezier3P.approximated_lengthh   sO     "&
%%h/ 	E%*--e44J	 r   c              #    K   g }d|z  }d}| j                   }|d   }| |dk  r||z   }t        j                  |d      r|d   }	d}n| j                  |      }		 ||z   dz  }
| j                  |
      }|j	                  |	      }|j                  |      }||k  r|	 |}|	}|r|j                         \  }}	nn|j                  ||	f       |
}|}	w|dk  ryyw)aB  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   r9   g      ?N)r0   mathiscloser6   lerprA   popappend)r(   rA   r;   stackdtt0r=   start_pointt1	end_pointmid_t	mid_point	chk_pointds                 r   
flatteningzBezier3P.flatteningt   s     (*(N  A 3hbB||B$qE	 11"5	 "R3#44U;	*//	:	&&y1x<#OB"+K(-		ILL"i1B )I#  3hs   CCCc                v    | j                   \  }}}d|z
  }d|z  |z  }||z  }||z  ||z  z   | j                  z   S )Nr          @r   )r(   r   r-   r.   r/   
_1_minus_tbcs           r   r6   zBezier3P._get_curve_point   sP     ((	2r1W
!Gj EAvQ--r   c                R    | j                   \  }}}dd|z  z
  }d|z  }||z  ||z  z   S )NrW   g      @)r   )r(   r   r-   r.   r/   rY   rZ   s          r   r2   zBezier3P._get_curve_tangent   s=     ((	2r#'M!GAvQr   c                P    t        t        t        | j                                    S )u>   Returns a new Bèzier-curve with reversed control point order.)r   listreversedr0   )r(   s    r   reversezBezier3P.reverse   s    Xd&9&9:;<<r   c                    t        j                  | j                        }t        t	        |j                  |                  S )zGeneral transformation interface, returns a new :class:`Bezier3P`
        curve and it is always a 3D curve.

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

        )r
   generater0   r   r'   transform_vertices)r(   mr)   s      r   	transformzBezier3P.transform   s3     MM$"5"56	a229=>??r   N)r)   Sequence[T])returnre   )r   floatrf   r   )r;   intrf   Iterator[T])   )r;   rh   rf   rg   )   )rA   rg   r;   rh   rf   ri   )rf   zBezier3P[T])rc   r   rf   zBezier3P[Vec3])r%   
__module____qualname____doc__	__slots__r+   propertyr0   r4   r7   r?   rD   rU   r6   r2   r_   rd   r   r   r   r   r      sW    
 /IS 0 0	*("
0*d	.=	@r   )r   rg   rf   None)
__future__r   typingr   r   r   r   r   rF   _vectorr
   r   	_matrix44r   __all__r   r   r   r   r   r   <module>rw      sS    #      ,4
 Ctj@wqz j@r   