
    g'                     8    d Z ddlZ G d d      Z G d d      Zy)z:Classes for easy interpolation of trajectories and curves.    Nc                       e Zd ZdZddZd Zy)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| _	        | _
        y N      ?)zipnparrayttssleftrightminmaxtmintmax)selfr   r   ttssr   r   s         j/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/tools/interpolators.py__init__zInterpolator.__init__*   sc    $ZFB$$	
"2wB	49    c                     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+     yyDGGTWWdiiDDr   )NNNNN)__name__
__module____qualname____doc__r   r    r   r   r   r      s    !F0	Er   r   c                   l    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y)
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                  |      | _        | j                          y r   )r	   r
   r   xxyyupdate_interpolators)r   r   r%   r&   s       r   r   zTrajectory.__init__[   s@    $((2,((2,!!#r   c                 l    t        j                  | j                  |      | 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(     xxTWWQZ011r   c                 ^    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#     $''477Q;88r   c                 ^    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#     $''477DGGaK88r   c                     t        | j                  | j                        | _        t        | j                  | j                        | _        y)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   s.    tww0tww0r   c                 f    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(     CDQ$''1477DGGDDr   c           
          t        j                  |t        j                  t        | j	                  d                  dd       y)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   s5     	

HHT$((t(,-.		
r   c                 v    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:      jjT2UU
B#(T/2r22r   c                    t        |       }t        j                  | D cg c]0  }t        j                  t	        |j                  d                  2 c}      }t        j                  ||dddj                  |g dz               yc c}w )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.
        Tr9   r:   r;   )zt(ms)r-   r0   )r<   r=   headerN)lenr	   hstackr
   r?   r7   r>   join)trajsr@   Nr   rF   s        r   	save_listzTrajectory.save_list   sn     Jii%HQ$quuu"78HI


99Q!445	
 Is   5B
c           	          t        j                  | d      j                  }|j                  d   }t        j                  ||dz        D cg c]  }t        d|d   z  dz  |d   |d   	      ! c}S c c}w )
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      r   r4   r5      )r   r%   r&   )r	   rD   rE   shapesplitr#   )r@   rF   Nlinesas       r   	load_listzTrajectory.load_list   sv      jjT2441 XXc6A:.
 #!*t+!1>
 	
 
s   $A3N)F)r   r   r   r    r   r   r.   r1   r'   r7   rA   staticmethodrG   rO   rW   r!   r   r   r#   r#   @   sg    4$	29"9"1
	E
  3 3& 
 
, 
 
r   r#   )r    numpyr	   r   r#   r!   r   r   <module>rZ      s$    @ 7E 7Etn
 n
r   