
    lj                   |   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZ d dlZd dlZ d dl!mZ" d dl#m$Z$ d dl%m&Z&m'Z' d d	l(T d d
l)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG d dlHmIZI d dlJmKZKmLZLmMZM erjd dlNmOZO d dl+mPZP d dl-mQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZY e
deZge[f         Z\de]d<   e
dge[f         Z^de]d<   e^e\z  Z_de]d<    ed          Z` ede ja                  Zbd3d!Zcg d"Zde je        Zfde]d#<   	 e"jg        ef         Zhde]d$<    G d% d          Zi G d& d'ei          Zj G d( d)ei          Zk G d* d+          Zl ed,e
d-                   Zm G d. d/e          Znd4d2ZodS )5    )annotationsN)CallableIterableIteratorSequence)partialmethodwraps)ceil)
TYPE_CHECKINGAnyClassVarNeverProtocolSelf	TypeAliasTypeVarcastoverload)override)configlogger)*)MethodWithArgs)get_colormap_code)Point3DPoint3D_ArrayPoint3DLikePoint3DLike_Array)integer_interpolateinterpolate)WHITE
ManimColorParsableManimColorcolor_gradientcolor_to_rgb
rgb_to_hex)_Data	_Uniforms)batch_by_propertylist_updatelistify	make_evenresize_arrayresize_preserving_orderresize_with_interpolation
uniq_chain)straight_path)angle_between_vectors	normalizerotation_matrix_transpose)	AnimationShaderWrapper)	FloatRGB_ArrayFloatRGBA_Array
ManimFloatMappingFunctionMatrixMNMultiMappingFunctionPathFuncTypeVector3DVector3DLikeOpenGLMobjectr   _TimeBasedUpdater_NonTimeBasedUpdater_Updater_T_T_np)boundfunc(Callable[[OpenGLMobject], OpenGLMobject]returnc                >     t                     d fd            }|S )NselfrA   rJ   c                t    |                                  D ]!} |           |                                 "| S N)
get_familyrefresh_shader_wrapper_id)rL   mobrH   s     ^/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/opengl/opengl_mobject.pywrapperz'affects_shader_info_id.<locals>.wrappera   sC    ??$$ 	, 	,CDIII))++++    )rL   rA   rJ   rA   )r	   )rH   rS   s   ` rR   affects_shader_info_idrU   ^   s:     4[[     [ NrT   )rA   OpenGLGroupOpenGLPoint_AnimationBuilder_ShaderDType_ShaderDatac                  ~    e Zd ZU dZded<   dej        dfgZded<   dZd	ed
<    e	            Z
ded<    e	            Zded<    e	            Zded<    e            Zded<    e            Zded<    e            Zded<    e            Zded<    e            Zded<   eddddej        ddddddddfdd0Zdd5Zdd8Zed fd:            Zedd<            Zedd=            ZddAZddBZddDZ ddEZ!eddF            Z"ddGZ#ddHZ$ddIZ%ddJZ&ddMZ'ddOZ(e)ddQ            Z*e)ddR            Z+e+j,        ddT            Z+e)ddU            Z-e-j,        ddV            Z-e)ddW            Z.e.j,        ddX            Z.e/fdd\Z0dd^Z1ddaZ2ddcZ3ddeZ4ddfZ5ddhZ6de7dfddoZ8ddpZ9ddqZ:ddrZ;ddtZ<dduZ=ddvZ>ddwZ?	 dddzZ@eAfdd}ZBddZCddZDddZEddZFddZGdddZHddZIddddZJ	 dĐddZKddddZLddZMddZNeOdfddZPddeAe7dddddf	ddZQ	 dʐddZRddZSd dfddZTdĐddZUdĐddZVdĐddZWddZXdĐddZYdĐddZZddZ[ddZ\dԐddZ]ddZ^ddZ_ddĄZ`ddńZa	 	 dؐddɄZbddʄZcddd˄Zddd̄Zeddd̈́Zfdېdd΄ZgddτZhddфZide7fddԄZjddքZkelfddلZmeldfddڄZneofddۄZpddބZqdd߄ZrddZsddZtddZuddZveOewdfddZxddZyezfddZ{e|ewz   ezfddZ}e|ezfddZ~eOee7dd ej        g d          fddZddZddZddZ	 dĐddZdd ZddZddZ	 dĐddZeZ	 dĐddZeZ	 dĐddZeZe7fddZe7fdd	Ze7fddZe7fddZdddZe7 ej        g d          fddZ	 	 dddZddeAfddZd dZ	 	 	 	 dddZ	 	 dddZ	 	 dddZ	 ddd Zdd!Zdd"Zdd%Zdd&Zd	d
d)Zdd*Zddd+Zdd,Zddd-Z	 	 ddd0Zdd1Zdd2Zdd3Zdd4Zdd5Zdd6Zdd7Zdd8Zdd9Zdd:Zdd;Zdd<Zdd=Zdd>Zdd?Zdd@ZddAZddBZddCZe7fddEZe7fddFZe7fddGZe7fddHZddIZddJZddLZddNZddOZddQZddRZÐddSZĐddTZŐddUZƐddVZǐddWZe7fddXZe7fddYZe7fddZZe7fdd[Ze7fdd\Z͐dd^Zeϐdd_            ZАdd`ZѐddaZҐddbZӐddcZԐdddZՐddeZ eצ            fddjZؐddmZ	 	 	 	 	 d d!drZڐd"dtZېd#duZܐddvZeސddw            Zeސddx            Zeސddy            Zeސddz            Zeސdd{            Zeސdd|            Zd$dZd%dZ	 	 	 d&d'dZddZd(dZd)dZd*dZd+dZd,dZd-dZddZd.dZd/dZe)d0d            Zej,        d1d            ZddZ xZS (2  rA   aC  Mathematical Object: base class for objects that can be displayed on screen.

    Attributes
    ----------
    submobjects : List[:class:`OpenGLMobject`]
        The contained objects.
    points : :class:`numpy.ndarray`
        The points of the objects.

        .. seealso::

            :class:`~.OpenGLVMobject`

    zClassVar[Callable[..., None]]_original__init__point)   zAClassVar[Sequence[tuple[str, type[np.generic], tuple[int, ...]]]]shader_dtype zClassVar[str]shader_folderz_Data[Point3D_Array]pointsbounding_boxz_Data[FloatRGBA_Array]rgbasr(   is_fixed_in_frameis_fixed_orientationz%_Uniforms[tuple[float, float, float]]fixed_orientation_centerglossshadow   r^           NFTcolor1ParsableManimColor | Sequence[ParsableManimColor]opacityfloatdimintrender_primitivetexture_pathsdict[str, str] | None
depth_testboollisten_to_eventsmodel_matrixMatrixMN | Noneshould_rendername
str | Nonekwargsr   c                .   || j         j        n|| _        t          | di           | _        t          | di           | _        || _        || _        || _        || _	        || _
        || _        || _        t          |	          | _        t          |
          | _        d| _        || _        g | _        g | _        d | _        | g| _        t-                      | _        d| _        |t3          j        d          | _        n|| _        |                                  |                                  |                                  t?          j         |          | _!        | "                                 d | _#        | j        r| $                                 || _%        d S )Ndatauniformsr   r   r   T   )&	__class____name__r{   getattrr   r   rn   rp   rh   ri   rr   rs   ru   ro   re   rf   rg   rw   _submobjectsparentsparentfamilysetlocked_data_keysneeds_new_bounding_boxnpeyerx   	init_datainit_updatersinit_pointsr"   parserl   init_colorsshader_indicesapply_depth_testrz   )rL   rl   rn   rp   rh   ri   rr   rs   ru   re   rf   rw   rx   rz   r{   r}   s                   rR   __init__zOpenGLMobject.__init__   s   2 59L00d	18vr1J1J	>E*b?
 ?
 18 
%54A *!&'8!9!9$)*>$?$?!(1% '713,.,0,06*-%%,0#*,&))D ,D4>4DU4K4K
48? 	$!!####0rT   submobjectsIterable[OpenGLMobject]rJ   r   c                8    |                      |t                    S )a  Check that all submobjects are actually instances of
        :class:`OpenGLMobject`, and that none of them is
        ``self`` (an :class:`OpenGLMobject` cannot contain itself).

        This is an auxiliary function called when adding OpenGLMobjects to the
        :attr:`submobjects` list.

        This function is intended to be overridden by subclasses such as
        :class:`OpenGLVMobject`, which should assert that only other
        OpenGLVMobjects may be added into it.

        Parameters
        ----------
        submobjects
            The list containing values to validate.

        Returns
        -------
        :class:`OpenGLMobject`
            The OpenGLMobject itself.

        Raises
        ------
        TypeError
            If any of the values in `submobjects` is not an
            :class:`OpenGLMobject`.
        ValueError
            If there was an attempt to add an :class:`OpenGLMobject` as its own
            submobject.
        )"_assert_valid_submobjects_internalrA   )rL   r   s     rR   _assert_valid_submobjectsz'OpenGLMobject._assert_valid_submobjects   s    > 66{MRRRrT   	mob_classtype[OpenGLMobject]c                p   t          |          D ]\  }}t          ||          sdd|j         dt          |           j         d| d| dt          |          j         d}t          |t                    r|dz  }t          |          || u r(t          dt          |           j         d	| d
          | S )NzOnly values of type z  can be added as submobjects of z, but the value z (at index z) is of type .z4 You can try adding this value into a Group instead.zCannot add z% as a submobject of itself (at index z).)	enumerate
isinstancer   typerA   	TypeError
ValueError)rL   r   r   isubmoberror_messages         rR   r   z0OpenGLMobject._assert_valid_submobjects_internal  s    #;// 	 	IAvfi00 /09+= 0 0)-d)<0 00 0*+0 0 F||,0 0 0  fm44 !NM  ...~~ .$t**"5 . .(). . .   
 rT   Nonec                R     t                      j        di | | j        | _        d S N )super__init_subclass__r   r\   )clsr}   r   s     rR   r   zOpenGLMobject.__init_subclass__  s0    !!++F+++ #rT   strc                    | j         j        S rN   )r   r   rL   s    rR   __str__zOpenGLMobject.__str__"  s    ~&&rT   c                *    t          | j                  S rN   )r   r{   r   s    rR   __repr__zOpenGLMobject.__repr__&  s    49~~rT   otherr   objectc                    t           S rN   NotImplementedrL   r   s     rR   __sub__zOpenGLMobject.__sub__*      rT   c                    t           S rN   r   r   s     rR   __isub__zOpenGLMobject.__isub__-  r   rT   mobjectc                    t           S rN   r   rL   r   s     rR   __add__zOpenGLMobject.__add__0  r   rT   c                    t           S rN   r   r   s     rR   __iadd__zOpenGLMobject.__iadd__3  r   rT   c                T    |rt          | j        fi || _        dS | j        | _        dS )a%  Sets the default values of keyword arguments.

        If this method is called without any additional keyword
        arguments, the original default values of the initialization
        method of this class are restored.

        Parameters
        ----------

        kwargs
            Passing any keyword argument will update the default
            values of the keyword arguments of the initialization
            function of this class.

        Examples
        --------

        ::

            >>> from manim import Square, GREEN
            >>> Square.set_default(color=GREEN, fill_opacity=0.25)
            >>> s = Square(); s.color, s.fill_opacity
            (ManimColor('#83C167'), 0.25)
            >>> Square.set_default()
            >>> s = Square(); s.color, s.fill_opacity
            (ManimColor('#FFFFFF'), 0.0)

        .. manim:: ChangedDefaultTextcolor
            :save_last_frame:

            config.background_color = WHITE

            class ChangedDefaultTextcolor(Scene):
                def construct(self):
                    Text.set_default(color=BLACK)
                    self.add(Text("Changing default values is easy!"))

                    # we revert the colour back to the default to prevent a bug in the docs.
                    Text.set_default(color=WHITE)

        N)r   r   r\   )r   r}   s     rR   set_defaultzOpenGLMobject.set_default6  s:    V  	1 )@@@@CLLL0CLLLrT   c                    t          j        d          | _        t          j        d          | _        t          j        d          | _        dS )zInitializes the ``points``, ``bounding_box`` and ``rgbas`` attributes and groups them into self.data.
        Subclasses can inherit and overwrite this method to extend `self.data`.
        r   r^   )r^   r^   )rj   r   N)r   zerosrb   rc   rd   r   s    rR   r   zOpenGLMobject.init_datah  s<     hv&&HV,,Xf%%


rT   c                F    |                      | j        | j                   dS )zCInitializes the colors.

        Gets called upon creation
        N)	set_colorrl   rn   r   s    rR   r   zOpenGLMobject.init_colorsp  s"    
 	tz4<00000rT   c                    dS )zInitializes :attr:`points` and therefore the shape.

        Gets called upon creation. This is an empty method that can be implemented by
        subclasses.
        Nr   r   s    rR   r   zOpenGLMobject.init_pointsw  s	     	rT   c                \    |                                 D ]\  }}t          | ||           | S )a  Sets attributes.

        Mainly to be used along with :attr:`animate` to
        animate setting attributes.

        Examples
        --------
        ::

            >>> mob = OpenGLMobject()
            >>> mob.set(foo=0)
            OpenGLMobject
            >>> mob.foo
            0

        Parameters
        ----------
        **kwargs
            The attributes and corresponding values to set.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``


        )itemssetattr)rL   r}   attrvalues       rR   r   zOpenGLMobject.set  s9    8 "<<>> 	' 	'KD%D$&&&&rT   r   dict[str, Any]c                T    |D ]$}||                                          | j        |<   %| S rN   )copyr   )rL   r   keys      rR   set_datazOpenGLMobject.set_data  s1     	. 	.C!#Y^^--DIcNNrT   r   c                0    |D ]}||         | j         |<   | S rN   r   )rL   r   r   s      rR   set_uniformszOpenGLMobject.set_uniforms  s)     	/ 	/C!)#DM#rT   _AnimationBuilder | Selfc                     t          |           S )a-  Used to animate the application of a method.

        .. warning::

            Passing multiple animations for the same :class:`OpenGLMobject` in one
            call to :meth:`~.Scene.play` is discouraged and will most likely
            not work properly. Instead of writing an animation like

            ::

                self.play(
                    my_mobject.animate.shift(RIGHT), my_mobject.animate.rotate(PI)
                )

            make use of method chaining for ``animate``, meaning::

                self.play(my_mobject.animate.shift(RIGHT).rotate(PI))

        Keyword arguments that can be passed to :meth:`.Scene.play` can be passed
        directly after accessing ``.animate``, like so::

            self.play(my_mobject.animate(rate_func=linear).shift(RIGHT))

        This is especially useful when animating simultaneous ``.animate`` calls that
        you want to behave differently::

            self.play(
                mobject1.animate(run_time=2).rotate(PI),
                mobject2.animate(rate_func=there_and_back).shift(RIGHT),
            )

        .. seealso::

            :func:`override_animate`


        Examples
        --------

        .. manim:: AnimateExample

            class AnimateExample(Scene):
                def construct(self):
                    s = Square()
                    self.play(Create(s))
                    self.play(s.animate.shift(RIGHT))
                    self.play(s.animate.scale(2))
                    self.play(s.animate.rotate(PI / 2))
                    self.play(Uncreate(s))


        .. manim:: AnimateChainExample

            class AnimateChainExample(Scene):
                def construct(self):
                    s = Square()
                    self.play(Create(s))
                    self.play(s.animate.shift(RIGHT).scale(2).rotate(PI / 2))
                    self.play(Uncreate(s))

        .. manim:: AnimateWithArgsExample

            class AnimateWithArgsExample(Scene):
                def construct(self):
                    s = Square()
                    c = Circle()

                    VGroup(s, c).arrange(RIGHT, buff=2)
                    self.add(s, c)

                    self.play(
                        s.animate(run_time=2).rotate(PI / 2),
                        c.animate(rate_func=there_and_back).shift(RIGHT),
                    )

        .. warning::

            ``.animate``
             will interpolate the :class:`~.OpenGLMobject` between its points prior to
             ``.animate`` and its points after applying ``.animate`` to it. This may
             result in unexpected behavior when attempting to interpolate along paths,
             or rotations.
             If you want animations to consider the points between, consider using
             :class:`~.ValueTracker` with updaters instead.

        )rX   r   s    rR   animatezOpenGLMobject.animate  s    p !&&&rT   c                ,    |                      d          S )a  The width of the mobject.

        Returns
        -------
        :class:`float`

        Examples
        --------
        .. manim:: WidthExample

            class WidthExample(Scene):
                def construct(self):
                    decimal = DecimalNumber().to_edge(UP)
                    rect = Rectangle(color=BLUE)
                    rect_copy = rect.copy().set_stroke(GRAY, opacity=0.5)

                    decimal.add_updater(lambda d: d.set_value(rect.width))

                    self.add(rect_copy, rect, decimal)
                    self.play(rect.animate.set(width=7))
                    self.wait()

        See also
        --------
        :meth:`length_over_dim`

        r   length_over_dimr   s    rR   widthzOpenGLMobject.width      < ##A&&&rT   r   c                6    |                      |dd           d S )Nr   Fstretchrescale_to_fitrL   r   s     rR   r   zOpenGLMobject.width&  #    E1e44444rT   c                ,    |                      d          S )a  The height of the mobject.

        Returns
        -------
        :class:`float`

        Examples
        --------
        .. manim:: HeightExample

            class HeightExample(Scene):
                def construct(self):
                    decimal = DecimalNumber().to_edge(UP)
                    rect = Rectangle(color=BLUE)
                    rect_copy = rect.copy().set_stroke(GRAY, opacity=0.5)

                    decimal.add_updater(lambda d: d.set_value(rect.height))

                    self.add(rect_copy, rect, decimal)
                    self.play(rect.animate.set(height=5))
                    self.wait()

        See also
        --------
        :meth:`length_over_dim`

        rj   r   r   s    rR   heightzOpenGLMobject.height*  r   rT   c                6    |                      |dd           d S )Nrj   Fr   r   r   s     rR   r   zOpenGLMobject.heightJ  r   rT   c                ,    |                      d          S )zThe depth of the mobject.

        Returns
        -------
        :class:`float`

        See also
        --------
        :meth:`length_over_dim`

           r   r   s    rR   depthzOpenGLMobject.depthN  s     ##A&&&rT   c                6    |                      |dd           d S )Nr   Fr   r   r   s     rR   r   zOpenGLMobject.depth^  r   rT   
new_lengthresize_func-Callable[[Point3D_Array, int], Point3D_Array]c                    |t          | j                  k    r || j        |          | _        |                                  | S rN   )lenrb   refresh_bounding_box)rL   r   r   s      rR   resize_pointszOpenGLMobject.resize_pointsb  sE    
 T[))))%+dk:>>DK!!###rT   r   c                ,   t          |          t          | j                  k    r|| j        d d <   nMt          |t          j                  r|                                | _        nt          j        |          | _        |                                  | S rN   )r   rb   r   r   ndarrayr   arrayr   )rL   rb   s     rR   
set_pointszOpenGLMobject.set_pointsl  s{    v;;#dk****#DKNN
++ 	+ ++--DKK(6**DK!!###rT   rH   2Callable[[npt.NDArray[_T_np]], npt.NDArray[_T_np]]c                    |                                  D ]*}t          | | |t          | |                               +| S rN   )get_array_attrsr   r   )rL   rH   r   s      rR   apply_over_attr_arraysz$OpenGLMobject.apply_over_attr_arraysv  sM     ((** 	; 	;DD$WT4%8%8 9 9::::rT   Iterable[str]c                    dgS )Nrb   r   r   s    rR   r   zOpenGLMobject.get_array_attrs}  s
    zrT   
new_pointsc                n    t          j        | j        |g          | _        |                                  | S rN   )r   vstackrb   r   )rL   r  s     rR   append_pointszOpenGLMobject.append_points  s1    ij 9::!!###rT   c                    |                                  D ]*}|j        D ] }|j        |         d d d         |j        |<   !+| S )N)rO   r   )rL   rQ   r   s      rR   reverse_pointszOpenGLMobject.reverse_points  sT    ??$$ 	4 	4Cx 4 4 #ddd 34rT   r   c                ,    |                      d          S )am  Get coordinates of the middle of the path that forms the  :class:`~.OpenGLMobject`.

        Examples
        --------

        .. manim:: AngleMidPoint
            :save_last_frame:

            class AngleMidPoint(Scene):
                def construct(self):
                    line1 = Line(ORIGIN, 2*RIGHT)
                    line2 = Line(ORIGIN, 2*RIGHT).rotate_about_origin(80*DEGREES)

                    a = Angle(line1, line2, radius=1.5, other_angle=False)
                    d = Dot(a.get_midpoint()).set_color(RED)

                    self.add(line1, line2, a, d)
                    self.wait()

              ?point_from_proportionr   s    rR   get_midpointzOpenGLMobject.get_midpoint  s    * ))#...rT   r=   about_pointPoint3DLike | None
about_edgeVector3DLike | Noneworks_on_bounding_boxc                   |||                      |          }|                                 D ]}g }|                                r|                    |j                   |r'|                    |                                           |D ]+}| ||          |d d <    |||z
            |z   |d d <   ,|s|                     d           n| j        D ]}|                                 | S )NTrecurse_down)get_bounding_box_pointrO   
has_pointsappendrb   get_bounding_boxr   r   )	rL   rH   r  r  r  rQ   arrsarrr   s	            rR   apply_points_functionz#OpenGLMobject.apply_points_function  s4    :#955jAAK??$$ 	C 	CC(*D~~ (CJ'''$ 4C0022333 C C&!T#YYCFF!T#"344{BCFF	C % 	.%%4%8888, . .++----rT   c                :    |                      |j                   | S )a]  Edit points, positions, and submobjects to be identical
        to another :class:`~.OpenGLMobject`, while keeping the style unchanged.

        Examples
        --------
        .. manim:: MatchPointsScene

            class MatchPointsScene(Scene):
                def construct(self):
                    circ = Circle(fill_color=RED, fill_opacity=0.8)
                    square = Square(fill_color=BLUE, fill_opacity=0.2)
                    self.add(circ)
                    self.wait(0.5)
                    self.play(circ.animate.match_points(square))
                    self.wait(0.5)
        )r   rb   r   s     rR   match_pointszOpenGLMobject.match_points  s    " 	'''rT   c                8    t          j        d          | _        | S Nr   )r   emptyrb   r   s    rR   clear_pointszOpenGLMobject.clear_points  s    hv&&rT   c                *    t          | j                  S rN   )r   rb   r   s    rR   get_num_pointszOpenGLMobject.get_num_points  s    4;rT   r   c                ~    | j         r0t          j        d |                                 D                       S | j        S )Nc                    g | ]	}|j         
S r   )rb   .0sms     rR   
<listcomp>z0OpenGLMobject.get_all_points.<locals>.<listcomp>  s    DDDBbiDDDrT   )r   r   r  rO   rb   r   s    rR   get_all_pointszOpenGLMobject.get_all_points  s>     	9DD$//2C2CDDDEEE;rT   c                2    |                                  dk    S Nr   )r#  r   s    rR   r  zOpenGLMobject.has_points  s    ""$$q((rT   c                ^    | j         r |                                 | _        d| _         | j        S NF)r   compute_bounding_boxrc   r   s    rR   r  zOpenGLMobject.get_bounding_box  s2    & 	0 $ 9 9 ; ;D*/D'  rT   c                p   t          j        | j        gd |                                 dd          D                       }t	          |          dk    rt          j        d| j        f          S |                    d          }|                    d          }||z   dz  }t          j	        |||g          S )Nc              3  f   K   | ],}|                                 |                                V  -d S rN   )r  r  r'  rQ   s     rR   	<genexpr>z5OpenGLMobject.compute_bounding_box.<locals>.<genexpr>  sR        ~~''((**     rT   rj   r   r^   r   )
r   r  rb   rO   r   r   rp   minmaxr   )rL   
all_pointsminsmaxsmidss        rR   r/  z"OpenGLMobject.compute_bounding_box  s    Y #004  	
 	

 z??a8QM*** >>!$$D>>!$$D4K1$D8T4.///rT   r  
recurse_upc                    |                      |          D ]	}d|_        
|r| j        D ]}|                                 | S NT)rO   r   r   r   )rL   r  r:  rQ   r   s        rR   r   z"OpenGLMobject.refresh_bounding_box  s]     ??<00 	. 	.C)-C&& 	., . .++----rT   r   buffc                    |                                  }|d         |z
  }|d         |z   }||k                                    o||k                                    }|S )Nr   r   )r  all)rL   r]   r=  bbr7  r8  rvs          rR   is_point_touchingzOpenGLMobject.is_point_touching  s^     ""$$!ut|!ut|TM&&((Betm-@-@-B-B	rT   int | slicec                    t          |t                    r>|                                 } ||                                                     |           S |                                                     |          S rN   )r   sliceget_group_classsplit__getitem__)rL   r   
GroupClasss      rR   rH  zOpenGLMobject.__getitem__  se    eU## 	@--//J:tzz||77>>??zz||''...rT   Iterator[OpenGLMobject]c                D    t          |                                           S rN   )iterrG  r   s    rR   __iter__zOpenGLMobject.__iter__  s    DJJLL!!!rT   c                D    t          |                                           S rN   )r   rG  r   s    rR   __len__zOpenGLMobject.__len__  s    4::<<   rT   Sequence[OpenGLMobject]c                    | j         S rN   )r   r   s    rR   rG  zOpenGLMobject.split"  s    rT   c                    d | j         D             }| gt          | | _        |                                  |                                  | j        D ]}|                                 | S )Nc              3  >   K   | ]}|                                 V  d S rN   rO   r&  s     rR   r3  z0OpenGLMobject.assemble_family.<locals>.<genexpr>&  s*      CCBCCCCCCrT   )r   r0   r   refresh_has_updater_statusr   r   assemble_family)rL   sub_familiesr   s      rR   rV  zOpenGLMobject.assemble_family%  s{    CC$2BCCC8j,78'')))!!###l 	% 	%F""$$$$rT   recursec                :    |rt          | d          r| j        S | gS )Nr   )hasattrr   )rL   rX  s     rR   rO   zOpenGLMobject.get_family.  s*     	wtX.. 	;6MrT   c                >    d |                                  D             S )Nc                :    g | ]}|                                 |S r   )r  )r'  ms     rR   r)  z<OpenGLMobject.family_members_with_points.<locals>.<listcomp>5  s%    ???a????rT   rT  r   s    rR   family_members_with_pointsz(OpenGLMobject.family_members_with_points4  s     ??4??,,????rT   )update_parentmobjectsr_  c                  |r*t                    dk    s
J d            | d         _        |                                t          fdD                       rt	          j        d           D ]H}|| j        vr| j                            |           | |j        vr|j                            |            I| 	                                 | S )a  Add mobjects as submobjects.

        The mobjects are added to :attr:`submobjects`.

        Subclasses of mobject may implement ``+`` and ``+=`` dunder methods.

        Parameters
        ----------
        mobjects
            The mobjects to add.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``

        Raises
        ------
        :class:`ValueError`
            When a mobject tries to add itself.
        :class:`TypeError`
            When trying to add an object that is not an instance of :class:`OpenGLMobject`.


        Notes
        -----
        A mobject cannot contain itself, and it cannot contain a submobject
        more than once.  If the parent mobject is displayed, the newly-added
        submobjects will also be displayed (i.e. they are automatically added
        to the parent Scene).

        See Also
        --------
        :meth:`remove`
        :meth:`add_to_back`

        Examples
        --------
        ::

            >>> outer = OpenGLMobject()
            >>> inner = OpenGLMobject()
            >>> outer = outer.add(inner)

        Duplicates are not added again::

            >>> outer = outer.add(inner)
            >>> len(outer.submobjects)
            1

        Only OpenGLMobjects can be added::

            >>> outer.add(3)
            Traceback (most recent call last):
            ...
            TypeError: Only values of type OpenGLMobject can be added as submobjects of OpenGLMobject, but the value 3 (at index 0) is of type int.

        Adding an object to itself raises an error::

            >>> outer.add(outer)
            Traceback (most recent call last):
            ...
            ValueError: Cannot add OpenGLMobject as a submobject of itself (at index 0).

        rj   zCan't set multiple parents.r   c              3  J   K   | ]}                     |          d k    V  dS )rj   N)count)r'  elemr`  s     rR   r3  z$OpenGLMobject.add.<locals>.<genexpr>  s4      ==Dx~~d##a'======rT   zgAttempted adding some Mobject as a child more than once, this is not possible. Repetitions are ignored.)
r   r   r   anyr   warningr   r  r   rV  rL   r_  r`  r   s     ` rR   addzOpenGLMobject.add7  s    D  	&x==A%%%'D%%%!%HQK&&x000====H===== 	NA     	- 	-Gd... ''0007?**&&t,,,rT   indexc                    |r| |_         |                     |g           || j        vr| j                            ||           | |j        vr|j                            |            |                                  | S )a  Inserts a mobject at a specific position into self.submobjects

        Effectively just calls  ``self.submobjects.insert(index, mobject)``,
        where ``self.submobjects`` is a list.

        Highly adapted from ``OpenGLMobject.add``.

        Parameters
        ----------
        index
            The index at which
        mobject
            The mobject to be inserted.
        update_parent
            Whether or not to set ``mobject.parent`` to ``self``.
        )r   r   r   insertr   r  rV  )rL   ri  r   r_  s       rR   rk  zOpenGLMobject.insert  s    &  	"!GN&&y111$***##E7333w&&O""4(((rT   c                  |r*t          |          dk    s
