
    -i'                     F    d Z ddlZ G d d          Z G d d          ZdS )z:Classes for easy interpolation of trajectories and curves.    Nc                        e Zd ZdZddZd ZdS )InterpolatoraY  Poorman's linear interpolator.

    Parameters
    ----------

    tt : list, optional
      List of time frames for the interpolator.

    ss : list, optional
      List of values for the interpolator.

    ttss : list, optional
      Lists of time frames and their correspondients values for the
      interpolator. This argument can be used instead of ``tt`` and ``ss``
      to instantiate the interpolator using an unique argument.

    left : float, optional
      Value to return when ``t < tt[0]``.

    right : float, optional
      Value to return when ``t > tt[-1]``.


    Examples
    --------

    .. code:: python

        # instantiate using `tt` and `ss`
        interpolator = Interpolator(tt=[0, 1, 2], ss=[3, 4, 5])

        # instantiate using `ttss`
        interpolator = Interpolator(ttss=[[0, 3], [1, 4], [2, 5]])  # [t, value]
    Nc                     |t          | \  }}dt          j        |          z  | _        dt          j        |          z  | _        || _        || _        t          |          t          |          c| _	        | _
        d S N      ?)zipnparrayttssleftrightminmaxtmintmax)selfr   r   ttssr   r   s         _/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/video/tools/interpolators.py__init__zInterpolator.__init__*   sk    $ZFB$$	
"2wwB	4999    c                 Z    t          j        || j        | j        | j        | j                  S )zInterpolates ``t``.

        Parameters
        ----------

        t : float
          Time frame for which the correspondent value will be returned.
        )r	   interpr   r   r   r   r   ts     r   __call__zInterpolator.__call__4   s$     yDGTWdiDDDr   )NNNNN)__name__
__module____qualname____doc__r   r    r   r   r   r      sG        ! !F0 0 0 0	E 	E 	E 	E 	Er   r   c                       e Zd ZdZd Zd Zd Zd Zd ZddZ	d	 Z
ed
             Zed             Zed             ZdS )
Trajectorya=  Trajectory compound by time frames and (x, y) pixels.

    It's designed as an interpolator, so you can get the position at a given
    time ``t``. You can instantiate it from a file using the methods
    ``from_file`` and ``load_list``.


    Parameters
    ----------

    tt : list or numpy.ndarray
      Time frames.

    xx : list or numpy.ndarray
      X positions in the trajectory.

    yy : list or numpy.ndarray
      Y positions in the trajectory.


    Examples
    --------

    >>> trajectory = Trajectory([0, .166, .333], [554, 474, 384], [100, 90, 91])
    c                     dt          j        |          z  | _        t          j        |          | _        t          j        |          | _        |                                  d S r   )r	   r
   r   xxyyupdate_interpolators)r   r   r%   r&   s       r   r   zTrajectory.__init__[   sL    $(2,,(2,,!!#####r   c                 z    t          j        |                     |          |                     |          g          S )zInterpolates the trajectory at the given time ``t``.

        Parameters
        ----------

        t : float
          Time for which to the corresponding position will be returned.
        )r	   r
   xiyir   s     r   r   zTrajectory.__call__a   s-     xTWWQZZ0111r   c                 H    t          | j        | j        |z   | j                  S )a  Adds a value to the ``xx`` position of the trajectory.

        Parameters
        ----------

        x : int
          Value added to ``xx`` in the trajectory.


        Returns
        -------

        Trajectory : new instance with the new X position included.
        r#   r   r%   r&   )r   xs     r   addxzTrajectory.addxl   s      $'47Q;888r   c                 H    t          | j        | j        | j        |z             S )a  Adds a value to the ``yy`` position of the trajectory.

        Parameters
        ----------

        y : int
          Value added to ``yy`` in the trajectory.


        Returns
        -------

        Trajectory : new instance with the new Y position included.
        r,   )r   ys     r   addyzTrajectory.addy}   s      $'47DGaK888r   c                     t          | j        | j                  | _        t          | j        | j                  | _        dS )zEUpdates the internal X and Y position interpolators for the instance.N)r   r   r%   r)   r&   r*   )r   s    r   r'   zTrajectory.update_interpolators   s0    tw00tw00r   Fc                 P    t          |rdnd| j        z  | j        | j                  S )zReturns all times with the X and Y values of each position.

        Parameters
        ----------

        tms : bool, optional
          If is ``True``, the time will be returned in milliseconds.
             )r   r   r%   r&   )r   tmss     r   txyzTrajectory.txy   s*     C&DDQ$'147DGDDDr   c           
          t          j        |t          j        t          |                     d                              dd           dS )zSaves the trajectory data in a text file.

        Parameters
        ----------

        filename : str
          Path to the location of the new trajectory text file.
        Tr6   %d	)fmt	delimiterN)r	   savetxtr
   listr7   )r   filenames     r   to_filezTrajectory.to_file   sS     	
HT$((t(,,--..		
 	
 	
 	
 	
 	
r   c                 r    t          j        | d          }|j        \  }}}t          d|z  dz  ||          S )a   Instantiates an object of Trajectory using a data text file.

        Parameters
        ----------

        filename : str
          Path to the location of trajectory text file to load.


        Returns
        -------

        Trajectory : new instance loaded from text file.
        r;   r=   r   r4   )r	   loadtxtTr#   )r@   arrr   r%   r&   s        r   	from_filezTrajectory.from_file   s?      jT222U
B#(T/2r222r   c                     t          |           }t          j        d | D                       }t          j        ||ddd                    |g dz                       dS )zSaves a set of trajectories into a text file.

        Parameters
        ----------

        trajs : list
          List of trajectories to be saved.

        filename : str
          Path of the text file that will store the trajectories data.
        c           	      x    g | ]7}t          j        t          |                    d                               8S )Tr9   )r	   r
   r?   r7   ).0r   s     r   
<listcomp>z(Trajectory.save_list.<locals>.<listcomp>   s6    HHHQ$quuu"7"788HHHr   r:   r;   )zt(ms)r-   r0   )r<   r=   headerN)lenr	   hstackr>   join)trajsr@   NrF   s       r   	save_listzTrajectory.save_list   sw     JJiHH%HHHII

99Q!4!4!4455	
 	
 	
 	
 	
 	
r   c                     t          j        | d          j        }|j        d         }d t          j        ||dz            D             S )a'  Loads a list of trajectories from a data text file.

        Parameters
        ----------

        filename : str
          Path of the text file that stores the data of a set of trajectories.


        Returns
        -------

        list : List of trajectories loaded from the file.
        r;   rC   r   c                 b    g | ],}t          d |d         z  dz  |d         |d                   -S )r   r   r4   r5      )r   r%   r&   )r#   )rJ   as     r   rK   z(Trajectory.load_list.<locals>.<listcomp>   sL     
 
 
 #!*t+!1>>>
 
 
r      )r	   rD   rE   shapesplit)r@   rF   Nliness      r   	load_listzTrajectory.load_list   sW      jT22241
 
Xc6A:..
 
 
 	
r   N)F)r   r   r   r    r   r   r.   r1   r'   r7   rA   staticmethodrG   rR   r[   r!   r   r   r#   r#   @   s         4$ $ $	2 	2 	29 9 9"9 9 9"1 1 1
	E 	E 	E 	E
 
 
  3 3 \3& 
 
 \
, 
 
 \
 
 
r   r#   )r    numpyr	   r   r#   r!   r   r   <module>r^      s    @ @    7E 7E 7E 7E 7E 7E 7E 7Etn
 n
 n
 n
 n
 n
 n
 n
 n
 n
r   