
    W|h'                     8    S r SSKr " S S5      r " S S5      rg)z:Classes for easy interpolation of trajectories and curves.    Nc                   (    \ rS rSrSrSS jrS rSrg)Interpolator   a  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                     Ub
  [        U6 u  pS[        R                  " U5      -  U l        S[        R                  " U5      -  U l        X@l        XPl        [        U5      [        U5      sU l	        U l
        g N      ?)zipnparrayttssleftrightminmaxtmintmax)selfr   r   ttssr   r   s         [/home/james-whalen/.local/lib/python3.13/site-packages/moviepy/video/tools/interpolators.py__init__Interpolator.__init__*   s]    $ZFB$$	
"2wB	49    c                     [         R                  " XR                  U R                  U R                  U R
                  5      $ )zwInterpolates ``t``.

Parameters
----------

t : float
  Time frame for which the correspondent value will be returned.
)r
   interpr   r   r   r   r   ts     r   __call__Interpolator.__call__4   s)     yyGGTWWdiiDDr   )r   r   r   r   r   r   )NNNNN)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r   r   r   r      s    !F0	Er   r   c                   v    \ rS rSrSrS rS rS rS rS r	SS jr
S	 r\S
 5       r\S 5       r\S 5       rSrg)
Trajectory@   a  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                     S[         R                  " U5      -  U l        [         R                  " U5      U l        [         R                  " U5      U l        U R                  5         g r   )r
   r   r   xxyyupdate_interpolators)r   r   r+   r,   s       r   r   Trajectory.__init__[   s@    $((2,((2,!!#r   c                 n    [         R                  " U R                  U5      U R                  U5      /5      $ )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   Trajectory.__call__a   s(     xxTWWQZ011r   c                 ^    [        U R                  U R                  U-   U R                  5      $ )zAdds 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   addxTrajectory.addxl   s#     $''477Q;88r   c                 ^    [        U R                  U R                  U R                  U-   5      $ )zAdds 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.
r4   )r   ys     r   addyTrajectory.addy}   s#     $''477DGGaK88r   c                     [        U R                  U R                  5      U l        [        U R                  U R                  5      U l        g)zEUpdates the internal X and Y position interpolators for the instance.N)r   r   r+   r0   r,   r1   )r   s    r   r-   Trajectory.update_interpolators   s.    tww0tww0r   c                 p    [        U(       a  SOSU R                  -  U R                  U R                  5      $ )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   txyTrajectory.txy   s(     CDQ$''1477DGGDDr   c                     [         R                  " U[         R                  " [        U R	                  SS95      5      SSS9  g)zSaves the trajectory data in a text file.

Parameters
----------

filename : str
  Path to the location of the new trajectory text file.
TrA   %d	)fmt	delimiterN)r
   savetxtr   listrB   )r   filenames     r   to_fileTrajectory.to_file   s5     	

HHT$((t(,-.		
r   c                 n    [         R                  " U SS9nUR                  u  p#n[        SU-  S-  X45      $ )zInstantiates 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.
rG   rI   r   r?   )r
   loadtxtTr(   )rL   arrr   r+   r,   s        r   	from_fileTrajectory.from_file   s6      jjT2UU
#(T/222r   c                    [        U 5      n[        R                  " U  Vs/ s H/  n[        R                  " [	        UR                  SS95      5      PM1     sn5      n[        R                  " UUSSSR                  U/ SQ-  5      S9  gs  snf )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.
TrE   rF   rG   )zt(ms)r5   r9   )rH   rI   headerN)lenr
   hstackr   rK   rB   rJ   join)trajsrL   Nr   rS   s        r   	save_listTrajectory.save_list   sr     Jii%H%Q$quuu"78%HI


99Q!445	
 Is   6B
c           	          [         R                  " U SS9R                  nUR                  S   n[         R                  " XS-  5       Vs/ s H  n[        SUS   -  S-  US   US   S	9PM     sn$ s  snf )
zLoads 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.
rG   rP   r      r   r?   r@      )r   r+   r,   )r
   rQ   rR   shapesplitr(   )rL   rS   Nlinesas       r   	load_listTrajectory.load_list   sy      jjT2441 XXcA:.
. #!*t+!1>.
 	
 
s   
$A1)r   r0   r+   r1   r,   N)F)r    r!   r"   r#   r$   r   r   r6   r:   r-   rB   rM   staticmethodrT   r]   rf   r%   r&   r   r   r(   r(   @   sg    4$	29"9"1
	E
  3 3& 
 
, 
 
r   r(   )r$   numpyr
   r   r(   r&   r   r   <module>rj      s$    @ 7E 7Etn
 n
r   