J d            d|d         _        |D ]H}|| j        v r| j                            |           | |j        v r|j                            |            I|                                  | S )a  Remove :attr:`submobjects`.

        The mobjects are removed from :attr:`submobjects`, if they exist.

        Subclasses of mobject may implement ``-`` and ``-=`` dunder methods.

        Parameters
        ----------
        mobjects
            The mobjects to remove.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``

        See Also
        --------
        :meth:`add`

        rj   zCan't remove multiple parents.Nr   )r   r   r   remover   rV  rg  s       rR   rm  zOpenGLMobject.remove  s    ,  	&x==A%%%'G%%%!%HQK 	- 	-G$*** ''000w&&&&t,,,rT   c                d    |                      |           t          || j                  | _        | S )a  Add all passed mobjects to the back of the submobjects.

        If :attr:`submobjects` already contains the given mobjects, they just get moved
        to the back instead.

        Parameters
        ----------
        mobjects
            The mobjects to add.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``


        .. note::

            Technically, this is done by adding (or moving) the mobjects to
            the head of :attr:`submobjects`. The head of this list is rendered
            first, which places the corresponding mobjects behind the
            subsequent list members.

        Raises
        ------
        :class:`ValueError`
            When a mobject tries to add itself.
        :class:`TypeError`
            When trying to add an object that is not an instance of :class:`OpenGLMobject`.

        Notes
        -----
        A mobject cannot contain itself, and it cannot contain a submobject
        more than once.  If the parent mobject is displayed, the newly-added
        submobjects will also be displayed (i.e. they are automatically added
        to the parent Scene).

        See Also
        --------
        :meth:`remove`
        :meth:`add`

        )r   r*   r   )rL   r`  s     rR   add_to_backzOpenGLMobject.add_to_back  s3    Z 	&&x000&x1ABBrT   
new_submobc                    |                      |g           | j        |         }| |j        v r|j                            |            || j        |<   |                                  | S rN   )r   r   r   rm  rV  )rL   ri  rp  
old_submobs       rR   replace_submobjectz OpenGLMobject.replace_submobject   sn    &&
|444%e,
:%%%%%d+++",rT   	directionr@   centerc                    t          | j        dd         | j        dd         d          D ]\  }} |j        ||fi | |r|                                  | S )a  Sorts :class:`~.OpenGLMobject` next to each other on screen.

        Examples
        --------

        .. manim:: Example
            :save_last_frame:

            class Example(Scene):
                def construct(self):
                    s1 = Square()
                    s2 = Square()
                    s3 = Square()
                    s4 = Square()
                    x = OpenGLVGroup(s1, s2, s3, s4).set_x(0).arrange(buff=1.0)
                    self.add(x)
        Nr  rj   Tstrict)zipr   next_toru  )rL   rt  ru  r}   m1m2s         rR   arrangezOpenGLMobject.arrange  sw    . $*3B3/1A!""1EdSSS 	0 	0FBBJr9////// 	KKMMMrT   rdrows
int | Nonecolsfloat | tuple[float, float]cell_alignmentrow_alignmentscol_alignmentsrow_heightsSequence[float | None] | None
col_widths
flow_orderc
           	     |  "#$ ddl m} | j                                        $|                                 }d=d} |||d           |||d          0.t          t          j        t          $                              t          t          $          z            t          t          $          z            z  t          $          k     rt          d          t          |t                    r|d         }|d         }n|x}}d>fd} ||t          t          t          ddt                    } ||t           t          t          ddt                    }fdfdfdfdfd fd!fd"fd#d$}|	|vr2d%                    d& |D                       }t          d'| d(          ||	         "t$          r3t&          d?d+            }t&          d@d.            }t&          dAd1            }dAd2} ||          } ||          }t)                      }$                    |gz  t          $          z
  z             "$fd3t-                    D             ##fd4t-                    D             }#fd5t-                    D             }dBd8} |||d9          } |||d:          }d;\  }}t-                    D ]}d<}t-                    D ]}#|         |         |urw||         ||         z   }  ||t          z  |t          z  z   |||         z   t          z  |||         z   t          z  z             }!#|         |                             |!|            |||         |z   z  }|||         |z   z  }|                     |           | S )Ca  Arrange submobjects in a grid.

        Parameters
        ----------
        rows
            The number of rows in the grid.
        cols
            The number of columns in the grid.
        buff
            The gap between grid cells. To specify a different buffer in the horizontal and
            vertical directions, a tuple of two values can be given - ``(row, col)``.
        cell_alignment
            The way each submobject is aligned in its grid cell.
        row_alignments
            The vertical alignment for each row (top to bottom). Accepts the following characters: ``"u"`` -
            up, ``"c"`` - center, ``"d"`` - down.
        col_alignments
            The horizontal alignment for each column (left to right). Accepts the following characters ``"l"`` - left,
            ``"c"`` - center, ``"r"`` - right.
        row_heights
            Defines a list of heights for certain rows (top to bottom). If the list contains
            ``None``, the corresponding row will fit its height automatically based
            on the highest element in that row.
        col_widths
            Defines a list of widths for certain columns (left to right). If the list contains ``None``, the
            corresponding column will fit its width automatically based on the widest element in that column.
        flow_order
            The order in which submobjects fill the grid. Can be one of the following values:
            "rd", "dr", "ld", "dl", "ru", "ur", "lu", "ul". ("rd" -> fill rightwards then downwards)

        Returns
        -------
        OpenGLMobject
            The mobject.

        NOTES
        -----

        If only one of ``cols`` and ``rows`` is set implicitly, the other one will be chosen big
        enough to fit all submobjects. If neither is set, they will be chosen to be about the same,
        tending towards ``cols`` > ``rows`` (simply because videos are wider than they are high).

        If both ``cell_alignment`` and ``row_alignments`` / ``col_alignments`` are
        defined, the latter has higher priority.


        Raises
        ------
        ValueError
            If ``rows`` and ``cols`` are too small to fit all submobjects.
        ValueError
            If :code:`cols`, :code:`col_alignments` and :code:`col_widths` or :code:`rows`,
            :code:`row_alignments` and :code:`row_heights` have mismatching sizes.

        Examples
        --------
        .. manim:: ExampleBoxes
            :save_last_frame:

            class ExampleBoxes(Scene):
                def construct(self):
                    boxes=VGroup(*[Square() for s in range(0,6)])
                    boxes.arrange_in_grid(rows=2, buff=0.1)
                    self.add(boxes)


        .. manim:: ArrangeInGrid
            :save_last_frame:

            class ArrangeInGrid(Scene):
                def construct(self):
                    #Add some numbered boxes:
                    np.random.seed(3)
                    boxes = VGroup(*[
                        Rectangle(WHITE, np.random.random()+.5, np.random.random()+.5).add(Text(str(i+1)).scale(0.5))
                        for i in range(22)
                    ])
                    self.add(boxes)

                    boxes.arrange_in_grid(
                        buff=(0.25,0.5),
                        col_alignments="lccccr",
                        row_alignments="uccd",
                        col_widths=[2, *[None]*4, 2],
                        flow_order="dr"
                    )


        r   )Linenumr  
alignmentsr|   sizesr  r{   r   rJ   rq   c                    | | S |t          |          S |t          |          S t          d| d| d| d|dk    rdnd d	          )	Nz+At least one of the following parameters: 'zs', 'z_alignments' or '_colwidthsheightsz', must not be None)r   r   )r  r  r  r{   s       rR   	init_sizez0OpenGLMobject.arrange_in_grid.<locals>.init_size  s     
%:& 5zz!#d # ## ## #'+u}}88)# # #  rT   r  rowNz0Too few rows and columns to fit all submobjetcs.rj   str_alignmentsmappingdict[str, Vector3D]rt  r?   Sequence[Vector3D]c                    | t          t          |z            g|z  S t          |           |k    rt          | d          fd| D             S )Nz#_alignments has a mismatching size.c                     g | ]
}|         S r   r   )r'  letterr  s     rR   r)  zJOpenGLMobject.arrange_in_grid.<locals>.init_alignments.<locals>.<listcomp>  s    AAAGFOAAArT   )r   r?   r   r   )r  r  r  r{   rt  r  s     `  rR   init_alignmentsz6OpenGLMobject.arrange_in_grid.<locals>.init_alignments  sm     %X~	'ABBCcII>""c)) D!M!M!MNNNAAAA.AAAArT   )ucd)lr  rc                     | z
  dz
  |z  z   S Nrj   r   r  r  r  s     rR   <lambda>z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    q1D8 rT   c                ,    | z
  dz
  |z
  dz
  z  z   S r  r   r  r  r  r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s!    q1A0EE rT   c                    | |z  z   S rN   r   r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    q1t8| rT   c                     | |z
  dz
  z  z   S r  r   r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    qD1HqLD#88 rT   c                     | z
  dz
  z  |z   S r  r   r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    q14q8 rT   c                ,    | z
  dz
  z  |z
  dz
  z   S r  r   r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s!    q14q1E rT   c                    | z  |z   S rN   r   r  r  r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    q4x!| rT   c                     | z  |z
  dz
  z   S r  r   r  s     rR   r  z/OpenGLMobject.arrange_in_grid.<locals>.<lambda>  s    q4x4!8a<8 rT   )drdlurulr~  ldrulu,c                    g | ]}d | d 	S )"r   )r'  r   s     rR   r)  z1OpenGLMobject.arrange_in_grid.<locals>.<listcomp>  s     )G)G)G*c***)G)G)GrT   z0flow_order must be one of the following values: r   
