
    ljy                       d Z ddlmZ ddgZddlmZmZ ddlmZm	Z	m
Z
 ddlZddlmZmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZ ddlmZmZ ddlmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2 ddl3T ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF ddlGmHZHmIZI ddlJmKZK erdd lmLZL dd!lMmNZNmOZOmPZPmQZQmRZRmSZS e@ZTeCZUe?ZV G d" de<          ZW G d# deW          ZXdS )$z#A scene suitable for vector spaces.    )annotationsVectorSceneLinearTransformationScene)CallableIterable)TYPE_CHECKINGAnycastN)DrawBorderThenFillGroup)Camera)Dot)ArrowLineVector)	Rectangle)AxesNumberPlane)OpenGLMobject)MathTexTex)update_dict_recursively   )config	Animation)CreateWrite)FadeOut)	GrowArrow)ApplyFunctionApplyPointwiseFunction	Transform)*)Matrix)Mobject)VGroupVMobject)Scene)	BLACKBLUE_DGREEN_CGREYPURE_YELLOWRED_CWHITE
ManimColorParsableManimColor)	rush_from	rush_into)angle_of_vector)Self)MappingFunctionPoint3DPoint3DLikeVector2DLikeVector3DVector3DLikec                       e Zd ZdGdH fdZdIdJdZd	efdKdZ	 dLdMdZdNdZe	dfdOdZ
dPd!ZeefdQd%ZdRd&Zd	d'd	d(ed)z
  fdSd3Z	 dTdUd4ZdVd8ZdWd;Zd<ez  d<ez  z   dfdXdAZ	 	 dYdZdDZd[dFZ xZS )\r         @basis_vector_stroke_widthfloatkwargsr	   returnNonec                H     t                      j        di | || _        d S )N )super__init__r?   )selfr?   rA   	__class__s      Y/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/scene/vector_space_scene.pyrG   zVectorScene.__init__H   s.    ""6""")B&&&    Fanimateboolr   c                    t          di |}|r$|                     t          |d                     |                     |           |S )al  
        Adds a NumberPlane object to the background.

        Parameters
        ----------
        animate
            Whether or not to animate the addition of the plane via Create.
        **kwargs
            Any valid keyword arguments accepted by NumberPlane.

        Returns
        -------
        NumberPlane
            The NumberPlane object.
              ?	lag_ratiorE   )r   playr   add)rH   rL   rA   planes       rJ   	add_planezVectorScene.add_planeL   sR      %%f%% 	4IIfUc222333rK   color1ParsableManimColor | Iterable[ParsableManimColor]r   c                    t          |ddi          }|r"|                     t          |                     |                     |           |S )z
        Adds a pair of Axes to the Scene.

        Parameters
        ----------
        animate
            Whether or not to animate the addition of the axes through Create.
        color
            The color of the axes. Defaults to WHITE.
        	unit_size   )rV   axis_config)r   rR   r   rS   )rH   rL   rV   axess       rJ   add_axeszVectorScene.add_axesb   sO     %k1-=>>> 	$IIfTll###rK   ffffff?rO   dimnessaxes_dimnessc                   |                                  }|                                }|                    |           |                    t                     |                    |           |                     |           | j                                         t          | j        	                                          | j        _
        |                                  dS )aN  
        This method freezes the NumberPlane and Axes that were already
        in the background, and adds new, manipulatable ones to the foreground.

        Parameters
        ----------
        dimness
            The required dimness of the NumberPlane

        axes_dimness
            The required dimness of the Axes.
        N)rU   get_axesfade	set_colorr0   rS   rendererupdate_framer   	get_framecameraclear)rH   r_   r`   rT   r\   s        rJ   lock_in_faded_gridzVectorScene.lock_in_faded_gridw   s       ~~

7u		, 	""$$$%dm&=&=&?&?@@

rK   numerical_vectorr<   r   c                ~    t          | j                            dd           | j        j        |dd          fddi|S )aP  
        Returns an arrow on the Plane given an input numerical vector.

        Parameters
        ----------
        numerical_vector
            The Vector to plot.
        **kwargs
            Any valid keyword argument of Arrow.

        Returns
        -------
        Arrow
            The Arrow representing the Vector.
        r   Nr   buff)r   rT   coords_to_point)rH   rk   rA   s      rJ   
get_vectorzVectorScene.get_vector   s_       J&&q!,,&DJ&(8!(<=	
 

 
 
 
 	
rK   TvectorArrow | Vector3DLikec                    t          |t                    s!t          t          j        |          fd|i|}|r"|                     t          |                     |                     |           |S )a  
        Returns the Vector after adding it to the Plane.

        Parameters
        ----------
        vector
            It can be a pre-made graphical vector, or the
            coordinates of one.

        color
            The string of the hex color of the vector.
            This is only taken into consideration if
            'vector' is not an Arrow. Defaults to YELLOW.

        animate
            Whether or not to animate the addition of the vector
            by using GrowArrow

        **kwargs
            Any valid keyword argument of Arrow.
            These are only considered if vector is not
            an Arrow.

        Returns
        -------
        Arrow
            The arrow representing the vector.
        rV   )
isinstancer   r   npasarrayrR   r    rS   )rH   rp   rV   rL   rA   s        rJ   
add_vectorzVectorScene.add_vector   su    F &%(( 	GBJv..FFeFvFFF 	)IIi''(((rK   r   r%   c                d     |j         di |}|                     t          |                     |S )a  
        Returns a column matrix indicating the vector coordinates,
        after writing them to the screen.

        Parameters
        ----------
        vector
            The arrow representing the vector.

        **kwargs
            Any valid keyword arguments of :meth:`~.Vector.coordinate_label`:

        Returns
        -------
        :class:`.Matrix`
            The column matrix representing the vector.
        rE   )coordinate_labelrR   r   )rH   rp   rA   coordss       rJ   write_vector_coordinatesz$VectorScene.write_vector_coordinates   s9    $ 10::6::		%--   rK   i_hat_colorj_hat_colorr'   c                B     t           fdddg|fddg|ffD              S )a  
        Returns a VGroup of the Basis Vectors (1,0) and (0,1)

        Parameters
        ----------
        i_hat_color
            The hex colour to use for the basis vector in the x direction

        j_hat_color
            The hex colour to use for the basis vector in the y direction

        Returns
        -------
        VGroup
            VGroup of the Vector Mobjects representing the basis vectors.
        c              3  p   K   | ]0\  }}t          t          j        |          |j                   V  1dS ))rV   stroke_widthN)r   rt   ru   r?   ).0vectrV   rH   s      rJ   	<genexpr>z0VectorScene.get_basis_vectors.<locals>.<genexpr>  sb          D% Jt$$!%!?       rK   rZ   r   )r'   )rH   r{   r|   s   `  rJ   get_basis_vectorszVectorScene.get_basis_vectors   sQ    *     '(V[$9QFK;P#Q  	
 		
rK   c                                                       \  }}t           fd|dt          f|dt          ffD              S )a  
        Returns naming labels for the basis vectors.

        Parameters
        ----------
        **kwargs
            Any valid keyword arguments of get_vector_label:
                vector,
                label (str,MathTex)
                at_tip (bool=False),
                direction (str="left"),
                rotate (bool),
                color (str),
                label_scale_factor=VECTOR_LABEL_SCALE_FACTOR (int, float),
        c              3  D   K   | ]\  }}} j         ||f|d dV  dS )rZ   )rV   label_scale_factorN)get_vector_label)r   r   labelrV   rA   rH   s       rJ   r   z6VectorScene.get_basis_vector_labels.<locals>.<genexpr>  sj         'D% &%%', FL      rK   z\hat{\imath}z\hat{\jmath})r   r'   X_COLORY_COLOR)rH   rA   i_hatj_hats   ``  rJ   get_basis_vector_labelsz#VectorScene.get_basis_vector_labels  sm      --//u    
 ,g6,g6+	  

 
	
rK   leftNg?r   MathTex | strat_tip	directionstrrotateParsableManimColor | Noner   r   c                r   t          |t                    sUt          |          dk    rd|z  }t          |          }||                                }n|}|                    |           t          |t                    sJ |                    |           |                                 |rg|                                }	|	t          j	        
                    |	          z  }	|                    |                                |	t                     n#|                                }
|s|                    |
 t                      |dk    rHt          j        |                                          }|                    | dt(          z  z              nGt          j        |                                          }|                    | dt,          z  z              |                    |
t                      |                    |                                |                                z
  dz             |S )	a  
        Returns naming labels for the passed vector.

        Parameters
        ----------
        vector
            Vector Object for which to get the label.

        at_tip
            Whether or not to place the label at the tip of the vector.

        direction
            If the label should be on the "left" or right of the vector.
        rotate
            Whether or not to rotate it to align it with the vector.
        color
            The color to give the label.
        label_scale_factor
            How much to scale the label by.

        Returns
        -------
        MathTex
            The MathTex of the label.
        rZ   z\vec{\textbf{%s}}N)rm   )about_pointr   皙?r   )rs   r   len	get_colorrd   scaleadd_background_rectanglero   rt   linalgnormnext_toget_end
SMALL_BUFF	get_angler   ORIGINru   
get_bottomshiftUPget_topDOWN	get_start)rH   rp   r   r   r   r   rV   r   prepared_colorr   angletemp_shift_1temp_shift_2s                rJ   r   zVectorScene.get_vector_label)  s   F %)) 	,5zzQ-5ENNE}5;5E5E5G5G!&OON+++%)))))&'''&&((( 	E$$&&DBINN4(((DMM&..**DzMBBBB$$&&E 9eV888F"")+E4D4D4F4F)G)G\MC"H45555)+EMMOO)D)D\MC$J6777LLFL333KK))F,<,<,>,>>!CDDDrK   c                     | j         ||fi |}|r$|                     t          |d                     |                     |           |S )a  
        Shortcut method for creating, and animating the addition of
        a label for the vector.

        Parameters
        ----------
        vector
            The vector for which the label must be added.

        label
            The MathTex/string of the label.

        animate
            Whether or not to animate the labelling w/ Write

        **kwargs
            Any valid keyword argument of get_vector_label

        Returns
        -------
        :class:`~.MathTex`
            The MathTex of the label.
        rZ   run_time)r   rR   r   rS   )rH   rp   r   rL   rA   mathtex_labels         rJ   label_vectorzVectorScene.label_vectork  s_    4 .-feFFvFF 	8IIeMA666777rK   x_coordx_liner   c                    |                     |t          j        |d                    t          z             |                    t
                     |S )NrZ   )r   rt   signr   rd   r   )rH   r   r   rp   s       rJ   position_x_coordinatez!VectorScene.position_x_coordinate  sG     	!3!3 3b 8999'"""rK   y_coordy_linec                    |                     |t          j        |d                   t          z             |                    t
                     |S )Nr   )r   rt   r   RIGHTrd   r   )rH   r   r   rp   s       rJ   position_y_coordinatez!VectorScene.position_y_coordinate  sD     	q	 2 2U :;;;'"""rK   r   r:   coords_startr9   clean_upc                    t           j                  }t                    }|                    |           t	                    }t          t          d         t          z            t                                          |                                          	                    t                     	                    t                     |                                }|d         d         }|d         d         }	                     t          |d                                                                            t!           fd|                                          t#                               t!           fd|	          t%          |                                          g}
  j        |
                       t#                                                    t#          |                                                       |r                                     j        |  dS dS )a  
        This method writes the vector as a column matrix (henceforth called the label),
        takes the values in it one by one, and form the corresponding
        lines that make up the x and y components of the vector. Then, an
        Vector() based vector is created between the lines on the Screen.

        Parameters
        ----------
        vector
            The vector to show.

        coords_start
            The starting point of the location of
            the label of the vector that shows it
            numerically.
            Defaults to 2 * RIGHT + 2 * UP or (2,2)

        clean_up
            Whether or not to remove whatever
            this method did after it's done.

        r   rZ   r   c                2                         |           S N)r   )xrH   rp   r   s    rJ   <lambda>z.VectorScene.coords_to_vector.<locals>.<lambda>      $44QGG rK   c                2                         |           S r   )r   )yrH   rp   r   s    rJ   r   z.VectorScene.coords_to_vector.<locals>.<lambda>  r   rK   N)listmobjectsr%   r   r   r   r   r   r   rd   r   r   get_mob_matrixrR   r   waitr!   r   r   get_bracketsri   rS   )rH   rp   r   r   starting_mobjectsarrayarrow
