Ë
    Eü´j'  ã                   ó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         ú_/root/workspace/ytshorts/venv/lib/python3.12/site-packages/moviepy/video/tools/interpolators.pyÚ__init__zInterpolator.__init__*   sc   € ØÐÜ˜$�Z‰FˆB�àœŸ™ ›Ñ$ˆŒØœŸ™ ›Ñ$ˆŒØˆŒ	ØˆŒ
Ü" 2›w¬¨B«ÐˆŒ	�4•9ó    c                 ó„   — t        j                  || j                  | j                  | j                  | j
                  «      S )zŸInterpolates ``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‰y˜˜DŸG™G T§W¡W¨d¯i©i¸¿¹Ó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 )zÀInterpolates 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‰x˜Ÿ™ › T§W¡W¨Q£ZÐ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#   € ô ˜$Ÿ'™' 4§7¡7¨Q¡;°·±Ó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#   € ô ˜$Ÿ'™' 4§7¡7¨D¯G©G°a©KÓ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.   € ä˜tŸw™w¨¯©Ó0ˆŒÜ˜tŸw™w¨¯©Ó0ˆ�r   c                 óf   — t        |rdnd| j                  z  | j                  | j                  «      S )zÎReturns 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‘D Q¨$¯'©'Ñ1°4·7±7¸D¿G¹GÓDÐDr   c           
      óŽ   — t        j                  |t        j                  t        | j	                  d¬«      «      «      dd¬«       y)z±Saves 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   € ô 	�
‰
ØÜ�H‰H”T˜$Ÿ(™( 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:   € ô  �j‰j˜¨TÔ2ˆØ—U‘U‰
ˆˆB�Ü˜# ™( T™/¨2¨rÓ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 )zþSaves 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ˆÜ�i‰iÀ%ÖH¸QœŸ™¤$ q§u¡u° u£Ó"7Õ8ÒHÓIˆÜ
�
‰
ØØØØØ—9‘9˜QÒ!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   € ô  �j‰j˜¨TÔ2×4Ñ4ˆØ—‘˜1‘ˆô —X‘X˜c 6¨A¡:Ó.ö
àô ˜#  !¡™* 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   