maybe_listr   c                    d S rN   r   r  s    rR   reversez.OpenGLMobject.arrange_in_grid.<locals>.reverse  s    363rT   Sequence[_T]list[_T]c                    d S rN   r   r  s    rR   r  z.OpenGLMobject.arrange_in_grid.<locals>.reverse  s    ?BsrT   Sequence[_T] | Nonelist[_T] | Nonec                    d S rN   r   r  s    rR   r  z.OpenGLMobject.arrange_in_grid.<locals>.reverse  s    MPSrT   c                T    | %t          |           } |                                  | S d S rN   )listr  r  s    rR   r  z.OpenGLMobject.arrange_in_grid.<locals>.reverse  s2    %!*--
""$$$!!4rT   c                L    g | ]fd t                    D              S )c                4    g | ]} |                   S r   r   )r'  r  flow_order_funcmobsr  s     rR   r)  z<OpenGLMobject.arrange_in_grid.<locals>.<listcomp>.<listcomp>
  s*    BBBooa++,BBBrT   )range)r'  r  r  r  r  s    @rR   r)  z1OpenGLMobject.arrange_in_grid.<locals>.<listcomp>
  s;    XXXqBBBBBBeDkkBBBXXXrT   c                d    g | ]+t          fd t                    D                       ,S )c              3  >   K   | ]}         |         j         V  d S rN   )r   )r'  r  gridr  s     rR   r3  z;OpenGLMobject.arrange_in_grid.<locals>.<listcomp>.<genexpr>  s.      77aQ
!777777rT   r5  r  )r'  r  r  r  s    @rR   r)  z1OpenGLMobject.arrange_in_grid.<locals>.<listcomp>  sM     
 
 
<=C777775;;77777
 
 
rT   c                d    g | ]+t          fd t                    D                       ,S )c              3  >   K   | ]}|                  j         V  d S rN   )r   )r'  r  r  r  s     rR   r3  z;OpenGLMobject.arrange_in_grid.<locals>.<listcomp>.<genexpr>  s.      66QQ
 666666rT   r  )r'  r  r  r  s    @rR   r)  z1OpenGLMobject.arrange_in_grid.<locals>.<listcomp>  sM     
 
 