mob_matrixr   r   
animationsr   r   s   ``         @@rJ   coords_to_vectorzVectorScene.coords_to_vector  s   8 !//vL!!!vffQi%/00fnn&&88!!!!!!))++
Q-"Q-"		%***+++				GGGGGG 	
 	
 	
 			&..!!!GGGGGG  E&&(())

 		: 			&..!!!		&--   		 	)JJLLLDH'((((	) 	)rK   integer_labelstuple[Matrix, Line, Line]c                   t          | j                  }d}t          |t                    r|}|                                dd         }nt          |          }d}|                    |          }t          t          |d         t          z            }t          |                                |                                          }	|
                    t                     |	
                    t                     t          t          |                                          \  }
}|                     |
                                ||          }|                     |                                |	|          }|                                }|r"|                     t+          |                     |                     t+          |          t-          |          d           |                     t+          |	          t-          |          d           |                                  |                     t1          ||
d	          t1          ||d	          t-          |d                     |                                  |                     |||           |                     |           |r|                                   | j        |  |||	fS )
ae  
        This method displays vector as a Vector() based vector, and then shows
        the corresponding lines that make up the x and y components of the vector.
        Then, a column matrix (henceforth called the label) is created near the
        head of the Vector.

        Parameters
        ----------
        vector
            The vector to show.

        integer_labels
            Whether or not to round the value displayed.
            in the vector's label to the nearest integer

        clean_up
            Whether or not to remove whatever
            this method did after it's done.

        FNr   T)r   r   rZ   r   rP   )r   r   rs   r   r   r   rx   r   r   r   rd   r   r   r
   r'   get_entriesr   copyr   r   rR   r   r   r   r#   removerS   ri   )rH   rp   r   r   r   show_creationr   r   r   r   r   r   x_coord_starty_coord_startbracketss                  rJ   vector_to_coordszVectorScene.vector_to_coords  sg   4 !//fe$$ 	!E]]__RaR(FF6NNE M&&n&EEffQi%/00fnn&&88!!!!!!(9(9(;(;<<227<<>>66RR227<<>>66RR%%'' 	%IIfUmm$$$		&..%"6"6	CCC		&..%"6"6	CCC				mW:::mW:::(Q'''	
 	
 	

 			M=(;;; 	)JJLLLDH'((ff$$rK   #Arrow | Vector2DLike | Vector3DLikec                   t          |t                    r*|                                |                                z
  }nNt	          j        |          }t          |          dk    r't	          j        t	          j        |          d          }|}t          t          d         t          |d                   z             }t          t          d         t          |d                   z             t          fdt          | |          D              }|                    t          d           |                                                    |dz                                t$          d          }|                                                    |          }|                     t)          ||t*          	                     |                     t)          ||t,          	                     |                     |           d