;<C66666%++66666
 
 
rT   measuresSequence[float]c                      d g|z   t                     |k    rt          | d           fdt          |          D             S )Nz has a mismatching size.c                8    g | ]}|         xn|         S rN   r   )r'  r   r  sizer  s     rR   r)  zEOpenGLMobject.arrange_in_grid.<locals>.init_sizes.<locals>.<listcomp>  s?        "'q)6HQK  rT   )r   r   r  )r  r  r  r{   r  s   ` ` @rR   
init_sizesz1OpenGLMobject.arrange_in_grid.<locals>.init_sizes  sz     }5zzS   D!B!B!BCCC     s   rT   r  r  )rk   rk   rk   )
r  r  r  r|   r  r  r{   r   rJ   rq   )r  r|   r  rq   r  r  r{   r   rt  r?   rJ   r  )r  r   rJ   r   )r  r  rJ   r  )r  r  rJ   r  )
r  r  r  rq   r  r  r{   r   rJ   r  )manim.mobject.geometry.liner  r   r   
get_centerr
   r   sqrtr   r   r   tupleUPORIGINDOWNRIGHTLEFTjoinr   r   rA   extendr  move_to)%rL   r  r  r=  r  r  r  r  r  r  r}   r  	start_posr  buff_xbuff_yr  row_alignments_seqcol_alignments_seqmappervalid_flow_ordersr  placeholdermeasured_heigthsmeasured_widthsr  r  r  xyr  r  	alignmentliner  r  r  s%    `` `                             @@@rR   arrange_in_gridzOpenGLMobject.arrange_in_grid(  s   L 	544444$$&&OO%%		 	 	 	& y~z5AAy~{EBB <DLD		**++D
 <D		D())D<D		D())D$;T""OPPP dE"" 	#!WF!WFF""FV	B 	B 	B 	B 	B 	B 2A6--2
 2
 2AV%002
 2
 9888EEEEE++++8888888888EEEEE++++8888	8
 	8
 V## #)G)G)G)G)G H HWCTWWW   !,  	Q666 X6BBB XBPPP XP	 	 	 	 %W%788gk**#oo
 	[MTD[3t99%<=>>>XXXXXXERVKKXXX
 
 
 
 
AFt
 
 

 
 
 
 
@Ed
 
 

	 	 	 	 *[$0@-PPJo|LL1t 	% 	%AA4[[ ( (71:[00 21 58J18M MI4E	AF*VAY%/1wqz>R2GG D GAJ&&tY777VAY''f$$AAYrT   n_rowsn_colsr   float | NonerV   c                    |                      ||z            } |j        ||fi | ||                    |           |S )zi
        Returns a new mobject containing multiple copies of this one
        arranged in a grid
        )	duplicater  
set_height)rL   r  r  r   r}   r  s         rR   get_gridzOpenGLMobject.get_grid;  sS     ~~fvo..VV66v666OOF###rT   nc                d                                         fdt          |          D              S )zIReturns an :class:`~.OpenGLGroup` containing ``n`` copies of the mobject.c                8    g | ]}                                 S r   r   )r'  r  rL   s     rR   r)  z+OpenGLMobject.duplicate.<locals>.<listcomp>N  s!    'F'F'F		'F'F'FrT   )rF  r  )rL   r  s   ` rR   r  zOpenGLMobject.duplicateL  s7    %t##%%'F'F'F'FU1XX'F'F'FGGrT   c                    | d         S r,  r   )ps    rR   r  zOpenGLMobject.<lambda>R  s
    ad rT   point_to_num_funcCallable[[Point3DLike], float]submob_func%Callable[[OpenGLMobject], Any] | Nonec                    || j                             |           n| j                             fd           | S )zOSorts the list of :attr:`submobjects` by a function defined by ``submob_func``.N)r   c                >     |                                            S rN   )r  )r]  r  s    rR   r  z$OpenGLMobject.sort.<locals>.<lambda>Y  s    0A0A!,,..0Q0Q rT   )r   sort)rL   r  r  s    ` rR   r  zOpenGLMobject.sortP  sQ     "!!k!2222!!&Q&Q&Q&Q!RRRrT   c                    |r | j         D ]}|                    d           t          j        | j                    |                                  | S )a  Shuffles the order of :attr:`submobjects`

        Examples
        --------

        .. manim:: ShuffleSubmobjectsExample

            class ShuffleSubmobjectsExample(Scene):
                def construct(self):
                    s= OpenGLVGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
                    s2= s.copy()
                    s2.shuffle()
                    s2.shift(DOWN)
                    self.play(Write(s), Write(s2))
        TrX  )r   shufflerandomrV  rL   rX  r   s      rR   r  zOpenGLMobject.shuffle\  s_       	-* - -t,,,,t'(((rT   	recursivec                    |r | j         D ]}|                    d           | j                                          |                                  | S )aQ  Inverts the list of :attr:`submobjects`.

        Parameters
        ----------
        recursive
            If ``True``, all submobject lists of this mobject's family are inverted.

        Examples
        --------

        .. manim:: InvertSumobjectsExample

            class InvertSumobjectsExample(Scene):
                def construct(self):
                    s = VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
                    s2 = s.copy()
                    s2.invert()
                    s2.shift(DOWN)
                    self.play(Write(s), Write(s2))
        T)r  )r   invertr  rV  )rL   r  r   s      rR   r  zOpenGLMobject.inverts  sa    *  	.* . .----  """rT   shallowc                F   |s|                                  S | j        }g | _        t          j        |           }|| _        t          | j                  |_        | j        D ])}| j        |                                         |j        |<   *t          | j                  |_        g |_         |j        d | j        D               |                    |            | j	        |_	        | 
                                }t          | j                                                  D ]\  }}t          |t                    r+||v r'|| ur#t!          |||                                           t          |t"          j                  r#t!          |||                                           |S )a  Create and return an identical copy of the :class:`OpenGLMobject` including all
        :attr:`submobjects`.

        Returns
        -------
        :class:`OpenGLMobject`
            The copy.

        Parameters
        ----------
        shallow
            Controls whether a shallow copy is returned.

        Note
        ----
        The clone is initially not visible in the Scene, even if the original was.
        c              3  >   K   | ]}|                                 V  d S rN   r  r&  s     rR   r3  z%OpenGLMobject.copy.<locals>.<genexpr>  s*      @@27799@@@@@@rT   )deepcopyr   r   dictr   r   r   rh  match_updatersr   rO   r  __dict__r   r   rA   r   r   r   )rL   r  r   copy_mobjectr   r   r   r   s           rR   r   zOpenGLMobject.copy  s   $  	#==??" ,y OO9 	; 	;C%)Ys^%8%8%:%:Lc"" !%T] 3 3#% @@t/?@@@AA##D))).2.I+ "" 3 3 5 566 	: 	:KD%5-00:VOO%%dEJJLL999%,, :dEJJLL999 rT   c                X    | j         }g | _         t          j        |           }|| _         |S rN   )r   r   r  )rL   r   results      rR   r  zOpenGLMobject.deepcopy  s+    ,t$$rT   use_deepcopyc                    d | _         |r|                                 | _         n|                                 | _         | j         S rN   )targetr  r   rL   r  s     rR   generate_targetzOpenGLMobject.generate_target  s9    ,0 	&--//DKK))++DK{rT   c                    t          | d          rd| _        |r|                                 | _        n|                                 | _        | S )zfSave the current state (position, color & size). Can be restored with :meth:`~.OpenGLMobject.restore`.saved_stateN)rZ  r  r  r   r  s     rR   
save_statezOpenGLMobject.save_state  sL    4'' 	:59D 	+#}}D#yy{{DrT   c                    t          | d          r| j        t          d          |                     | j                   | S )zURestores the state that was previously saved with :meth:`~.OpenGLMobject.save_state`.r  Nz&Trying to restore without having saved)rZ  r  	Exceptionbecomer   s    rR   restorezOpenGLMobject.restore  sF    t]++ 	Ft/?/GDEEED$%%%rT   c                >    g | _         g | _        d| _        d| _        d S r.  )time_based_updatersnon_time_updatershas_updatersupdating_suspendedr   s    rR   r   zOpenGLMobject.init_updaters  s(    >@ ?A"'(-rT   r   dtc                    | j         r2| j        s+| j        D ]} || |           | j        D ]} ||            |r | j        D ]}|                    ||           | S rN   )r'  r(  r%  r&  r   update)rL   r)  rX  time_based_updaternon_time_updaterr   s         rR   r+  zOpenGLMobject.update  s     	'T%< 	'&*&> - -"""4,,,,$($: ' '   &&&& 	+* + +b'****rT   Sequence[_TimeBasedUpdater]c                    | j         S rN   )r%  r   s    rR   get_time_based_updatersz%OpenGLMobject.get_time_based_updaters  s    ''rT   c                2    t          | j                  dk    S r,  )r   r%  r   s    rR   has_time_based_updaterz$OpenGLMobject.has_time_based_updater  s    4+,,q00rT   Sequence[_Updater]c                X    t          d| j                  t          d| j                  z   S Nlist[_Updater])r   r%  r&  r   s    rR   get_updaterszOpenGLMobject.get_updaters  s3    $d&>??$d4C
 C
 
 	
rT   c                p    t          t          j        d |                                 D                        S )Nc              3  >   K   | ]}|                                 V  d S rN   r7  r&  s     rR   r3  z4OpenGLMobject.get_family_updaters.<locals>.<genexpr>  s,      MMRr00MMMMMMrT   )r  itchainrO   r   s    rR   get_family_updatersz!OpenGLMobject.get_family_updaters
  s0    BHMM4??;L;LMMMNOOOrT   update_functionrD   call_updaterc                B   dt          j        |          j        v r| j        }n| j        }|$t          d|                              |           n$t          d|                              ||           |                                  |r| 	                                 | S )Nr)  r6  )
inspect	signature
parametersr%  r&  r   r  rk  rU  r+  )rL   r>  ri  r?  updater_lists        rR   add_updaterzOpenGLMobject.add_updater  s     7$_55@@@3LL1L=!<0077HHHH!<0077OOO''))) 	KKMMMrT   c                    | j         | j        fD ]/}t          d|          }||v r|                    |           ||v 0|                                  | S r5  )r%  r&  r   rm  rU  )rL   r>  rD  s      rR   remove_updaterzOpenGLMobject.remove_updater#  sp    !5t7MN 	5 	5L 0,??L!\11##O444 "\11'')))rT   c                    g | _         g | _        |                                  |r| j        D ]}|                                 | S rN   )r%  r&  rU  r   clear_updatersr
  s      rR   rI  zOpenGLMobject.clear_updaters+  sX    #% !#''))) 	(* ( (%%''''rT   c                    |                                   |                                D ]}|                     |           | S rN   )rI  r7  rE  )rL   r   updaters      rR   r  zOpenGLMobject.match_updaters4  sK    ++-- 	& 	&GW%%%%rT   c                V    d| _         |r| j        D ]}|                    |           | S r<  )r(  r   suspend_updatingr
  s      rR   rM  zOpenGLMobject.suspend_updating:  s@    "& 	1* 1 1''0000rT   c                    d| _         |r| j        D ]}|                    |           | j        D ]}|                    dd           |r|                     d|           | S )NF)rX  r?  r   )r)  rX  )r(  r   resume_updatingr   r+  )rL   rX  r?  r   r   s        rR   rO  zOpenGLMobject.resume_updatingA  s    "' 	0* 0 0&&w////l 	F 	FF""5u"EEEE 	/KK1gK...rT   c                f    t          d |                                 D                       | _        | S )Nc              3  >   K   | ]}|                                 V  d S rN   r:  r2  s     rR   r3  z;OpenGLMobject.refresh_has_updater_status.<locals>.<genexpr>M  s.      PPs 0 0 2 2PPPPPPrT   )re  rO   r'  r   s    rR   rU  z(OpenGLMobject.refresh_has_updater_statusL  s0    PPdoo>O>OPPPPPrT   vectorc                >    |                      fdd d           | S )Nc                    | z   S rN   r   )rb   rR  s    rR   r  z%OpenGLMobject.shift.<locals>.<lambda>T  s    6F? rT   T)r  r  r  )rL   rR  s    `rR   shiftzOpenGLMobject.shiftR  s9    ""****"& 	# 	
 	
 	

 rT   scale_factor_kwargsc                @    |                      fd||d           | S )u  Scale the size by a factor.

        Default behavior is to scale about the center of the mobject.
        The argument about_edge can be a vector, indicating which side of
        the mobject to scale about, e.g., mob.scale(about_edge = RIGHT)
        scales about mob.get_right().

        Otherwise, if about_point is given a value, scaling is done with
        respect to that point.

        Parameters
        ----------
        scale_factor
            The scaling factor :math:`\alpha`. If :math:`0 < |\alpha| < 1`, the mobject
            will shrink, and for :math:`|\alpha| > 1` it will grow. Furthermore,
            if :math:`\alpha < 0`, the mobject is also flipped.
        kwargs
            Additional keyword arguments passed to
            :meth:`apply_points_function`.

        Returns
        -------
        OpenGLMobject
            The scaled mobject.

        Examples
        --------

        .. manim:: MobjectScaleExample
            :save_last_frame:

            class MobjectScaleExample(Scene):
                def construct(self):
                    f1 = Text("F")
                    f2 = Text("F").scale(2)
                    f3 = Text("F").scale(0.5)
                    f4 = Text("F").scale(-1)

                    vgroup = VGroup(f1, f2, f3, f4).arrange(6 * RIGHT)
                    self.add(vgroup)

        See also
        --------
        :meth:`move_to`

        c                    | z  S rN   r   )rb   rW  s    rR   r  z%OpenGLMobject.scale.<locals>.<lambda>  s    <&0 rT   T)r  r  r  rU  )rL   rW  r  r  rX  s    `   rR   scalezOpenGLMobject.scaleZ  s?    j 	""0000#!"&	 	# 	
 	
 	
 rT   factorc                8    dfd} | j         |fddi| | S )Nrb   r   rJ   c                0    | d d fxx         z  cc<   | S rN   r   )rb   rp   r\  s    rR   rH   z#OpenGLMobject.stretch.<locals>.func  s&    111c6NNNf$NNNMrT   r  Trb   r   rJ   r   rU  )rL   r\  rp   r}   rH   s    ``  rR   r   zOpenGLMobject.stretch  sN    	 	 	 	 	 	 	 	#"4NNtNvNNNrT   angleaxisc                <    |                      ||t                    S Nr  )rotater  )rL   r`  ra  s      rR   rotate_about_originz!OpenGLMobject.rotate_about_origin  s    {{5$F{;;;rT   c                N    t          ||           | j        fdfd|i| | S )z;Rotates the :class:`~.OpenGLMobject` about a certain point.c                .    t          j        |           S rN   )r   dot)rb   rot_matrix_Ts    rR   r  z&OpenGLMobject.rotate.<locals>.<lambda>  s    26&,77 rT   r  )r4   r  )rL   r`  ra  r  r}   rj  s        @rR   re  zOpenGLMobject.rotate  sU     1==""7777	
 	
#	
 	
 	
 	

 rT   c                0     | j         t          dz  |fi |S )a  Flips/Mirrors an mobject about its center.

        Examples
        --------

        .. manim:: FlipExample
            :save_last_frame:

            class FlipExample(Scene):
                def construct(self):
                    s= Line(LEFT, RIGHT+UP).shift(4*LEFT)
                    self.add(s)
                    s2= s.copy().flip()
                    self.add(s2)

        r   )re  TAU)rL   ra  r}   s      rR   flipzOpenGLMobject.flip  s$    " t{37D33F333rT   functionr;   c                j    t          |          dk    r
t          |d<   dfd} | j        |fi | | S )Nr   r  rb   r   rJ   c                4    t          j        d|           }|S r  )r   apply_along_axis)rb   r  rn  s     rR   multi_mapping_functionz<OpenGLMobject.apply_function.<locals>.multi_mapping_function  s    $&$7!V$L$LFMrT   r_  )r   r  r  )rL   rn  r}   rr  s    `  rR   apply_functionzOpenGLMobject.apply_function  s_    v;;!$*F=!	 	 	 	 	 	 	#"#9DDVDDDrT   c                f    |                       ||                                                      | S rN   )r  r  )rL   rn  s     rR   apply_function_to_positionz(OpenGLMobject.apply_function_to_position  s-    XXdoo//00111rT   c                D    | j         D ]}|                    |           | S rN   )r   ru  )rL   rn  r   s      rR   &apply_function_to_submobject_positionsz4OpenGLMobject.apply_function_to_submobject_positions  s0    & 	8 	8F--h7777rT   matrixr<   c                    d|vrd|vr
t           |d<   t          j        | j                  t          j        |          }|d |j        d         d |j        d         f<    | j        fdfi | | S )Nr  r  r   rj   c                8    t          j        | j                  S rN   )r   ri  T)rb   full_matrixs    rR   r  z,OpenGLMobject.apply_matrix.<locals>.<lambda>  s    26&+-88 rT   )r  r   identityrp   r   shaper  )rL   rx  r}   r|  s      @rR   apply_matrixzOpenGLMobject.apply_matrix  s    ''l&.H.H$*F=!k$(++&!!<B%fl1o%'8a'889""8888	
 	
<B	
 	
 	
 rT   Callable[[complex], complex]c                ,    dfd} | j         |fi |S )a  Applies a complex function to a :class:`OpenGLMobject`.
        The x and y coordinates correspond to the real and imaginary parts respectively.

        Example
        -------

        .. manim:: ApplyFuncExample

            class ApplyFuncExample(Scene):
                def construct(self):
                    circ = Circle().scale(1.5)
                    circ_ref = circ.copy()
                    circ.apply_complex_function(
                        lambda x: np.exp(x*1j)
                    )
                    t = ValueTracker(0)
                    circ.add_updater(
                        lambda x: x.become(circ_ref.copy().apply_complex_function(
                            lambda x: np.exp(x+t.get_value()*1j)
                        )).set_color(BLUE)
                    )
                    self.add(circ_ref)
                    self.play(TransformFromCopy(circ_ref, circ))
                    self.play(t.animate.set_value(TAU), run_time=3)
        r]   r   rJ   c                    | \  }}} t          ||                    }t          j        |j        |j        |g          S rN   )complexr   r   realimag)r]   r  r  z
xy_complexrn  s        rR   R3_funcz5OpenGLMobject.apply_complex_function.<locals>.R3_func  s@    GAq!!'!Q--00J8Z_joqABBBrT   )r]   r   rJ   r   )rs  )rL   rn  r}   r  s    `  rR   apply_complex_functionz$OpenGLMobject.apply_complex_function  sD    :	C 	C 	C 	C 	C 	C
 #t"755f555rT   c                   | j         | j        S | j        g}| }|j         -|                    |j         j                   |j         }|j         -t          j                            t          t          |                              S rN   )r   rx   r  r   linalg	multi_dotr  reversed)rL   model_matricescurrent_objects      rR   hierarchical_model_matrixz'OpenGLMobject.hierarchical_model_matrix
  s    ;$$+,#/!!."7"DEEE+2N #/ y""4(@(@#A#ABBBrT         ?
wag_factorc                   |                                  D ]}t          j        |j        t          j        |                    }|t          |          z  }|t          |          z  }||z  }|                    |j        t          j        |                    t          |          df          t          j
        |                              d|j        f                    z              | S r  )r^  r   ri  rb   	transposer4  r5  r   reshaper   r   rp   )rL   rt  ra  r  rQ   alphass         rR   wagzOpenGLMobject.wag  s     2244 	 	CVCJT(:(:;;Fc&kk!Fc&kk!FZ'FNN
&NNCKK#344HY''//CG==     rT   c                V    |                      |                                             | S )z-Moves the mobject to the center of the Scene.)rV  r  r   s    rR   ru  zOpenGLMobject.center+  s&    

DOO%%%&&&rT   c                <   t          j        |          t          d         t          d         dfz  }|                     |          }||z
  |t          j        |          z  z
  }|t          t          j        |                    z  }|                     |           | S )zn
        Direction just needs to be a vector pointing towards side or
        corner in the 2d plane.
        frame_x_radiusframe_y_radiusr   )r   signr   r  asarrayabsrV  )rL   rt  r=  target_pointpoint_to_align	shift_vals         rR   align_on_borderzOpenGLMobject.align_on_border0  s     wy))#$#$-
 

 44Y?? >1D2:i;P;P4PP	BGI$6$6 7 77	

9rT   cornerc                .    |                      ||          S rN   r  )rL   r  r=  s      rR   	to_cornerzOpenGLMobject.to_cornerD  s    
 ##FD111rT   edgec                .    |                      ||          S rN   r  )rL   r  r=  s      rR   to_edgezOpenGLMobject.to_edgeK  s    
 ##D$///rT   )rj   rj   rj   mobject_or_pointOpenGLMobject | Point3DLikealigned_edgesubmobject_to_alignOpenGLMobject | Noneindex_of_submobject_to_align	coor_maskc                j   t          j        |          }t          j        |          }	t          |t                    r(|}
|	|
|         }n|
}|                    |	|z             }n|}||}n|	| |         }n| }|                    |	|z
            }|                     ||z
  ||z  z   |z             | S )a=  Move this :class:`~.OpenGLMobject` next to another's :class:`~.OpenGLMobject` or coordinate.

        Examples
        --------

        .. manim:: GeometricShapes
            :save_last_frame:

            class GeometricShapes(Scene):
                def construct(self):
                    d = Dot()
                    c = Circle()
                    s = Square()
                    t = Triangle()
                    d.next_to(c, RIGHT)
                    s.next_to(c, LEFT)
                    t.next_to(c, DOWN)
                    self.add(d, c, s, t)

        )r   r  r   rA   r  rV  )rL   r  rt  r=  r  r  r  r  np_directionnp_aligned_edgerQ   target_alignerr  alignerr  s                  rR   rz  zOpenGLMobject.next_toR  s    < z),,*\22 &66 
	,"C+7!$%A!B!$)@@,. LL ,L*)GG)578GGG 77,8VWW

L>1D<4GG9TUUUrT   c                   t           d         t           d         g}t          t          t          t          fD ]}t          j        t          j        |                    }|                    dt                    }||         |z
  }| 
                    |          }t          j        ||          |k    r|                     ||           | S )Nr  r  r=  )r=  )r   r  r  r  r  r   argmaxr  getDEFAULT_MOBJECT_TO_EDGE_BUFFERget_edge_centerri  r  )rL   r}   space_lengthsvectrp   r=  max_valedge_centers           rR   shift_onto_screenzOpenGLMobject.shift_onto_screen  s    #$#$&
 dE) 	. 	.D)BF4LL))C **V-KLLD#C(4/G..t44Kvk4((722T---rT   c                v   |                                  d         t          j        k    rdS |                                 d         t          j        k     rdS |                                 d         t          j        k    rdS t          t          |                                 d                   t          j         k     S )Nr   Trj   )	get_leftr   r  	get_right
get_bottomr  r   ro   get_topr   s    rR   is_off_screenzOpenGLMobject.is_off_screen  s    ==??1 5554>>A!6664??Q&"7774E4<<>>!,--1F0FFFrT   c                2    |                      |||          S rc  r   )rL   r\  rp   r]   s       rR   stretch_about_pointz!OpenGLMobject.stretch_about_point  s    ||FCU|;;;rT   lengthr   c                    |                      |          }|dk    r| S |r | j        ||z  |fi | n | j        ||z  fi | | S r,  )r   r   r[  )rL   r  rp   r   r}   
old_lengths         rR   r   zOpenGLMobject.rescale_to_fit  su     ))#..
??K 	6DL*,c<<V<<<<DJv
*55f555rT   r   c                $     | j         |dfddi|S )a.  Stretches the :class:`~.OpenGLMobject` to fit a width, not keeping height/depth proportional.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> import numpy as np
            >>> sq = Square()
            >>> sq.height
            np.float64(2.0)
            >>> sq.stretch_to_fit_width(5)
            Square
            >>> sq.width
            np.float64(5.0)
            >>> sq.height
            np.float64(2.0)
        r   r   Tr   )rL   r   r}   s      rR   stretch_to_fit_widthz"OpenGLMobject.stretch_to_fit_width  s&    0 #t"5!DDTDVDDDrT   c                $     | j         |dfddi|S )z^Stretches the :class:`~.OpenGLMobject` to fit a height, not keeping width/height proportional.rj   r   Tr   )rL   r   r}   s      rR   stretch_to_fit_heightz#OpenGLMobject.stretch_to_fit_height  s$    "t"61EEdEfEEErT   r   c                $     | j         |dfddi|S )z]Stretches the :class:`~.OpenGLMobject` to fit a depth, not keeping width/height proportional.rj   r   Tr   )rL   r   r}   s      rR   stretch_to_fit_depthz"OpenGLMobject.stretch_to_fit_depth  s$    "t"5!DDTDVDDDrT   c                $     | j         |dfd|i|S )a*  Scales the :class:`~.OpenGLMobject` to fit a width while keeping height/depth proportional.

        Returns
        -------
        :class:`OpenGLMobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> import numpy as np
            >>> sq = Square()
            >>> sq.height
            np.float64(2.0)
            >>> sq.scale_to_fit_width(5)
            Square
            >>> sq.width
            np.float64(5.0)
            >>> sq.height
            np.float64(5.0)
        r   r   r   )rL   r   r   r}   s       rR   	set_widthzOpenGLMobject.set_width  s&    : #t"5!GGWGGGGrT   c                $     | j         |dfd|i|S )z[Scales the :class:`~.OpenGLMobject` to fit a height while keeping width/depth proportional.rj   r   r   )rL   r   r   r}   s       rR   r  zOpenGLMobject.set_height  s&     #t"61HHgHHHHrT   c                $     | j         |dfd|i|S )z[Scales the :class:`~.OpenGLMobject` to fit a depth while keeping width/height proportional.r   r   r   )rL   r   r   r}   s       rR   	set_depthzOpenGLMobject.set_depth  s&     #t"5!GGWGGGGrT   c                    |                      ||          }t          j        | j                  }||z
  ||<   |                     |           | S rN   )	get_coordr   r   rp   rV  )rL   r   rp   rt  curr
shift_vects         rR   	set_coordzOpenGLMobject.set_coord  sL     ~~c9--Xdh''
$,
3

:rT   r  c                0    |                      |d|          S )zPSet x value of the center of the :class:`~.OpenGLMobject` (``int`` or ``float``)r   r  )rL   r  rt  s      rR   set_xzOpenGLMobject.set_x      ~~aI...rT   r  c                0    |                      |d|          S )zPSet y value of the center of the :class:`~.OpenGLMobject` (``int`` or ``float``)rj   r  )rL   r  rt  s      rR   set_yzOpenGLMobject.set_y  r  rT   r  c                0    |                      |d|          S )zPSet z value of the center of the :class:`~.OpenGLMobject` (``int`` or ``float``)r   r  )rL   r  rt  s      rR   set_zzOpenGLMobject.set_z  r  rT         ?c                f     | j         |fi | | j        D ]}|                     d|z             | S Nr  )r[  r   )rL   r\  r}   r   s       rR   space_out_submobjectsz#OpenGLMobject.space_out_submobjects!  sL    
6$$V$$$& 	' 	'FLLv&&&&rT   point_or_mobjectPoint3DLike | OpenGLMobjectc                    t          |t                    r|                    |          }n|}|                     |          }|                     ||z
  |z             | S )zBMove center of the :class:`~.OpenGLMobject` to certain coordinate.)r   rA   r  rV  )rL   r  r  r  r  r  s         rR   r  zOpenGLMobject.move_to'  se     &66 	&%<<\JJFF%F44\BB

F^+y8999rT   dim_to_matchc                   |                                 s|j        s|                     d           | S |rCt          | j                  D ]-}|                     |                    |          |d           .n+|                     |                    |          |d           |                     |                                |                                 z
             | S )Nr   Tr   F)	r#  r   r[  r  rp   r   r   rV  r  )rL   r   r  r   r   s        rR   replacezOpenGLMobject.replace7  s     %%'' 	0C 	JJqMMMK 	48__ Q Q##G$;$;A$>$>4#PPPPQ ''55     
 	

7%%''$//*;*;;<<<rT   c                    |                      |||           |                    |          }|                     ||z   |z             | S rN   )r  r   r[  )rL   r   r  r   r=  r  s         rR   surroundzOpenGLMobject.surroundL  sM     	WlG444((66

FTMV+,,,rT   startendc                   |                                  \  }}||z
  }t          j        |dk              rt          d          t          j        |          t          j        |          z
  }t          j                            t          j        ||                    dk    r"t          t          j        ||                    nt          }| 
                    t          t          j                            |          t          j                            |          z            |           |                     t          ||          ||           |                     ||z
             | S )Nr   z(Cannot position endpoints of closed looprd  )r  ra  )get_start_and_endr   r?  r!  r   r  normcrossr3   OUTr[  ro   re  r2   rV  )rL   r  r  
curr_startcurr_end	curr_vecttarget_vectra  s           rR   put_start_and_end_onz"OpenGLMobject.put_start_and_end_onX  sG   #5577
Hz)	6)q.!! 	HFGGGhsmmbhuoo5 y~~bhy+>>??1DD bhy+66777 	
 	

")..--	y0I0IIJJ" 	 	
 	
 	
 	!)[99" 	 	
 	
 	

 	

5:%&&&rT   8ParsableManimColor | Iterable[ParsableManimColor] | Nonefloat | Iterable[float] | Nonec           	     V   |+t          j        d t          |          D                       }|t          |          }|}|{|                     |          D ]e}t	          ||j        v r|j        |         nt          j        d          t          |                    |j        |<   ||j        |         d d d df<   f|{|y|                     |          D ]c}t	          ||j        v r|j        |         nt          j        d          t          |                    |j        |<   ||j        |         d d df<   d|l|jt          j        d t          t          ||          ddiD                       }|                     |          D ]}|
                                |j        |<   | S )Nc                ,    g | ]}t          |          S r   )r%   )r'  r  s     rR   r)  z0OpenGLMobject.set_rgba_array.<locals>.<listcomp>y  s    ,U,U,U\!__,U,U,UrT   )rj   r^   r^   c                     g | ]\  }}g ||S r   r   )r'  rgbos      rR   r)  z0OpenGLMobject.set_rgba_array.<locals>.<listcomp>  s$    WWWvsA3WWWrT   rx  T)r   r   r+   rO   r-   r   r   r   ry  r,   r   )	rL   rl   rn   r{   rX  rgbs	opacitiesrQ   rd   s	            rR   set_rgba_arrayzOpenGLMobject.set_rgba_arrayq  s    #%8,U,Ugenn,U,U,U#V#VD((I w// - -!-&*ch&6&6CHTNNBHV<L<LcRVii" " )-qqq"1"u%% =W0w// 1 1!-&*ch&6&6CHTNNBHV<L<L	NN" " (1qqq!t$$ !4%'XWWii.H.H)VQU)V)VWWW& &E w// . .!&rT   r9   c                n    |                      |          D ]}|                                |j        |<   | S )a  Directly set rgba data from `rgbas` and optionally do the same recursively
        with submobjects. This can be used if the `rgbas` have already been generated
        with the correct shape and simply need to be set.

        Parameters
        ----------
        rgbas
            the rgba to be set as data
        name
            the name of the data attribute to be set
        recurse
            set to true to recursively apply this method to submobjects
        )rO   r   r   )rL   rd   r{   rX  rQ   s        rR   set_rgba_array_directz#OpenGLMobject.set_rgba_array_direct  s9    & ??7++ 	* 	*C"ZZ\\CHTNNrT   8ParsableManimColor | Sequence[ParsableManimColor] | Nonec                    |                      ||d           |t          j        |          | _        ||| _        |r!| j        D ]}|                    |d           | S )NFr  T)r  r"   r   rl   rn   r   r   )rL   rl   rn   rX  r   s        rR   r   zOpenGLMobject.set_color  s     	E7E::: #)%00DJ"DL 	6* 6 6   5555rT   c                |    |                      d |d           |r!| j        D ]}|                    |d           | S )NF)rl   rn   rX  Tr  )r  r   set_opacity)rL   rn   rX  r   s       rR   r
  zOpenGLMobject.set_opacity  sZ     	$GGG 	:* : :""7D"9999rT   c                >    t          | j        dd df                   S )Nr   r^   )r&   rd   r   s    rR   	get_colorzOpenGLMobject.get_color  s    $*QU+,,,rT   c                     | j         d         }|S r  )rd   )rL   rA  s     rR   get_opacityzOpenGLMobject.get_opacity  s    Jt$	rT   colorsr#   c                     | j         | S rN   )!set_submobject_colors_by_gradient)rL   r  s     rR   set_color_by_gradientz#OpenGLMobject.set_color_by_gradient  s    5t5v>>rT   c                &   t          |          dk    rt          d          t          |          dk    r
 | j        | S | j        }t	          |t          |                    }t          ||d          D ]\  }}|                    |           | S )Nr   zNeed at least one colorrj   Trw  )r   r!  r   r   r$   ry  )rL   r  r  
new_colorsrQ   rl   s         rR   r  z/OpenGLMobject.set_submobject_colors_by_gradient  s    v;;!5666[[A!4>6** #FCII66
dJt<<< 	! 	!JCMM%    rT   r	  darknessc                6    |                      d|z
  |          S )Nr  r  )r
  )rL   r  rX  s      rR   fadezOpenGLMobject.fade  s    h@@@rT   c                    | j         S rN   )rh   r   s    rR   	get_glosszOpenGLMobject.get_gloss  s
    zrT   c                D    |                      |          D ]	}||_        
| S rN   )rO   rh   )rL   rh   rX  rQ   s       rR   	set_glosszOpenGLMobject.set_gloss  s+    ??7++ 	 	CCIIrT   c                    | j         S rN   )ri   r   s    rR   
get_shadowzOpenGLMobject.get_shadow  s
    {rT   c                D    |                      |          D ]	}||_        
| S rN   )rO   ri   )rL   ri   rX  rQ   s       rR   
set_shadowzOpenGLMobject.set_shadow  s+    ??7++ 	  	 CCJJrT         ?ParsableManimColor | Nonec                h    ddl m}  || f||d|| _        |                     | j                   | S )a  Add a BackgroundRectangle as submobject.

        The BackgroundRectangle is added behind other submobjects.

        This can be used to increase the mobjects visibility in front of a noisy background.

        Parameters
        ----------
        color
            The color of the BackgroundRectangle
        opacity
            The opacity of the BackgroundRectangle
        kwargs
            Additional keyword arguments passed to the BackgroundRectangle constructor


        Returns
        -------
        :class:`OpenGLMobject`
            ``self``

        See Also
        --------
        :meth:`add_to_back`
        :class:`~.BackgroundRectangle`

        r   )BackgroundRectangle)rl   fill_opacity)%manim.mobject.geometry.shape_matchersr#  background_rectanglero  )rL   rl   rn   r}   r#  s        rR   add_background_rectanglez&OpenGLMobject.add_background_rectangle  sh    F 	NMMMMM9L9L:
 :
 :
 	:
 :
! 	2333rT   c                4    | j         D ]} |j        di | | S r   )r   r'  )rL   r}   
submobjects      rR   'add_background_rectangle_to_submobjectsz5OpenGLMobject.add_background_rectangle_to_submobjects$	  s5    * 	: 	:J/J/99&9999rT   c                N    |                                  D ]} |j        di | | S r   )r^  r'  )rL   r}   rQ   s      rR   6add_background_rectangle_to_family_members_with_pointszDOpenGLMobject.add_background_rectangle_to_family_members_with_points)	  s@     2244 	3 	3C(C(2262222rT   c                    |                                  t          j        |          dz                       t                    t          j        fdt          d          D                       S )Nrj   c                8    g | ]}|                  |         S r   r   )r'  r   r@  indicess     rR   r)  z8OpenGLMobject.get_bounding_box_point.<locals>.<listcomp>5	  s&    ===qGAJ*===rT   r^   )r  r   r  astyperq   r   r  )rL   rt  r@  r/  s     @@rR   r  z$OpenGLMobject.get_bounding_box_point2	  se    ""$$79%%)11#66x=====E!HH===>>>rT   c                ,    |                      |          S )z+Get edge coordinates for certain direction.r  rL   rt  s     rR   r  zOpenGLMobject.get_edge_center7	      **9555rT   c                ,    |                      |          S )z-Get corner coordinates for certain direction.r2  r3  s     rR   
get_cornerzOpenGLMobject.get_corner;	  r4  rT   c                6    |                                  d         S )zGet center coordinates.rj   )r  r   s    rR   r  zOpenGLMobject.get_center?	  s    $$&&q))rT   c                P    |                                                      d          S r,  )r*  meanr   s    rR   get_center_of_massz OpenGLMobject.get_center_of_massC	  s"    ""$$))!,,,rT   c                l   |                                  }||                                 z
  }t          j                            |d          }|t          j        |d                              t          |          df          z  }t          j        t          j	        ||                    }||         S )Nrj   )ra  r^   )
r*  r  r   r  r  repeatr  r   r  ri  )rL   rt  r6  boundary_directionsnormsri  s         rR   get_boundary_pointz OpenGLMobject.get_boundary_pointF	  s    ((**
(4??+<+<<	2;;ry22::CJJ?KKK	"&!4i@@AA%  rT   c                .   |                                  \  }}}||z
  }t          j        |          }||t          j        t          j        t          j        ||t          j        t          |                    |dk                                  z  z   S )Nr   )outwhere)r  r   r  r5  r  true_divider   r   )rL   rt  _dlru  r  corner_vectr  s          rR   !get_continuous_bounding_box_pointz/OpenGLMobject.get_continuous_bounding_box_pointN	  s    //11VR6kz),,rvF \!2!233'A-	   	(
 	(
 	
 	
 		
rT   c                6    |                      t                    S )zBGet top coordinates of a box bounding the :class:`~.OpenGLMobject`)r  r  r   s    rR   r  zOpenGLMobject.get_top]	      ##B'''rT   c                6    |                      t                    S )zEGet bottom coordinates of a box bounding the :class:`~.OpenGLMobject`)r  r  r   s    rR   r  zOpenGLMobject.get_bottoma	      ##D)))rT   c                6    |                      t                    S )zDGet right coordinates of a box bounding the :class:`~.OpenGLMobject`)r  r  r   s    rR   r  zOpenGLMobject.get_righte	  s    ##E***rT   c                6    |                      t                    S )zCGet left coordinates of a box bounding the :class:`~.OpenGLMobject`)r  r  r   s    rR   r  zOpenGLMobject.get_lefti	  rJ  rT   c                6    |                      t                    S )zGGet zenith coordinates of a box bounding a 3D :class:`~.OpenGLMobject`.)r  r  r   s    rR   
get_zenithzOpenGLMobject.get_zenithm	  s    ##C(((rT   c                6    |                      t                    S )z\Get nadir (opposite the zenith) coordinates of a box bounding a 3D :class:`~.OpenGLMobject`.)r  INr   s    rR   	get_nadirzOpenGLMobject.get_nadirq	  rH  rT   c                v    |                                  }t          |d         |d         z
  |                   }|S )Nr   r   )r  r  )rL   rp   r@  rA  s       rR   r   zOpenGLMobject.length_over_dimu	  s6    ""$$AA,--	rT   c                ,    |                      d          S )z!Returns the width of the mobject.r   r   r   s    rR   	get_widthzOpenGLMobject.get_widthz	      ##A&&&rT   c                ,    |                      d          S )z"Returns the height of the mobject.rj   r   r   s    rR   
get_heightzOpenGLMobject.get_height~	  rU  rT   c                ,    |                      d          S )z!Returns the depth of the mobject.r   r   r   s    rR   	get_depthzOpenGLMobject.get_depth	  rU  rT   r:   c                8    |                      |          |         S )z6Meant to generalize ``get_x``, ``get_y`` and ``get_z``r2  )rL   rp   rt  s      rR   r  zOpenGLMobject.get_coord	  s    **955c::rT   c                .    |                      d|          S )zOReturns x coordinate of the center of the :class:`~.OpenGLMobject` as ``float``r   r  r3  s     rR   get_xzOpenGLMobject.get_x	      ~~a+++rT   c                .    |                      d|          S )zOReturns y coordinate of the center of the :class:`~.OpenGLMobject` as ``float``rj   r\  r3  s     rR   get_yzOpenGLMobject.get_y	  r^  rT   c                .    |                      d|          S )zOReturns z coordinate of the center of the :class:`~.OpenGLMobject` as ``float``r   r\  r3  s     rR   get_zzOpenGLMobject.get_z	  r^  rT   c                h    |                                   t          j        | j        d                   S )zWReturns the point, where the stroke that surrounds the :class:`~.OpenGLMobject` starts.r   throw_error_if_no_pointsr   r   rb   r   s    rR   	get_startzOpenGLMobject.get_start	  s*    %%'''xA'''rT   c                h    |                                   t          j        | j        d                   S )zUReturns the point, where the stroke that surrounds the :class:`~.OpenGLMobject` ends.r  rd  r   s    rR   get_endzOpenGLMobject.get_end	  s*    %%'''xB(((rT   tuple[Point3D, Point3D]c                R    |                                  |                                 fS )z=Returns starting and ending point of a stroke as a ``tuple``.)rf  rh  r   s    rR   r  zOpenGLMobject.get_start_and_end	  s    ~~//rT   alphac                    | j         }t          dt          |          dz
  |          \  }}t          ||         ||dz            |          S )Nr   rj   )rb   r   r   r    )rL   rk  rb   r   subalphas        rR   r  z#OpenGLMobject.point_from_proportion	  sF    )!S[[1_eDD86!9fQUmX>>>rT   c                ,    |                      |          S )z&Abbreviation for point_from_proportionr
  )rL   rk  s     rR   pfpzOpenGLMobject.pfp	  s    ))%000rT   n_piecesc           	                                            g _        t          j        dd|dz             }t	           fdt          |d d         |dd          d          D              S )Nr   rj   c              3  p   K   | ]0\  }}                                                     ||          V  1d S rN   )r   pointwise_become_partial)r'  a1a2rL   templates      rR   r3  z+OpenGLMobject.get_pieces.<locals>.<genexpr>	  sU        B 88r2FF     rT   r  Trw  )r   r   r   linspacerV   ry  )rL   rp  r  rv  s   `  @rR   