S )a  
        This method plays an animation that partially shows the entire plane moving
        in the direction of a particular vector. This is useful when you wish to
        convey the idea of mentally moving the entire plane in a direction, without
        actually moving the plane.

        Parameters
        ----------
        vector
            The vector which indicates the direction of movement.
        r   g        frame_x_radiusr   frame_y_radiusrZ   c              3     K   | ]:}t                     D ]&}t          |t          z  |t          z  z             V  ';d S r   )ranger   r   r   )r   r   r   y_maxs      rJ   r   z2VectorScene.show_ghost_movement.<locals>.<genexpr>9  so        vu--   AIB&''      rK   )opacity)	rate_funcN)rs   r   r   r   rt   ru   r   appendr   intr   absr(   r   set_fillr*   r   r   r0   rR   r#   r4   r3   r   )rH   rp   vector_cleanedx_maxdotsdots_halfwaydots_endr   s          @rJ   show_ghost_movementzVectorScene.show_ghost_movement   s    fe$$ 	:^^%%(8(8(:(::FFZ''F6{{a28F#3#3S99#)F+,s>!3D/E/EEFFF+,s>!3D/E/EEFF    vu--  
 	eQ'''yy{{((!);<<EEeQOO99;;$$^44		)D,)DDDEEE		)D(i@@@AAADrK   )r>   )r?   r@   rA   r	   rB   rC   F)rL   rM   rA   r	   rB   r   )rL   rM   rV   rW   rB   r   )r^   rO   )r_   r@   r`   r@   rB   rC   )rk   r<   rA   r	   rB   r   )
rp   rq   rV   rW   rL   rM   rA   r	   rB   r   rp   r   rA   r	   rB   r%   )r{   rW   r|   rW   rB   r'   )rA   r	   rB   r'   )rp   r   r   r   r   rM   r   r   r   rM   rV   r   r   r@   rB   r   )T)
rp   r   r   r   rL   rM   rA   r	   rB   r   )r   r   r   r   rp   r<   rB   r   )r   r   r   r   rp   r<   rB   r   )rp   r:   r   r9   r   rM   rB   rC   )TT)rp   r<   r   rM   r   rM   rB   r   )rp   r   rB   rC   )__name__
__module____qualname__rG   rU   r0   r]   rj   ro   r.   rv   rz   r   r   r   r   
LARGE_BUFFr   r   r   r   r   r   r   r   r   __classcell__rI   s   @rJ   r   r   G   s       C C C C C C C    0 CH    , ;>    8
 
 
 
8 DO	( ( ( ( (T   0 JQIP
 
 
 
 
@
 
 
 
B +/$.$4@ @ @ @ @F EI    @       %&IB$6	@) @) @) @) @)J  $	=% =% =% =% =%~% % % % % % % %rK   c            
      F    e Zd ZdZdddddddeedf
dh fdZedid            ZdjdZ	dkd#Z
dld%Zdld&Zdld'Z	 dmdnd+Zdod-Zed.d/fdpd5Zdqdrd8Zedfds fd<Zdt fd?Z	 	 dudvdHZ	 	 dwdxdMZdydQZdzdSZd{dWZd|dZZd|d[Zd}d\Zd~d]Zd~d^Zdd_ZddaZ dddZ!g fddgZ" xZ#S )r   aq  
    This scene contains special methods that make it
    especially suitable for showing linear transformations.

    Parameters
    ----------
    include_background_plane
        Whether or not to include the background plane in the scene.
    include_foreground_plane
        Whether or not to include the foreground plane in the scene.
    background_plane_kwargs
        Parameters to be passed to :class:`NumberPlane` to adjust the background plane.
    foreground_plane_kwargs
        Parameters to be passed to :class:`NumberPlane` to adjust the foreground plane.
    show_coordinates
        Whether or not to include the coordinates for the background plane.
    show_basis_vectors
        Whether to show the basis x_axis -> ``i_hat`` and y_axis -> ``j_hat`` vectors.
    basis_vector_stroke_width
        The ``stroke_width`` of the basis vectors.
    i_hat_color
        The color of the ``i_hat`` vector.
    j_hat_color
        The color of the ``j_hat`` vector.
    leave_ghost_vectors
        Indicates the previous position of the basis vectors following a transformation.

    Examples
    -------

    .. manim:: LinearTransformationSceneExample

        class LinearTransformationSceneExample(LinearTransformationScene):
            def __init__(self, **kwargs):
                LinearTransformationScene.__init__(
                    self,
                    show_coordinates=True,
                    leave_ghost_vectors=True,
                    **kwargs
                )

            def construct(self):
                matrix = [[1, 1], [0, 1]]
                self.apply_matrix(matrix)
                self.wait()
    TNF   include_background_planerM   include_foreground_planebackground_plane_kwargsdict[str, Any] | Noneforeground_plane_kwargsshow_coordinatesshow_basis_vectorsr?   r@   r{   r2   r|   leave_ghost_vectorsrA   r	   rB   rC   c                P    t                      j        di | || _        || _        || _        || _        || _        t          |          | _        t          |	          | _	        |
| _
        t          dt          it          ddd| _        t                      | _        t          j        t"          d          t"          d         dg          t          j        t"          d          t"          d         dg          dd| _        |                     | j        | j        f||f           d S )	NrV   rZ   )stroke_colorr   )rV   r[   background_line_styleframe_widthg      ?)x_rangey_rangefaded_line_ratiorE   )rF   rG   r   r   r   r   r?   r1   r{   r|   r   r-   r   r'   ghost_vectorsrt   r   r   r   update_default_configs)rH   r   r   r   r   r   r   r?   r{   r|   r   rA   rI   s               rJ   rG   z"LinearTransformationScene.__init__x  sA    	""6"""(@%(@% 0"4)B&%k22%k22#6  !% !& &	8
 	8
$ $XX x&"7!79NPS TUUx&"7!79NPS TUU !8
 8
$ 	##)4+GH$&=>	
 	
 	
 	
 	
rK   default_configsIterable[dict[str, Any]]passed_configsIterable[dict[str, Any] | None]c                Z    t          | |d          D ]\  }}|t          ||           d S )NF)strict)zipr   )r
  r  default_configpassed_configs       rJ   r	  z0LinearTransformationScene.update_default_configs  sU    
 .1^E.
 .
 .
 	G 	G)NM ('FFF		G 	GrK   c                   t          | d          rd S d| _        g | _        g | _        g | _        g | _        g | _        g | _        t          di | j	        | _
        | j        r| j
                                         | j        r|                     | j
                   | j        r0t          di | j        | _        |                     | j                   | j        rx|                     | j        | j                  | _        | xj        t1          | j                  z  c_        | j        \  | _        | _        |                     | j                   d S d S )Nhas_already_setupT)r{   r|   rE   )hasattrr  background_mobjectsforeground_mobjectstransformable_mobjectsmoving_vectorstransformable_labelsmoving_mobjectsr   r   background_planer   add_coordinatesr   add_background_mobjectr   r   rT   add_transformable_mobjectr   r   r{   r|   basis_vectorsr   r   r   rS   rH   s    rJ   setupzLinearTransformationScene.setup  sq   4,-- 	F!%24 24 57#-/35!.0 + K Kd.J K K  	4!11333( 	?''(=>>>( 	7$DDt'CDDDJ**4:666" 	)!%!7!7 , , "8 " "D 4(:#;#;;%)%7"DJ
HHT'(((((	) 	)rK   mob_listlist[Mobject]mobs_to_addr&   c                l    |D ]0}||vr*|                     |           |                     |           1dS )a?  
        Adds mobjects to a separate list that can be tracked,
        if these mobjects have some extra importance.

        Parameters
        ----------
        mob_list
            The special list to which you want to add
            these mobjects.

        *mobs_to_add
            The mobjects to add.

        N)r   rS   )rH   r#  r%  mobjects       rJ   add_special_mobjectsz.LinearTransformationScene.add_special_mobjects  sM    " # 	" 	"Gh&&(((!!!	" 	"rK   r   c                ,     | j         | j        g|R   dS )z
        Adds the mobjects to the special list
        self.background_mobjects.

        Parameters
        ----------
        *mobjects
            The mobjects to add to the list.
        N)r(  r  rH   r   s     rJ   r  z0LinearTransformationScene.add_background_mobject  (     	"!$":FXFFFFFFrK   c                ,     | j         | j        g|R   dS )z
        Adds the mobjects to the special list
        self.foreground_mobjects.

        Parameters
        ----------
        *mobjects
            The mobjects to add to the list
        N)r(  r  r*  s     rJ   add_foreground_mobjectz0LinearTransformationScene.add_foreground_mobject  r+  rK   c                ,     | j         | j        g|R   dS )z
        Adds the mobjects to the special list
        self.transformable_mobjects.

        Parameters
        ----------
        *mobjects
            The mobjects to add to the list.
        N)r(  r  r*  s     rJ   r  z3LinearTransformationScene.add_transformable_mobject  s(     	"!$"=IIIIIIIrK   r'  target_mobjectMobject | Nonec                J    ||_         |                     | j        |           dS )a  
        Adds the mobject to the special list
        self.moving_mobject, and adds a property
        to the mobject called mobject.target, which
        keeps track of what the mobject will move to
        or become etc.

        Parameters
        ----------
        mobject
            The mobjects to add to the list

        target_mobject
            What the moving_mobject goes to, etc.
        N)targetr(  r  )rH   r'  r/  s      rJ   add_moving_mobjectz,LinearTransformationScene.add_moving_mobject  s*    $ (!!$"6@@@@@rK   r'   c                    | j         S )z~
        Returns all ghost vectors ever added to ``self``. Each element is a ``VGroup`` of
        two ghost vectors.
        )r  r!  s    rJ   get_ghost_vectorsz+LinearTransformationScene.get_ghost_vectors"  s    
 !!rK   g333333?   rV   rW   r   r   r   c           	        t          || j                                        | j                                        ||||          x}| _        |                    | j                            dd          t                     |S )a{  
        Returns a unit square for the current NumberPlane.

        Parameters
        ----------
        color
            The string of the hex color code of the color wanted.

        opacity
            The opacity of the square

        stroke_width
            The stroke_width in pixels of the border of the square

        Returns
        -------
        Square
        )rV   widthheightr  r   
fill_colorfill_opacityr   )r   rT   get_x_unit_sizeget_y_unit_sizesquaremove_torn   DL)rH   rV   r   r   r>  s        rJ   get_unit_squarez)LinearTransformationScene.get_unit_square)  s    0  )*,,..:--//%  
  
  
 	
 	tz11!Q77<<<rK   rL   r6   c                     | j         di |}|r<|                     t          |          t          t	          | j                              |                     |            | j        | j          || _        | S )a  
        Adds a unit square to the scene via
        self.get_unit_square.

        Parameters
        ----------
        animate
            Whether or not to animate the addition
            with DrawBorderThenFill.
        **kwargs
            Any valid keyword arguments of
            self.get_unit_square()

        Returns
        -------
        Square
            The unit square.
        rE   )	rA  rR   r   r   r   r  r  bring_to_frontr>  )rH   rL   rA   r>  s       rJ   add_unit_squarez)LinearTransformationScene.add_unit_squareM  s    & &%//// 	II"6**%!4566   	&&v...T011rK   rp   !Arrow | list | tuple | np.ndarrayr   c                v     t                      j        |f||d|}| j                            |           |S )aa  
        Adds a vector to the scene, and puts it in the special
        list self.moving_vectors.

        Parameters
        ----------
        vector
            It can be a pre-made graphical vector, or the
            coordinates of one.

        color
            The string of the hex color of the vector.
            This is only taken into consideration if
            'vector' is not an Arrow. Defaults to YELLOW.

        **kwargs
            Any valid keyword argument of VectorScene.add_vector.

        Returns
        -------
        Arrow
            The arrow representing the vector.
        )rV   rL   )rF   rv   r  r   )rH   rp   rV   rL   rA   rI   s        rJ   rv   z$LinearTransformationScene.add_vectork  sF    < $#FS%SSFSS""6***rK   r   r%   c                f     t                      j        |fi |}|                     |           |S )a  
        Returns a column matrix indicating the vector coordinates,
        after writing them to the screen, and adding them to the
        special list self.foreground_mobjects

        Parameters
        ----------
        vector
            The arrow representing the vector.

        **kwargs
            Any valid keyword arguments of VectorScene.write_vector_coordinates

        Returns
        -------
        Matrix
            The column matrix representing the vector.
        )rF   rz   r-  )rH   rp   rA   ry   rI   s       rJ   rz   z2LinearTransformationScene.write_vector_coordinates  s<    & 21&CCFCC##F+++rK   Lr   r   transformation_namestr | MathTex	new_labelstr | MathTex | Noner   c                2    | j         ||fi |}|r||_        n| d|                                 d|_        ||_        ||_        d|j        v r|j                            d           | j                            |           t          t          |          S )a  
        Method for creating, and animating the addition of
        a transformable label for the vector.

        Parameters
        ----------
        vector
            The vector for which the label must be added.

        label
            The MathTex/string of the label.

        transformation_name
            The name to give the transformation as a label.

        new_label
            What the label should display after a Linear Transformation

        **kwargs
            Any valid keyword argument of get_vector_label

        Returns
        -------
        :class:`~.MathTex`
            The MathTex of the label.
        ()rL   )
r   target_textget_tex_stringrp   rA   popr  r   r
   r   )rH   rp   r   rI  rK  rA   	label_mobs          rJ   add_transformable_labelz1LinearTransformationScene.add_transformable_label  s    F &D%fe>>v>>	 	$-I!! 'FF)A)A)C)CFFF ! "	!		(((  +++!((333GY'''rK         ?titlestr | MathTex | Texscale_factorc                ^   t          |t          t          f          s"t          |                              |          }|                    t                     |                                 |r"|                     t          |                     | 
                    |           || _        | S )a3  
        Adds a title, after scaling it, adding a background rectangle,
        moving it to the top and adding it to foreground_mobjects adding
        it as a local variable of self. Returns the Scene.

        Parameters
        ----------
        title
            What the title should be.

        scale_factor
            How much the title should be scaled by.

        animate
            Whether or not to animate the addition.

        Returns
        -------
        LinearTransformationScene
            The scene with the title added to it.
        )rs   r&   r   r   r   to_edger   r   rR   r   r-  rV  )rH   rV  rX  rL   s       rJ   	add_titlez#LinearTransformationScene.add_title  s    6 %'=!9:: 	3JJ$$\22Eb&&((( 	$IIeEll#####E***