get_pieceszOpenGLMobject.get_pieces	  s    99;;!Q8a<00    !&"+vabbz$GGG  
 	
rT   c                L    t          | d|           }|                                S )Nz_index_group)r   r  )rL   rz  s     rR   get_z_index_reference_pointz)OpenGLMobject.get_z_index_reference_point	  s%    ot<<'')))rT   c                P    |                      |                                          S )zCMatch the color with the color of another :class:`~.OpenGLMobject`.)r   r  r   s     rR   match_colorzOpenGLMobject.match_color	  s     ~~g//11222rT   c                F     | j         |                    |          |fi |S )zUMatch the specified dimension with the dimension of another :class:`~.OpenGLMobject`.)r   r   )rL   r   rp   r}   s       rR   match_dim_sizezOpenGLMobject.match_dim_size	  s/     #t"7#:#:3#?#?OOOOOrT   c                      | j         |dfi |S )zCMatch the width with the width of another :class:`~.OpenGLMobject`.r   r  rL   r   r}   s      rR   match_widthzOpenGLMobject.match_width	      "t"7A88888rT   c                      | j         |dfi |S )zEMatch the height with the height of another :class:`~.OpenGLMobject`.rj   r  r  s      rR   match_heightzOpenGLMobject.match_height	  r  rT   c                      | j         |dfi |S )zCMatch the depth with the depth of another :class:`~.OpenGLMobject`.r   r  r  s      rR   match_depthzOpenGLMobject.match_depth	  r  rT   c                Z    |                      |                    ||          ||          S )zOMatch the coordinates with the coordinates of another :class:`~.OpenGLMobject`.)rp   rt  )r  r  )rL   r   rp   rt  s       rR   match_coordzOpenGLMobject.match_coord	  s8     ~~c9--  
 
 	
rT   c                0    |                      |d|          S )zCMatch x coord. to the x coord. of another :class:`~.OpenGLMobject`.r   r  rL   r   rt  s      rR   match_xzOpenGLMobject.match_x	      I666rT   c                0    |                      |d|          S )zCMatch y coord. to the x coord. of another :class:`~.OpenGLMobject`.rj   r  r  s      rR   match_yzOpenGLMobject.match_y	  r  rT   c                0    |                      |d|          S )zCMatch z coord. to the x coord. of another :class:`~.OpenGLMobject`.r   r  r  s      rR   match_zzOpenGLMobject.match_z	  r  rT   c                    t          |t                    r|                    |          }n|}t          | j                  D ]+}||         dk    r|                     ||         ||           ,| S )a*  
        Examples:
        mob1.align_to(mob2, UP) moves mob1 vertically so that its
        top edge lines ups with mob2's top edge.

        mob1.align_to(mob2, alignment_vect = RIGHT) moves mob1
        horizontally so that it's center is directly above/below
        the center of mob2
        r   )r   rA   r  r  rp   r  )rL   r  rt  r]   rp   s        rR   align_tozOpenGLMobject.align_to	  sw     &66 	%$;;IFFEE$E?? 	; 	;C~""uSz3	:::rT   type[OpenGLGroup]c                    t           S rN   )rV   r   s    rR   rF  zOpenGLMobject.get_group_class
  s    rT   c                     t           S )z+Return the base class of this mobject type.)rA   r   rT   rR   get_mobject_type_classz$OpenGLMobject.get_mobject_type_class

  s
     rT   c                Z    |                      |           |                     |           | S rN   )align_family
align_datar   s     rR   align_data_and_familyz#OpenGLMobject.align_data_and_family
  s-    '"""   rT   c                l   t          |                                 |                                d          D ]\  }}|                    |           |j                                        |j                                        z  D ]}|dk    r	|j        |         }|j        |         }t          |          t          |          k    r&t          |t          |                    |j        |<   it          |          t          |          k    r%t          |t          |                    |j        |<   | S )NFrw  rb   )ry  rO   align_pointsr   keysr   r.   )rL   r   mob1mob2r   arr1arr2s          rR   r  zOpenGLMobject.align_data
  s    doo//1C1C1E1EeTTT 	N 	NJD$ d###y~~''$)..*:*:: N N(??y~y~t99s4yy((%<T3t99%M%MDIcNNYYT**%<T3t99%M%MDIcNN rT   c                    t          |                                 |                                          }| |fD ]}|                    |t                     | S )N)r   )r5  r#  r   r.   )rL   r   max_lenrQ   s       rR   r  zOpenGLMobject.align_points(
  s`    d))++W-C-C-E-EFF'? 	L 	LCg3JKKKKrT   c                \   | }|}t          |          }t          |          }||k    rL|                    t          d||z
                       |                    t          d||z
                       t          |j        |j        d          D ]\  }}|                    |           | S )Nr   Trw  )r   add_n_more_submobjectsr5  ry  r   r  )rL   r   r  r  n1n2sm1sm2s           rR   r  zOpenGLMobject.align_family.
  s    YYYY88''ArBw888''ArBw888D,d.>tLLL 	" 	"HCS!!!!rT   c                    |                                  }g |_        |                     d           |                     |           | S r,  )r  r   r   rh  )rL   r   s     rR   push_self_into_submobjectsz(OpenGLMobject.push_self_into_submobjects;
  s?    }}1rT   c                  
 |dk    r| S t          | j                  }|dk    r^|                                 

                    |                                 g           
fdt          |          D             | _        | S ||z   }t          j        |          |z  |z  fdt          |          D             }g }t          | j        |d          D ]\  }}|	                    |           t          d|          D ]X}|                                }	|
                                dk     r|	                    d           |	                    |	           Y|| _        | S )Nr   c                8    g | ]}                                 S r   r  )r'  knull_mobs     rR   r)  z8OpenGLMobject.add_n_more_submobjects.<locals>.<listcomp>K
  s!    BBBABBBrT   c                @    g | ]}|k                                     S r   )sum)r'  r   repeat_indicess     rR   r)  z8OpenGLMobject.add_n_more_submobjects.<locals>.<listcomp>O
  s*    JJJ.A-2244JJJrT   Trw  rj   )r   r   r   r   r  r  r   arangery  r  r  r
  )rL   r  r  r  split_factorsnew_submobsr   sfr  rp  r  r  s             @@rR   r  z$OpenGLMobject.add_n_more_submobjectsB
  s{   66K4#$$199yy{{H!2!2 3444BBBBqBBBDK)F++d2v=JJJJeDkkJJJd.dKKK 	/ 	/JFBv&&&1b\\ / /#[[]]
 %%''!++**1---"":..../ 'rT   mobject1mobject2	path_funcr>   c           
     R   | j         D ]~}|| j        v rt          | j         |                   dk    r+||j         vs	||j         vr>|dv r|nt          } ||j         |         |j         |         |          | j         |         dd<   | j        D ]}|dk    r0t          |j        |         |j        |         |          | j        |<   8t          t          t          j        |j        d                   t          j        |j        d                   |                    | j        d<   | S )aa  Turns this :class:`~.OpenGLMobject` into an interpolation between ``mobject1``
        and ``mobject2``.

        Examples
        --------

        .. manim:: DotInterpolation
            :save_last_frame:

            class DotInterpolation(Scene):
                def construct(self):
                    dotR = Dot(color=DARK_GREY)
                    dotR.shift(2 * RIGHT)
                    dotL = Dot(color=WHITE)
                    dotL.shift(2 * LEFT)

                    dotMiddle = OpenGLVMobject().interpolate(dotL, dotR, alpha=0.3)

                    self.add(dotL, dotR, dotMiddle)
        r   )rb   rc   Nrg   )r   r   r   r    r   r  r   r   )rL   r  r  rk  r  r   rH   s          rR   r    zOpenGLMobject.interpolate_
  sV   6 9 
	T 
	TCd+++49S>""a''(-''3hm+C+C #'A A A99{D $X]3%7s9KU S SDIcN111= 	 	C000%0%c*%c*& &c"" =B!23M!NOO!23M!NOO = =899 rT   abc                    | S )z
        Set points in such a way as to become only
        part of mobject.
        Inputs 0 <= a < b <= 1 determine what portion
        of mobject to become.

        Returns `self` to allow method chaining.
        r   )rL   r   r  r  s       rR   rs  z&OpenGLMobject.pointwise_become_partial
  s	     rT   r  r  r  match_centerc                   |rO|                     | j                   |                    | j                   |                    | j                   nE|r|                    |            |r|                    |            |r|                    |            |r'|	                    | 
                                           |                     |           t          |                                 |                                d          D ]9\  }}|                    |j                   |                    |j                   :|                     d           | S )a}  Edit all data and submobjects to be identical
        to another :class:`~.OpenGLMobject`

        .. note::

            If both match_height and match_width are ``True`` then the transformed :class:`~.OpenGLMobject`
            will match the height first and then the width

        Parameters
        ----------
        match_height
            If ``True``, then the transformed :class:`~.OpenGLMobject` will match the height of the original
        match_width
            If ``True``, then the transformed :class:`~.OpenGLMobject` will match the width of the original
        match_depth
            If ``True``, then the transformed :class:`~.OpenGLMobject` will match the depth of the original
        match_center
            If ``True``, then the transformed :class:`~.OpenGLMobject` will match the center of the original
        stretch
            If ``True``, then the transformed :class:`~.OpenGLMobject` will stretch to fit the proportions of the original

        Examples
        --------
        .. manim:: BecomeScene

            class BecomeScene(Scene):
                def construct(self):
                    circ = Circle(fill_color=RED, fill_opacity=0.8)
                    square = Square(fill_color=BLUE, fill_opacity=0.2)
                    self.add(circ)
                    self.wait(0.5)
                    circ.become(square)
                    self.wait(0.5)
        Trw  r  )r  r   r  r   r  r   r  r  r  r  r  r  ry  rO   r   r   r   r   r   )	rL   r   r  r  r  r  r   r  r  s	            rR   r"  zOpenGLMobject.become
  s_   V  
	*))$+666((444((4444 +$$T*** *##D))) *##D))) 	/OODOO--...'"""DOO--w/A/A/C/CDQQQ 	+ 	+HCLL"""S\****!!t!444rT   r  c                h    | j         rdS |                                  t          |          | _        dS )a3  
        To speed up some animations, particularly transformations,
        it can be handy to acknowledge which pieces of data
        won't change during the animation so that calls to
        interpolate can skip this, and so that it's not
        read into the shader_wrapper objects needlessly
        N)r'  refresh_shader_datar   r   )rL   r  s     rR   	lock_datazOpenGLMobject.lock_data
  s:      	F  """ #D		rT   c           	        t          |                                 |                                |                                d          D ]\  }|j                                        j                                        z  j                                        z  }|                    t          t          fd|                               | S )NFrw  c                `    t          j        j        |          j        |          k              S rN   )r   r?  r   )r   r  r  s    rR   r  z2OpenGLMobject.lock_matching_data.<locals>.<lambda>  s"    BF38C=CHSM+I$J$J rT   )ry  rO   r   r  r  r  filter)rL   r  r  r(  r  r  r  s        @@rR   lock_matching_dataz OpenGLMobject.lock_matching_data
  s      OO!!!!	
 
 
 	 	LBS 7<<>>CHMMOO3chmmooEDLLJJJJJ      rT   c                Z    |                                  D ]}t                      |_        d S rN   )rO   r   r   )rL   rQ   s     rR   unlock_datazOpenGLMobject.unlock_data	  s4    ??$$ 	) 	)C#&55C  	) 	)rT   c                    d| _         | S r  re   r   s    rR   fix_in_framezOpenGLMobject.fix_in_frame      !$rT   c                n    d| _         t          |                                           | _        d| _        | S )Nr  T)rf   r  r  rg   ru   r   s    rR   fix_orientationzOpenGLMobject.fix_orientation  s0    $'!(-doo.?.?(@(@%rT   c                    d| _         | S )Nrk   r  r   s    rR   unfix_from_framezOpenGLMobject.unfix_from_frame  r  rT   c                0    d| _         d| _        d| _        | S )Nrk   r   F)rf   rg   ru   r   s    rR   unfix_orientationzOpenGLMobject.unfix_orientation   s    $'!(1%rT   c                    d| _         | S r<  ru   r   s    rR   r   zOpenGLMobject.apply_depth_test'  s    rT   c                    d| _         | S r.  r  r   s    rR   deactivate_depth_testz#OpenGLMobject.deactivate_depth_test,  s    rT   old_codenew_codec                `    |                                  D ]}|                    ||           | S rN   )get_shader_wrapper_listreplace_code)rL   r  r  rS   s       rR   replace_shader_codez!OpenGLMobject.replace_shader_code3  s=     3355 	5 	5G  84444rT   	glsl_codec                2    |                      d|           | S )z
        Takes a snippet of code and inserts it into a
        context which has the following variables:
        vec4 color, vec3 point, vec3 unit_normal.
        The code should change the color variable
        z&///// INSERT COLOR FUNCTION HERE /////)r  )rL   r  s     rR   set_color_by_codezOpenGLMobject.set_color_by_code;  s      	  !I9UUUrT               @viridisglsl_snippet	min_value	max_valuecolormapc                    dD ]}|                     |d|z             }t          |          }|                     d| dt          |           dt          |           dt	          |           d	           | S )za
        Pass in a glsl expression in terms of x, y and z which returns
        a float.
        xyzzpoint.zcolor.rgb = float_to_color(z, z);)r  get_colormap_listr  ro   r   )rL   r  r  r  r  charrgb_lists          rR   set_color_by_xyz_funcz#OpenGLMobject.set_color_by_xyz_funcE  s      	G 	GD'//hoFFLL %X.. B,  B  B%	:J:J  B  BeT]N^N^  B  Bbst|b}b}  B  B  B	
 	
 	
 rT   c                R    |                                                                   | S rN   )get_shader_wrapper
refresh_idr   s    rR   rP   z'OpenGLMobject.refresh_shader_wrapper_id^  s%    !!,,...rT   'ShaderWrapper'c           	         ddl m}  ||                                 |                                 |                                 | j        | j        | j        | j        j	                  | _
        | j
        S )Nr   r6   )	vert_datavert_indicesr   ru   rs   rr   ra   )manim.renderer.shader_wrapperr7   get_shader_dataget_shader_vert_indicesget_shader_uniformsru   rs   rr   r   ra   shader_wrapper)rL   r7   s     rR   r  z OpenGLMobject.get_shader_wrapperb  s    ??????
 .;]**,,5577--//,!2.6.
 .
 .
 ""rT   Sequence['ShaderWrapper']c                \   t          j        |                                 ggd | j        D             R  }t	          |d           }g }|D ]a\  }}|d         }|                                s" |j        |dd            t          |j                  dk    r|	                    |           b|S )Nc              3  >   K   | ]}|                                 V  d S rN   )r  r&  s     rR   r3  z8OpenGLMobject.get_shader_wrapper_list.<locals>.<genexpr>v  s.      FFrb((**FFFFFFrT   c                *    |                                  S rN   )get_id)sws    rR   r  z7OpenGLMobject.get_shader_wrapper_list.<locals>.<lambda>x  s    		 rT   r   rj   )