rK   matrixnp.ndarray | list | tupleCallable[[Point3D], Point3D]c                Z    |                      t          j        |          j                  S )z
        Returns a function corresponding to the linear
        transformation represented by the matrix passed.

        Parameters
        ----------
        matrix
            The matrix.
        )$get_transposed_matrix_transformationrt   r   T)rH   r\  s     rJ   get_matrix_transformationz3LinearTransformationScene.get_matrix_transformation  s%     88&9I9I9KLLLrK   transposed_matrixc                    t          j                  j        dk    r"t          j        d          }|ddddf<   |nj        dk    rt	          d          fdS )z
        Returns a function corresponding to the linear
        transformation represented by the transposed
        matrix passed.

        Parameters
        ----------
        transposed_matrix
            The matrix.
        )r   r   r6  Nr   )r6  r6  zMatrix has bad dimensionsc                .    t          j        |           S r   )rt   dot)pointrc  s    rJ   r   zPLinearTransformationScene.get_transposed_matrix_transformation.<locals>.<lambda>  s    RVE+<== rK   )rt   r   shapeidentity
ValueError)rH   rc  
new_matrixs    ` rJ   r`  z>LinearTransformationScene.get_transposed_matrix_transformation  s|     H%677"f,,QJ!2Jrr2A2v *$..8999=====rK   piecesIterable[Mobject]r#   c                P   d |D             }t          | }t          d |D              }| j        rf|j        r_| j                            |                                                    d                     |                     | j        d                    t          ||d          S )a  
        This method returns an animation that moves an arbitrary
        mobject in "pieces" to its corresponding .target value.
        If self.leave_ghost_vectors is True, ghosts of the original
        positions/mobjects are left on screen

        Parameters
        ----------
        pieces
            The pieces for which the movement must be shown.

        Returns
        -------
        Animation
            The animation of the movement.
        c                <    g | ]}t          |t                    |S rE   )rs   r(   )r   pieces     rJ   
<listcomp>z@LinearTransformationScene.get_piece_movement.<locals>.<listcomp>/  s'    MMMeE81L1LMEMMMrK   c              3  $   K   | ]}|j         V  d S r   )r2  )r   mobs     rJ   r   z?LinearTransformationScene.get_piece_movement.<locals>.<genexpr>1  s$      99#*999999rK   r^   r   rP   )r'   r   submobjectsr  rS   r   rc   r#   )rH   rl  v_piecesstartr2  s        rJ   get_piece_movementz,LinearTransformationScene.get_piece_movement  s    " NMvMMM!99999: # 	-(9 	-""5::<<#4#4S#9#9:::HHT'+,,,!4444rK   funcr7   c                    | j         D ][}|j        |                                |_        |                                } ||          }|j                            |           \|                     | j                   S )a  
        This method returns an animation that moves a mobject
        in "self.moving_mobjects"  to its corresponding .target value.
        func is a function that determines where the .target goes.

        Parameters
        ----------

        func
            The function that determines where the .target of
            the moving mobject goes.

        Returns
        -------
        Animation
            The animation of the movement.
        )r  r2  r   
get_centerr?  rx  )rH   ry  mtemptarget_points        rJ   get_moving_mobject_movementz5LinearTransformationScene.get_moving_mobject_movement:  sw    $ % 	+ 	+Ax6688LLNND4::LH\****&&t';<<<rK   c                   | j         D ]}t           ||                                          |                                          |_        t          t          j                            |j                                                            }|dk     r,|j        	                                
                    |           |                     | j                   S )a  
        This method returns an animation that moves a mobject
        in "self.moving_vectors"  to its corresponding .target value.
        func is a function that determines where the .target goes.

        Parameters
        ----------

        func
            The function that determines where the .target of
            the moving mobject goes.

        Returns
        -------
        Animation
            The animation of the movement.
        )rV   r   )r  r   r   r   r2  r@   rt   r   r   get_tipr   rx  )rH   ry  vr   s       rJ   get_vector_movementz-LinearTransformationScene.get_vector_movementT  s    $ $ 	/ 	/Add199;;//q{{}}EEEAH(8(8(:(:;;<<Dczz  ""((...&&t':;;;rK   c                    | j         D ],}|j        } | j        |j        j        |fi |j        |_        -|                     | j                   S )z
        This method returns an animation that moves all labels
        in "self.transformable_labels" to its corresponding .target .

        Returns
        -------
        Animation
            The animation of the movement.
        )r  rP  r   rp   r2  rA   rx  )rH   r   rP  s      rJ    get_transformable_label_movementz:LinearTransformationScene.get_transformable_label_movementm  sm     . 	 	E */):K040#  , ELL
 &&t'@AAArK   c                P     | j         t          j        |          j        fi | dS )a@  
        Applies the transformation represented by the
        given matrix to the number plane, and each vector/similar
        mobject on it.

        Parameters
        ----------
        matrix
            The matrix.
        **kwargs
            Any valid keyword argument of self.apply_transposed_matrix()
        N)apply_transposed_matrixrt   r   ra  rH   r\  rA   s      rJ   apply_matrixz&LinearTransformationScene.apply_matrix  s2     	%$RXf%5%5%7BB6BBBBBrK   c                \     | j         t          j                            |          fi | dS )aw  
        This method applies the linear transformation
        represented by the inverse of the passed matrix
        to the number plane, and each vector/similar mobject on it.

        Parameters
        ----------
        matrix
            The matrix whose inverse is to be applied.
        **kwargs
            Any valid keyword argument of self.apply_matrix()
        N)r  rt   r   invr  s      rJ   apply_inversez'LinearTransformationScene.apply_inverse  s3     	")--//::6:::::rK   c                   |                      |          }d|vrat          j        t           |t                              t           |t
                              t          j        dz  z
  g          }||d<    | j        |fi | dS )aM  
        Applies the transformation represented by the
        given transposed matrix to the number plane,
        and each vector/similar mobject on it.

        Parameters
        ----------
        transposed_matrix
            The matrix.
        **kwargs
            Any valid keyword argument of self.apply_function()
        path_arcr   N)r`  rt   meanr5   r   r   piapply_function)rH   rc  rA   ry  net_rotations        rJ   r  z1LinearTransformationScene.apply_transposed_matrix  s     889JKKV##7 e--ttBxx/H/H25ST9/TU L ".F:D++F+++++rK   t_matrixc                    t           j                            t          j        |          j                  j        } | j        |fi | dS )a[  
        Applies the inverse of the transformation represented
        by the given transposed matrix to the number plane and each
        vector/similar mobject on it.

        Parameters
        ----------
        t_matrix
            The matrix.
        **kwargs
            Any valid keyword argument of self.apply_transposed_matrix()
        N)rt   r   r  r   ra  r  )rH   r  rA   t_invs       rJ   apply_inverse_transposez1LinearTransformationScene.apply_inverse_transpose  sH     	bhx002335$$U55f55555rK   function"Callable[[np.ndarray], np.ndarray]c                T    | j                                           | j        |fi | dS )aG  
        Applies the non-linear transformation represented
        by the given function to the number plane and each
        vector/similar mobject on it.

        Parameters
        ----------
        function
            The function.
        **kwargs
            Any valid keyword argument of self.apply_function()
        N)rT   prepare_for_nonlinear_transformr  )rH   r  rA   s      rJ   apply_nonlinear_transformationz8LinearTransformationScene.apply_nonlinear_transformation  s9     	
22444H///////rK   added_animslist[Animation]c                    d|vrd|d<   fd| j         D             |                               |                                 |                               gz   d | j        D             z   |z   } | j        |i | dS )a  
        Applies the given function to each of the mobjects in
        self.transformable_mobjects, and plays the animation showing
        this.

        Parameters
        ----------
        function
            The function that affects each point
            of each mobject in self.transformable_mobjects.

        added_anims
            Any other animations that need to be played
            simultaneously with this.

        **kwargs
            Any valid keyword argument of a self.play() call.
        r   r6  c                0    g | ]}t          |          S rE   )r"   )r   t_mobr  s     rJ   rq  z<LinearTransformationScene.apply_function.<locals>.<listcomp>  s3        'x77  rK   c                ,    g | ]}t          |          S rE   r   )r   f_mobs     rJ   rq  z<LinearTransformationScene.apply_function.<locals>.<listcomp>  s     FFFEyFFFrK   N)r  r  r  r  r  rR   )rH   r  r  rA   animss    `   rJ   r  z(LinearTransformationScene.apply_function  s    0 V##!"F:   !8  
 ((22557700::	 GFT-EFFF	G 
 	 		5#F#####rK   )r   rM   r   rM   r   r   r   r   r   rM   r   rM   r?   r@   r{   r2   r|   r2   r   rM   rA   r	   rB   rC   )r
  r  r  r  rB   rC   )rB   rC   )r#  r$  r%  r&   rB   rC   )r   r&   rB   rC   r   )r'  r&   r/  r0  rB   rC   )rB   r'   )rV   rW   r   r@   r   r@   rB   r   r   )rL   rM   rA   r	   rB   r6   )
rp   rE  rV   r2   rL   rM   rA   r	   rB   r   r   )rH  N)rp   r   r   r   rI  rJ  rK  rL  rA   r	   rB   r   )rU  F)rV  rW  rX  r@   rL   rM   rB   r6   )r\  r]  rB   r^  )rc  r]  rB   r^  )rl  rm  rB   r#   )ry  r7   rB   r#   )rB   r#   )r\  r]  rA   r	   rB   rC   )rc  r]  rA   r	   rB   rC   )r  r]  rA   r	   rB   rC   )r  r  rA   r	   rB   rC   )r  r7   r  r  rA   r	   rB   rC   )$r   r   r   __doc__r   r   rG   staticmethodr	  r"  r(  r  r-  r  r3  r5  r.   rA  rD  rv   rz   rT  r[  rb  r`  rx  r  r  r  r  r  r  r  r  r  r   r   s   @rJ   r   r   H  s       - -b *.)-9=9=!&#'+,*1*1$).
 .
 .
 .
 .
 .
 .