r;  r<  r  r   r)   is_validcombine_withr   r  r  )rL   shader_wrappersbatchesr  wrapper_groupr  r  s          rR   r  z%OpenGLMobject.get_shader_wrapper_lists  s    ($$&&'
FFT5EFFF
 
 
 $O5K5KLL(* ' 	. 	.M1*1-N!**,, 'N'qrr):;;>+,,q00n---rT   r   rZ   data_keyc                    t          | j        |                   }|dk    rC|t          |          k    r0t          | j        |         t          |                    | j        |<   | S r  )r   r   r/   )rL   r   r  d_lens       rR   check_data_alignmentz"OpenGLMobject.check_data_alignment  sa     DIh'((A::%3u::--";	(#E

# #DIh rT   c                    | j         }t          t          t          j        t          |          | j                            }|S )N)dtype)rb   r   rZ   r   r   r   r_   )rL   r  rb   shader_datas       rR   get_resized_shader_data_arrayz+OpenGLMobject.get_resized_shader_data_array  s8     ;VDDU(V(V(VWWrT   r  shader_data_keyc                h    || j         v rd S |                     ||           | j        |         ||<   d S rN   )r   r
  r   )rL   r  r  r  s       rR   read_data_to_shaderz!OpenGLMobject.read_data_to_shader  sD     t,,,F!!+x888'+y':O$$$rT   c                    |                      |                                           }|                     |dd           |S )Nr]   rb   )r  r#  r  )rL   r  s     rR   r  zOpenGLMobject.get_shader_data  s?    889L9L9N9NOO  gx@@@rT   c                .    |                                   d S rN   )r  r   s    rR   r  z!OpenGLMobject.refresh_shader_data  s    rT   c                    | j         S rN   r   r   s    rR   r  z!OpenGLMobject.get_shader_uniforms  s
    }rT   Sequence[int] | Nonec                    | j         S rN   )r   r   s    rR   r  z%OpenGLMobject.get_shader_vert_indices  s    ""rT   list[OpenGLMobject]c                4    t          | d          r| j        ng S )Nr   )rZ  r   r   s    rR   r   zOpenGLMobject.submobjects  s    $+D.$A$AIt  rIrT   submobject_listc                8     | j         | j           | j        |  d S rN   )rm  r   rh  )rL   r  s     rR   r   zOpenGLMobject.submobjects  s)    T%&&/""""rT   c                    |                                  sBd}t          j        d          j        j        }t          |                    |                    d S )Nz?Cannot call OpenGLMobject.{} for a OpenGLMobject with no pointsrj   )r  sys	_getframef_codeco_namer!  format)rL   messagecaller_names      rR   re  z&OpenGLMobject.throw_error_if_no_points  sW       	9V  -**19KGNN;77888	9 	9rT   )rl   rm   rn   ro   rp   rq   rh   ro   ri   ro   rr   rq   rs   rt   ru   rv   re   rv   rf   rv   rw   rv   rx   ry   rz   rv   r{   r|   r}   r   )r   r   rJ   r   )r   r   r   r   rJ   r   )r}   r   rJ   r   )rJ   r   )r   r   rJ   r   )r   r   rJ   r   )rJ   r   )r}   r   rJ   r   )r   r   rJ   r   )r   r   rJ   r   )rJ   r   rJ   ro   )r   ro   rJ   r   )r   rq   r   r   rJ   r   )rb   r   rJ   r   )rH   r   rJ   r   )rJ   r   )r  r   rJ   r   )rJ   r   rJ   r   )
rH   r=   r  r  r  r  r  rv   rJ   r   )r   rA   rJ   r   )rJ   rq   )rJ   r   )rJ   rv   )FT)r  rv   r:  rv   rJ   r   )r]   r   r=  ro   rJ   rv   )r   rC  rJ   rA   )rJ   rJ  )rJ   rP  )T)rX  rv   rJ   rP  )r`  rA   r_  rv   rJ   r   )F)ri  rq   r   rA   r_  rv   rJ   r   )r`  rA   rJ   r   )ri  rq   rp  rA   rJ   r   )rt  r@   ru  rv   r}   r   rJ   r   )r  r  r  r  r=  r  r  r@   r  r|   r  r|   r  r  r  r  r  r   r}   r   rJ   r   rN   )
r  rq   r  rq   r   r  r}   r   rJ   rV   )r  rq   rJ   rV   )r  r   r  r  rJ   r   )rX  rv   rJ   r   )r  rv   rJ   r   )r  rv   rJ   rA   )rJ   rA   )r  rv   rJ   rA   )r  rv   rJ   r   )r   T)r)  ro   rX  rv   rJ   r   )rJ   r.  )rJ   r3  r.  )r>  rD   ri  r  r?  rv   rJ   r   )r>  rD   rJ   r   )TT)rX  rv   r?  rv   rJ   r   )rR  r@   rJ   r   )
rW  ro   r  r  r  r  rX  r   rJ   r   )r\  ro   rp   rq   r}   r   rJ   r   )r`  ro   ra  r@   rJ   r   )
r`  ro   ra  r@   r  r  r}   r   rJ   r   )ra  r@   r}   r   rJ   r   )rn  r;   r}   r   rJ   r   )rn  r;   rJ   r   )rx  r<   r}   r   rJ   r   )rn  r  r}   r   rJ   r   )rJ   r<   )rt  r@   ra  r@   r  ro   rJ   r   )rt  r@   r=  ro   rJ   r   )r  r@   r=  ro   rJ   r   )r  r@   r=  ro   rJ   r   )r  r  rt  r@   r=  ro   r  r@   r  r  r  r  r  r@   rJ   r   r}   r   rJ   r   )r\  ro   rp   rq   r]   r   rJ   r   )
r  ro   rp   rq   r   rv   r}   r   rJ   r   )r   ro   r}   r   rJ   r   )r   ro   r}   r   rJ   r   )r   ro   r}   r   rJ   r   )r   ro   r   rv   r}   r   rJ   r   )r   ro   r   rv   r}   r   rJ   r   )r   ro   r   rv   r}   r   rJ   r   )r   ro   rp   rq   rt  r@   rJ   r   )r  ro   rt  r@   rJ   r   )r  ro   rt  r@   rJ   r   )r  ro   rt  r@   rJ   r   )r  )r\  ro   r}   r   rJ   r   )r  r  r  r@   r  r@   rJ   r   )r   F)r   rA   r  rq   r   rv   rJ   r   )
r   rA   r  rq   r   rv   r=  ro   rJ   r   )r  r   r  r   rJ   r   )NNrd   T)
rl   r  rn   r  r{   r   rX  rv   rJ   r   )rd   T)rd   r9   r{   r   rX  rv   rJ   r   r<  )rl   r  rn   r  rX  rv   rJ   r   )rn   r  rX  rv   rJ   r   )r  r#   rJ   r   )r	  T)r  ro   rX  rv   rJ   r   )rh   ro   rX  rv   rJ   r   )ri   ro   rX  rv   rJ   r   )Nr   )rl   r!  rn   ro   r}   r   rJ   r   )rt  r@   rJ   r   )rp   rq   rJ   ro   )rp   rq   rt  r@   rJ   r:   )rt  r@   rJ   r:   )rJ   ri  )rk  ro   rJ   r   )rp  rq   rJ   rA   )r   rA   rp   rq   r}   r   rJ   r   )r   rA   r}   r   rJ   r   )r   rA   rp   rq   rt  r@   rJ   r   )r   rA   rt  r@   rJ   r   )r  r  rt  r@   rJ   r   )rJ   r  )rJ   r   )r  rq   rJ   r   )
r  rA   r  rA   rk  ro   r  r>   rJ   r   )r   rA   r  ro   r  ro   rJ   r   )FFFFF)r   rA   r  rv   r  rv   r  rv   r  rv   r   rv   rJ   r   )r  r   rJ   r   )r  rA   r  rA   rJ   r   )r  r   r  r   rJ   r   )r  r   rJ   r   )r  r  r  )
r  r   r  ro   r  ro   r  r   rJ   r   )rJ   r  )rJ   r  )r   rZ   r  r   rJ   r   )r  ro   rJ   rZ   )r  rZ   r  r   r  r   rJ   r   )rJ   rZ   )rJ   r   )rJ   r  )rJ   r  )r  r   rJ   r   )r   
__module____qualname____doc____annotations__r   float32r_   ra   r'   rb   rc   rd   r(   re   rf   rg   rh   ri   r!   moderngl	TRIANGLESr   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   r   setterr   r   r-   r   r   r   r   r  r  r  r  r  r  r!  r#  r*  r  r  r/  r   MED_SMALL_BUFFrB  rH  rM  rO  rG  rV  rO   r^  rh  rk  rm  ro  rs  r  r}  r  r  r  r  r  r  r   r  r  r  r#  r   r+  r0  r2  r7  r=  rE  rG  rI  r  rM  rO  rU  rV  r[  r   r  rf  re  r  rm  rs  ru  rw  r  r  r  r  r  ru  r  r  r  r  r  !DEFAULT_MOBJECT_TO_MOBJECT_BUFFERr   rz  r  r  r  r   r  r  r  r  scale_to_fit_widthr  scale_to_fit_heightr  scale_to_fit_depthr  r  r  r  r  r  r  r  r  r  r  r   r
  r  r  r  r  r  r  r  r  r  r'  r*  r,  r  r  r6  r  r:  r?  rF  r  r  r  r  rN  rQ  r   rT  rW  rY  r  r]  r`  rb  rf  rh  r  r  ro  rx  r{  r}  r  r  r  r  r  r  r  r  r  rF  staticmethodr  r  r  r  r  r  r  r1   r    rs  r"  r  r  r  rU   r  r  r  r  r   r  r  r  r  rP   r  r  r
  r  r  r  r  r  r  r   re  __classcell__r   s   @rR   rA   rA   s   s          5444 
"*d#WL     $&M%%%% $)577F****).L0000$)EGGE++++#,9;;....&/ikk1111	      !y{{E""""!	F#### DI  ( 2/3 "'%* "'(,"-J1 J1 J1 J1 J1XS S S SB   2 - - - - - [- ' ' ' X'    X             /1 /1 /1 [/1b& & & &1 1 1 1      B   
   
 W' W' W' XW'r ' ' ' X'@ \5 5 5 \5 ' ' ' X'> ]5 5 5 ]5 ' ' ' X' \5 5 5 \5 FR                
   / / / /6 +/*0&+    @   (             ) ) ) )! ! ! !0 0 0 0* >B     1?    / / / /" " " "! ! ! !              @ @ @ @ CH S S S S S Sl IN    B FK            D/ / / /b    #(    >  ,:'-%)%)5948Q Q Q Q Qn  $	    "H H H H =KN=A
 
 
 
 
    .    <8 8 8 8 8t       	 	 	 	 	   . . . .	 	 	 	 	( ( ( (1 1 1 1
 
 
 

P P P P !"	    ,              	 	 	 	 	       +/)/	; ; ; ; ;z    FI < < < < < !*.	      )+ 4 4 4 4 4&
 
 
 
      

 
 
 
"6 "6 "6 "6H	C 	C 	C 	C #(!	    ,    5    ,  $d{42 2 2 2 2 "40 0 0 0 0 #(7%+4837"*"(999"5"55 5 5 5 5n   G G G G< < < < 	     E E E E4F F F FE E E E H H H H H> #
 I I I I I %
 H H H H H # AG     9? / / / / / 9? / / / / / 9? / / / / /     &,"*"(999"5"5	    & 	    0 $
 
 
 
 
   6 KO26$ $ $ $ $R 	    4 37	    & HL    - - - -   ? ? ? ?   A A A A A       
        ,0, , , , ,\   
   ? ? ? ?
6 6 6 66 6 6 6* * * *- - - -! ! ! !
 
 
 
( ( ( (* * * *+ + + +* * * *) ) ) )( ( ( (   
' ' ' '' ' ' '' ' ' ' =C ; ; ; ; ; /5 , , , , , /5 , , , , , /5 , , , , ,( ( ( (
) ) ) )
0 0 0 0? ? ? ?
1 1 1 1	
 	
 	
 	
* * * *3 3 3 3P P P P9 9 9 99 9 9 99 9 9 9
 KQ
 
 
 
 
 IO 7 7 7 7 7 IO 7 7 7 7 7 IO 7 7 7 7 7 #)    2       \   
   $            D #0-//6 6 6 6 6p     #!!"? ? ? ? ?F* * * *   () ) ) )                                !    2   # # # #"   "
 
 
 
   	; 	; 	; 	;   
      # # # # J J J XJ # # # #9 9 9 9 9 9 9 9rT   c                        e Zd Zd fdZ xZS )	rV   r`  rA   r}   r   rJ   r   c                N     t                      j        di |  | j        |  d S r   )r   r   rh  )rL   r`  r}   r   s      rR   r   zOpenGLGroup.__init__  s5    ""6"""(rT   )r`  rA   r}   r   rJ   r   )r   r&  r'  r   r6  r7  s   @rR   rV   rV     s=                 rT   rV   c                       e Zd Zeddfd fdZedd            Zedd            ZddZedd            Z	ddZ
 xZS )rW   gư>locationr   artificial_widthro   artificial_heightr}   r   rJ   r   c                    || _         || _         t                      j        di | |                     |           d S r   )r<  r=  r   r   set_location)rL   r;  r<  r=  r}   r   s        rR   r   zOpenGLPoint.__init__  sL     (8(9""6"""(#####rT   c                    | j         S rN   )r<  r   s    rR   rT  zOpenGLPoint.get_width  s    $$rT   c                    | j         S rN   )r=  r   s    rR   rW  zOpenGLPoint.get_height  s    %%rT   r   c                f    t          t          | j        d                                                   S r,  )r   r   rb   r   r   s    rR   get_locationzOpenGLPoint.get_location  s$    GT[^,,11333rT   argsr   c                *    |                                  S rN   )rC  )rL   rD  r}   s      rR   r  z"OpenGLPoint.get_bounding_box_point  s      """rT   new_locc                d    |                      t          j        |dt                               d S )Nr   )ndminr  )r   r   r   ro   )rL   rF  s     rR   r?  zOpenGLPoint.set_location  s+    ???@@@@@rT   )
r;  r   r<  ro   r=  ro   r}   r   rJ   r   r#  r$  )rD  r   r}   r   rJ   r   )rF  r   rJ   r   )r   r&  r'  r  r   r   rT  rW  rC  r  r?  r6  r7  s   @rR   rW   rW     s         !'"&#'	
$ 
$ 
$ 
$ 
$ 
$ 
$ % % % X% & & & X&4 4 4 4 # # # X#A A A A A A A ArT   rW   c                  .    e Zd ZddZdd	ZddZddZdS )rX   r   rA   rJ   r   c                    || _         | j                                          d | _        d| _        g | _        d| _        i | _        d S r.  )r   r  overridden_animationis_chainingmethodscannot_pass_args	anim_argsr   s     rR   r   z_AnimationBuilder.__init__  sI    &-$$&&&6:!!&-/ ',,.rT   r}   r   r   c                N    | j         rt          d          || _        d| _         | S )NzWAnimation arguments must be passed before accessing methods and can only be passed onceT)rN  r   rO  )rL   r}   s     rR   __call__z_AnimationBuilder.__call__  s8      	i     $rT   method_namer   Callable[..., Self]c                     t           j        j        |          t          d           j        rs j        rt          d          d
 fd}d	 _        d	 _        |S )N_override_animatezDMethod chaining is currently not supported for overridden animationsmethod_argsr   method_kwargsrJ   r   c                     r1 t          dj                  j        g| R dj        i|_        n1j                            t          | |                      | i | S )NzCallable[..., Animation]rO  )r   rU  r   rO  rK  rM  r  r   )rV  rW  has_overridden_animationmethodrL   s     rR   update_targetz4_AnimationBuilder.__getattr__.<locals>.update_target  s    ' 6-D.0H- - L- !	- - -
 #n- $- -)) ##N6;$V$VWWW5}555KrT   T)rV  r   rW  r   rJ   r   )r   r   r  rZ  rL  rK  NotImplementedErrorrN  )rL   rR  r[  rY  rZ  s   `  @@rR   __getattr__z_AnimationBuilder.__getattr__  s    ,k::#*63F#G#G  	!9 	d>W 	%V  	 	 	 	 	 	 	 	   $rT   'Animation'c                    ddl m} | j        p || j        | j                  }| j                                        D ]\  }}t          |||           |S )Nr   )_MethodAnimation)manim.animation.transformr`  rK  r   rM  rO  r   r   )rL   r`  animr   r   s        rR   buildz_AnimationBuilder.build"  sp    >>>>>> (X,<,<T\4<,X,X>//11 	' 	'KD%D$&&&&rT   N)r   rA   rJ   r   r%  )rR  r   rJ   rS  )rJ   r^  )r   r&  r'  r   rQ  r]  rc  r   rT   rR   rX   rX     se        
/ 
/ 
/ 
/	 	 	 	   @
 
 
 
 
 
rT   rX   
_Decorated).r5   c                      e Zd ZddZdS )_OverrideAnimateDecorator	decoratedrd  rJ   c                   d S rN   r   )rL   rg  s     rR   rQ  z"_OverrideAnimateDecorator.__call__4  s      rT   N)rg  rd  rJ   rd  )r   r&  r'  rQ  r   rT   rR   rf  rf  2  s        CCCCCCrT   rf  rZ  types.FunctionTypec                     d fd}|S )a  Decorator for overriding method animations.

    This allows to specify a method (returning an :class:`~.Animation`)
    which is called when the decorated method is used with the ``.animate`` syntax
    for animating the application of a method.

    .. seealso::

        :attr:`OpenGLMobject.animate`

    .. note::

        Overridden methods cannot be combined with normal or other overridden
        methods using method chaining with the ``.animate`` syntax.


    Examples
    --------

    .. manim:: AnimationOverrideExample

        class CircleWithContent(VGroup):
            def __init__(self, content):
                super().__init__()
                self.circle = Circle()
                self.content = content
                self.add(self.circle, content)
                content.move_to(self.circle.get_center())

            def clear_content(self):
                self.remove(self.content)
                self.content = None

            @override_animate(clear_content)
            def _clear_content_animation(self, anim_args=None):
                if anim_args is None:
                    anim_args = {}
                anim = Uncreate(self.content, **anim_args)
                self.clear_content()
                return anim

        class AnimationOverrideExample(Scene):
            def construct(self):
                t = Text("hello!")
                my_mobject = CircleWithContent(t)
                self.play(Create(my_mobject))
                self.play(my_mobject.animate.clear_content())
                self.wait()

    animation_methodrd  rJ   c                    | _         | S rN   )rU  )rk  rZ  s    rR   	decoratorz#override_animate.<locals>.decoratork  s    #3 rT   )rk  rd  rJ   rd  r   )rZ  rm  s   ` rR   override_animatern  7  s*    h            rT   )rH   rI   rJ   rI   )rZ  ri  rJ   rf  )p
__future__r   r   rA  	itertoolsr;  r	  r  typescollections.abcr   r   r   r   	functoolsr   r	   mathr
   typingr   r   r   r   r   r   r   r   r   r   r+  numpyr   numpy.typingnpttyping_extensionsr   manimr   r   manim.constantsmanim.data_structuresr   r  r   manim.typingr   r   r   r   manim.utils.bezierr   r    manim.utils.colorr!   r"   r#   r$   r%   r&   manim.utils.config_opsr'   r(   manim.utils.iterablesr)   r*   r+   r,   r-   r.   r/   r0   manim.utils.pathsr1   manim.utils.space_opsr2   r3   r4   manim.animation.animationr5   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   ro   r   rB   r)  rC   rD   rE   genericrF   rU   __all__voidrY   NDArrayrZ   rA   rV   rW   rX   rd  rf  rn  r   rT   rR   <module>r     s   " " " " " " "        



  B B B B B B B B B B B B * * * * * * * *                                              !                   0 0 0 0 0 0 ; ; ; ; ; ;            @ ? ? ? ? ? ? ?                4 3 3 3 3 3 3 3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 , + + + + +           /333333;;;;;;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 $,_e,Df,L#MMMMM&./@&/H&IIIII.1BBHBBBB	BGG2:...E
 
 
 
 O
N
N ' ! ! ! ! ~\2 2 2 2 2N-9 N-9 N-9 N-9 N-9 N-9 N-9 N-9bZ    -   A A A A A- A A A@B B B B B B B BJ W\2B)CDDD
D D D D D D D D
8 8 8 8 8 8rT   