` G G G \G) ) ) )<" " " ",
G 
G 
G 
G
G 
G 
G 
G
J 
J 
J 
J BFA A A A A*" " " " DO	" " " " "H    B %0	             D     6 .1*./( /( /( /( /(h "	# # # # #JM M M M> > > >,5 5 5 58= = = =4< < < <2B B B B*C C C C; ; ; ;, , , ,.6 6 6 6$0 0 0 0* (*'$ '$ '$ '$ '$ '$ '$ '$ '$rK   )Yr  
__future__r   __all__collections.abcr   r   typingr   r	   r
   numpyrt   manim.animation.creationr   r   manim.camera.camerar   manim.mobject.geometry.arcr   manim.mobject.geometry.liner   r   r   manim.mobject.geometry.polygramr   )manim.mobject.graphing.coordinate_systemsr   r   #manim.mobject.opengl.opengl_mobjectr   manim.mobject.text.tex_mobjectr   r   manim.utils.config_opsr    r   animation.animationr   animation.creationr   r   animation.fadingr   animation.growingr    animation.transformr!   r"   r#   	constantsmobject.matrixr%   mobject.mobjectr&    mobject.types.vectorized_mobjectr'   r(   scene.scener)   utils.colorr*   r+   r,   r-   r.   r/   r0   r1   r2   utils.rate_functionsr3   r4   utils.space_opsr5   r6   manim.typingr7   r8   r9   r:   r;   r<   r   r   Z_COLORr   r   rE   rK   rJ   <module>r     s   ) ) " " " " " "5
6 . . . . . . . . + + + + + + + + + +     > > > > > > > > & & & & & & * * * * * * ; ; ; ; ; ; ; ; ; ; 5 5 5 5 5 5 G G G G G G G G = = = = = = 7 7 7 7 7 7 7 7 : : : : : :       + + + + + + . . . . . . . . & & & & & & ) ) ) ) ) ) R R R R R R R R R R     # # # # # # % % % % % % ? ? ? ? ? ? ? ?      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 8 7 7 7 7 7 7 7 - - - - - - 
                

~ ~ ~ ~ ~% ~ ~ ~Bz
$ z
$ z
$ z
$ z
$ z
$ z
$ z
$ z
$ z
$rK   