
    lj                   X   U d Z ddlmZ g d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ZddlZddlZddlmZmZ ddlmZmZ ddlmZ ddlmZm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%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 erQddlm7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC ddlDmEZE edeFgeGf         ZHdeId<   edgeGf         ZJdeId<   eJeHz  ZKdeId<    G d d          ZL G d deLe          ZM G d d           ZN G d! d"          ZOd&d%ZPdS )'z/Base classes for objects that can be displayed.    )annotations)MobjectGroupoverride_animateN)CallableIterable)partialmethodreduce)Path)TYPE_CHECKINGAny)MethodWithArgs)ConvertToOpenGL   )configlogger)*)BLACKPURE_YELLOWWHITE
ManimColorParsableManimColorcolor_gradientinterpolate_color)MultiAnimationOverrideException)list_updateremove_list_redundancies)straight_path)angle_between_vectors	normalizerotation_matrix)Self	TypeAlias)
FunctionOverrideMappingFunctionMatrixMNMultiMappingFunctionPathFuncType
PixelArrayPoint3DPoint3DLikePoint3DLike_ArrayVector3DLike)	Animationr   r#   TimeBasedUpdaterNonTimeBasedUpdaterUpdaterc            	      &
    e Zd ZdZi ZedR fd            ZeddddfdSdZdTdZ	dUdZ
edVd            ZedRd            ZedWd             ZedRd!            ZedXd#            ZedYd$            ZdYd%ZdZd'ZdYd(Zd[d*Zd[d+Zd\d-Zd]d0Zd^d1Zd^d2Zd\d3Zd\d4Zd5 Zd6 ZdYd7Zd_d:Z ed`d;            Z!e!j"        dad=            Z!ed`d>            Z#e#j"        dad?            Z#ed`d@            Z$e$j"        dadA            Z$dbdCZ%dcdFZ&dddedHZ'dddRdIZ(dddfdJZ)dYdKZ*dgdhdOZ+didjdSZ,dkdUZ-dldVZ.dmdXZ/dmdYZ0	 	 dndod^Z1dpd_Z2dqdrd`Z3dsdaZ4dqdrdbZ5dqdrdcZ6dtdeZ7dudhZ8dddidvdoZ9e:fdwdrZ;e:fdddidxdsZ<e=fdddidydtZ>dddidzdvZ?dddid{dyZ@d|dzZAd|d{ZBdddid}d~ZCdddid~dZDdYdZEddZF	 	 dddZGd ZHdYdZIeJfddZKeLeJfddZMeNeJfddZOePeQeRdd eSjT        g d          fddZUdYdZVd ZWddZX	 dgddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_eRfddZ`eRfddZaeRfddZbeRfddZcdddZdeR eSjT        g d          fddZe	 dddZfddLegfddZhddZi	 dddZjdYdZkdYdZlemdPfddZnddĄZoddeepfddʄZqdd̄Zrddeepfdd̈́ZsdYd΄Zt	 dqddЄZudddӄZvddՄZwdYdքZxdYdׄZyddڄZzdd܄Z{dd߄Z|ddZ}ddZ~ddZ	 dddZddZddZddZddZddZddZddZddZddZddZddZddZddZddZeRfddZeRfddZeRfddZeRfddZddZddZddZddZdd ZddZddZdldZdldZdsdZddZdsd	Zdsd
ZdsdZeRfddZeRfdsdZeRfdsdZeRfdsdZeRfddZd Zd ZddZddZedd            ZddZdqddZddZePeQdPfddZddegeRdddddf	dd'Zd( dfdd-Zdgdd.Zdgdd/ZdYd0ZdYd1ZdRd2Zdgdd4Zddd5Zdsd6Zdd8Zdsd9Zd^d:ZdYd;Zdd>Zdd@Z e            fddEZddFZ	 	 	 	 	 dddKZÐdqddMZĐdRdNZ	 dqdÐdPZƐdYdQZǈ xZS (  r   a  Mathematical Object: base class for objects that can be displayed on screen.

    There is a compatibility layer that allows for
    getting and setting generic attributes with ``get_*``
    and ``set_*`` methods. See :meth:`set` for more details.

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

        .. seealso::

            :class:`~.VMobject`

    returnNonec                     t                      j        di | i | _        |                                  | j        | _        d S N )super__init_subclass__animation_overrides"_add_intrinsic_animation_overrides__init___original__init__)clskwargs	__class__s     P/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/mobject/mobject.pyr9   zMobject.__init_subclass__X   sQ    !!++F+++
  	 	..000 #    N   r   color-ParsableManimColor | list[ParsableManimColor]name
str | Nonedimintz_indexfloatc                <   || j         j        n|| _        || _        || _        || _        d | _        g | _        g | _        d| _	        t          j        |          | _        |                                  |                                  |                                  d S NF)r@   __name__rF   rH   targetrJ   
point_hashsubmobjectsupdatersupdating_suspendedr   parserD   reset_pointsgenerate_pointsinit_colors)selfrD   rF   rH   rO   rJ   s         rA   r<   zMobject.__init__c   s     04|DN++	')"'%e,,
rB   rQ   Iterable[Mobject]r"   c                8    |                      |t                    S )a  Check that all submobjects are actually instances of
        :class:`Mobject`, and that none of them is ``self`` (a
        :class:`Mobject` cannot contain itself).

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

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

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

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

        Raises
        ------
        TypeError
            If any of the values in `submobjects` is not a :class:`Mobject`.
        ValueError
            If there was an attempt to add a :class:`Mobject` as its own
            submobject.
        )"_assert_valid_submobjects_internalr   )rX   rQ   s     rA   _assert_valid_submobjectsz!Mobject._assert_valid_submobjectsy   s    < 66{GLLLrB   list[Mobject]	mob_classtype[Mobject]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
isinstancerN   typer   	TypeError
ValueError)rX   rQ   r^   isubmoberror_messages         rA   r[   z*Mobject._assert_valid_submobjects_internal   s    #;// 	 	IAvfi00 /09+= 0 0)-d)<0 00 0*+0 0 F||,0 0 0  fg.. !NM  ...~~ .$t**"5 . .(). . .   
 rB   animation_classtype[Animation]FunctionOverride | Nonec                2    || j         v r| j         |         S dS )a  Returns the function defining a specific animation override for this class.

        Parameters
        ----------
        animation_class
            The animation class for which the override function should be returned.

        Returns
        -------
        Optional[Callable[[Mobject, ...], Animation]]
            The function returning the override animation or ``None`` if no such animation
            override is defined.
        N)r:   )r>   rj   s     rA   animation_override_forzMobject.animation_override_for   s%    $ c555*?;;trB   c                    t          |           D ]U}|                    d          rt          | |          }t          |d          r|j        }|                     ||           VdS )zhInitializes animation overrides marked with the :func:`~.override_animation`
        decorator.
        ___override_animationN)dir
startswithgetattrhasattrrq   add_animation_override)r>   method_namemethodrj   s       rA   r;   z*Mobject._add_intrinsic_animation_overrides   s    
 s88 	D 	DK%%d++ S+..Fv455 D"("<**?FCCC	D 	DrB   override_funcr$   c                    || j         vr|| j         |<   dS t          d|j         d| j         d| j         |         j         d|j         d	          )a  Add an animation override.

        This does not apply to subclasses.

        Parameters
        ----------
        animation_class
            The animation type to be overridden
        override_func
            The function returning an animation replacing the default animation. It gets
            passed the parameters given to the animation constructor.

        Raises
        ------
        MultiAnimationOverrideException
            If the overridden animation was already overridden.
        zThe animation z for z( is overridden by more than one method: z and ra   N)r:   r   rN   __qualname__)r>   rj   ry   s      rA   rv   zMobject.add_animation_override   s    . #"9997DC#O44411!9 1 1<1 1*?;H1 1 !-1 1 1  rB   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     rA   set_defaultzMobject.set_default   s8    V  	1(@@@@CLLL0CLLLrB   _AnimationBuilder | Selfc                     t          |           S )a  Used to animate the application of any method of :code:`self`.

        Any method called on :code:`animate` is converted to an animation of applying
        that method on the mobject itself.

        For example, :code:`square.set_fill(WHITE)` sets the fill color of a square,
        while :code:`square.animate.set_fill(WHITE)` animates this action.

        Multiple methods can be put in a single animation once via chaining:

        ::

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

        .. warning::

            Passing multiple animations for the same :class:`Mobject` 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.

        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:`~.Mobject` 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 (see :meth:`.rotate`).
             If you want animations to consider the points between, consider using
             :class:`~.ValueTracker` with updaters instead (see :meth:`.add_updater`).

        )_AnimationBuilderrX   s    rA   animatezMobject.animate)  s    D !&&&rB   c                     t          |           S )a  Call a method on a mobject every frame.

        This is syntactic sugar for ``mob.add_updater(lambda m: m.method(*args, **kwargs), call_updater=True)``.
        Note that this will call the method immediately. If this behavior is not
        desired, you should use :meth:`add_updater` directly.

        .. warning::

            Chaining of methods is allowed, but each method will be added
            as its own updater. If you are chaining methods, make sure they
            do not interfere with each other or you may get unexpected results.

        .. warning::

            :attr:`always` is not compatible with :meth:`.ValueTracker.get_value`, because
            the value will be computed once and then never updated again. Use :meth:`add_updater`
            if you would like to use a :class:`~.ValueTracker` to update the value.

        Example
        -------

            .. manim:: AlwaysExample

                class AlwaysExample(Scene):
                    def construct(self):
                        sq = Square().to_edge(LEFT)
                        t = Text("Hello World!")
                        t.always.next_to(sq, UP)
                        self.add(sq, t)
                        self.play(sq.animate.to_edge(RIGHT))
        )_UpdaterBuilderr   s    rA   alwayszMobject.always  s    D t$$$rB   c           	     *   | j         }|                    |          }||t          |           <   | j                                        D ])\  }}t          ||t          j        ||                     *t          t          |                     |_	        |S N)
r@   __new__id__dict__itemssetattrcopydeepcopystroriginal_id)rX   clone_from_idr>   resultkvs         rA   __deepcopy__zMobject.__deepcopy__  s    nS!!"(bhhM'')) 	@ 	@DAqFAt}Q>>???? D]]rB   r   c                *    t          | j                  S r   )r   rF   r   s    rA   __repr__zMobject.__repr__  s    49~~rB   c                F    t          j        d| j        f          | _        | S )z)Sets :attr:`points` to be an empty array.r   )npzerosrH   pointsr   s    rA   rU   zMobject.reset_points  s    h48}--rB   objectc                    dS )zInitializes the colors.

        Gets called upon creation. This is an empty method that can be implemented by
        subclasses.
        Nr7   r   s    rA   rW   zMobject.init_colors        rB   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.
        Nr7   r   s    rA   rV   zMobject.generate_points  r   rB   mobjectsc                    |                      |           t          |          }t          |          t          |          k    rt          j        d           t          | j        |          | _        | 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:`Mobject`
            ``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:`Mobject`.


        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 = Mobject()
            >>> inner = Mobject()
            >>> outer = outer.add(inner)

        Duplicates are not added again::

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

        Only Mobjects can be added::

            >>> outer.add(3)
            Traceback (most recent call last):
            ...
            TypeError: Only values of type Mobject can be added as submobjects of Mobject, 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 Mobject as a submobject of itself (at index 0).

        A given mobject cannot be added as a submobject
        twice to some parent::

            >>> parent = Mobject(name="parent")
            >>> child = Mobject(name="child")
            >>> parent.add(child, child)
            [...] WARNING  ...
            parent
            >>> parent.submobjects
            [child]

        zgAttempted adding some Mobject as a child more than once, this is not possible. Repetitions are ignored.)r\   r   lenr   warningr   rQ   )rX   r   unique_mobjectss      rA   addzMobject.add  su    Z 	&&x00028<<x==C0000NA  
 't'7IIrB   indexmobjectc                h    |                      |g           | j                            ||           d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 ``Mobject.add``.

        Parameters
        ----------
        index
            The index at which
        mobject
            The mobject to be inserted.
        N)r\   rQ   insert)rX   r   r   s      rA   r   zMobject.insert(  s9     	&&y111w/////rB   c                    t           r   NotImplementedErrorrX   r   s     rA   __add__zMobject.__add__:      !!rB   c                    t           r   r   r   s     rA   __iadd__zMobject.__iadd__=  r   rB   c                    |                      |            | j        |  t          t                              |                    | j        z   | _        | 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:`Mobject`
            ``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:`Mobject`.

        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\   removelistdictfromkeysrQ   )rX   r   s     rA   add_to_backzMobject.add_to_back@  sQ    X 	&&x000Xh 7 7884;KKrB   c                V    |D ]%}|| j         v r| j                             |           &| 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:`Mobject`
            ``self``

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

        )rQ   r   )rX   r   r   s      rA   r   zMobject.remover  s>    ,   	1 	1G$*** ''000rB   c                    t           r   r   rX   others     rA   __sub__zMobject.__sub__  r   rB   c                    t           r   r   r   s     rA   __isub__zMobject.__isub__  r   rB   c                \    |                                 D ]\  }}t          | ||           | S )a#  Sets attributes.

        I.e. ``my_mobject.set(foo=1)`` applies ``my_mobject.foo = 1``.

        This is a convenience to be used along with :attr:`animate` to
        animate setting attributes.

        In addition to this method, there is a compatibility
        layer that allows ``get_*`` and ``set_*`` methods to
        get and set generic attributes. For instance::

            >>> mob = Mobject()
            >>> mob.set_foo(0)
            Mobject
            >>> mob.get_foo()
            0
            >>> mob.foo
            0

        This compatibility layer does not interfere with any
        ``get_*`` or ``set_*`` methods that are explicitly
        defined.

        .. warning::

            This compatibility layer is for backwards compatibility
            and is not guaranteed to stay around. Where applicable,
            please prefer getting/setting attributes normally or with
            the :meth:`set` method.

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

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        ::

            >>> mob = Mobject()
            >>> mob.set(foo=0)
            Mobject
            >>> mob.foo
            0
        )r   r   )rX   r?   attrvalues       rA   setzMobject.set  s:    f "<<>> 	' 	'KD%D$&&&&rB   r   types.MethodTypec                8   |                     d          r$|dd          fd}t          j        ||           S |                     d          r$|dd          fd}t          j        ||           S t          t	          |           j         d| d          )Nget_   c                \    t          j        dt          d           t          |           S )Nz[This method is not guaranteed to stay around. Please prefer getting the attribute normally.r   
stacklevel)warningswarnDeprecationWarningrt   )rX   to_gets    rA   getterz#Mobject.__getattr__.<locals>.getter  s9    6& 	    tV,,,rB   set_c                b    t          j        dt          d           t          | |           | S )NzqThis method is not guaranteed to stay around. Please prefer setting the attribute normally or with Mobject.set().r   r   )r   r   r   r   )rX   r   to_sets     rA   setterz#Mobject.__getattr__.<locals>.setter  sA    L& 	    fe,,,rB   z object has no attribute '')rs   types
MethodTypeAttributeErrorrd   rN   )rX   r   r   r   r   r   s       @@rA   __getattr__zMobject.__getattr__  s     ??6"" 	2!""XF- - - - - #FD111??6"" 	2!""XF
 
 
 
 
 #FD111 T

 3VVtVVVWWWrB   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    rA   widthzMobject.width      < ##A&&&rB   r   c                0    |                      |           d S r   )scale_to_fit_widthrX   r   s     rA   r   zMobject.width      &&&&&rB   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`

           r   r   s    rA   heightzMobject.height  r   rB   c                0    |                      |           d S r   )scale_to_fit_heightr   s     rA   r   zMobject.height>  s      '''''rB   c                ,    |                      d          S )zThe depth of the mobject.

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

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

        r   r   r   s    rA   depthzMobject.depthB  s     ##A&&&rB   c                0    |                      |           d S r   )scale_to_fit_depthr   s     rA   r   zMobject.depthR  r   rB   	list[str]c                    dgS )Nr   r7   r   s    rA   get_array_attrszMobject.get_array_attrsW  s
    zrB   funcr'   c                    |                                  D ]*}t          | | |t          | |                               +| S r   )r   r   rt   )rX   r   r   s      rA   apply_over_attr_arrayszMobject.apply_over_attr_arraysZ  sK    ((** 	; 	;DD$WT4%8%8 9 9::::rB   r)   c                x    |ddl m}  |            }|                    |            |                                S )Nr   )Camera)camera.camerar   capture_mobject	get_image)rX   camerar   s      rA   r   zMobject.get_imagea  sJ    >......VXXFt$$$!!!rB   c                V    |                      |                                           d S )N)r   )r   show)rX   r   s     rA   r   zMobject.showi  s(    f%%**,,,,,rB   c                    |                                                      t          t          j        d                                        |pt          |           dz                        dS )z\Saves an image of only this :class:`Mobject` at its position to a png
        file.
        	video_dirz.pngN)r   saver   r   get_dirjoinpathr   )rX   rF   s     rA   
save_imagezMobject.save_imagel  sc     	,,--668ID		V7STT	
 	
 	
 	
 	
rB   c                *    t          j        |           S )a-  Create and return an identical copy of the :class:`Mobject` including all
        :attr:`submobjects`.

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

        Note
        ----
        The clone is initially not visible in the Scene, even if the original was.
        )r   r   r   s    rA   r   zMobject.copyt  s     }T"""rB   Fuse_deepcopyboolc                    d | _         |rt          j        |           | _         n|                                 | _         | j         S r   )rO   r   r   )rX   r   s     rA   generate_targetzMobject.generate_target  s;     	&---DKK))++DK{rB   Tdt	recursivec                    | j         s=| j        D ]5}dt          j        |          j        v r || |           * ||            6|r!| j        D ]}|                    ||           | S )a  Apply all updaters.

        Does nothing if updating is suspended.

        Parameters
        ----------
        dt
            The parameter ``dt`` to pass to the update functions. Usually this is the
            time in seconds since the last call of ``update``.
        recursive
            Whether to recursively update all submobjects.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See Also
        --------
        :meth:`add_updater`
        :meth:`get_updaters`

        r  r  )rS   rR   inspect	signature
parametersrQ   update)rX   r  r  updaterrh   s        rA   r
  zMobject.update  s    0 & 	"= " "7,W55@@@GD"%%%%GDMMMM 	7* 7 7bI6666rB   list[TimeBasedUpdater]c                $    d | j         D             S )a\  Return all updaters using the ``dt`` parameter.

        The updaters use this parameter as the input for difference in time.

        Returns
        -------
        List[:class:`Callable`]
            The list of time based updaters.

        See Also
        --------
        :meth:`get_updaters`
        :meth:`has_time_based_updater`

        c                H    g | ]}d t          j        |          j        v | S )r  r  r  r	  .0r  s     rA   
<listcomp>z3Mobject.get_time_based_updaters.<locals>.<listcomp>  s;     
 
 
w(11<<< <<<rB   rR   r   s    rA   get_time_based_updaterszMobject.get_time_based_updaters  s%     
 
=
 
 
 	
rB   c                >    t          d | j        D                       S )a  Test if ``self`` has a time based updater.

        Returns
        -------
        :class:`bool`
            ``True`` if at least one updater uses the ``dt`` parameter, ``False``
            otherwise.

        See Also
        --------
        :meth:`get_time_based_updaters`

        c              3  L   K   | ]}d t          j        |          j        v V   dS )r  Nr  r  s     rA   	<genexpr>z1Mobject.has_time_based_updater.<locals>.<genexpr>  sF       
 
>EDG%g..99
 
 
 
 
 
rB   )anyrR   r   s    rA   has_time_based_updaterzMobject.has_time_based_updater  s4      
 
IM
 
 
 
 
 	
rB   list[Updater]c                    | j         S )zReturn all updaters.

        Returns
        -------
        List[:class:`Callable`]
            The list of updaters.

        See Also
        --------
        :meth:`add_updater`
        :meth:`get_time_based_updaters`

        r  r   s    rA   get_updaterszMobject.get_updaters  s     }rB   c                p    t          t          j        d |                                 D                        S )Nc              3  >   K   | ]}|                                 V  d S r   )r  )r  sms     rA   r  z.Mobject.get_family_updaters.<locals>.<genexpr>  s,      MMRr00MMMMMMrB   )r   itchain
get_familyr   s    rA   get_family_updaterszMobject.get_family_updaters  s0    BHMM4??;L;LMMMNOOOrB   update_functionr1   
int | Nonecall_updaterc                    || j                             |           n| j                             ||           |r5t          j        |          j        }d|v r || d           n ||            | S )u  Add an update function to this mobject.

        Update functions, or updaters in short, are functions that are applied to the
        Mobject in every frame.

        Parameters
        ----------
        update_function
            The update function to be added.
            Whenever :meth:`update` is called, this update function gets called using
            ``self`` as the first parameter.
            The updater can have a second parameter ``dt``. If it uses this parameter,
            it gets called using a second value ``dt``, usually representing the time
            in seconds since the last call of :meth:`update`.
        index
            The index at which the new updater should be added in ``self.updaters``.
            In case ``index`` is ``None`` the updater will be added at the end.
        call_updater
            Whether or not to call the updater initially. If ``True``, the updater will
            be called using ``dt=0``.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        .. manim:: NextToUpdater

            class NextToUpdater(Scene):
                def construct(self):
                    def update_label(mobject):
                        mobject.set_value(dot.get_center()[0])
                        mobject.next_to(dot)

                    dot = Dot(RIGHT*3)
                    label = DecimalNumber()
                    label.add_updater(update_label)
                    self.add(dot, label)

                    self.play(Rotating(dot, angle=TAU, about_point=ORIGIN, run_time=TAU, rate_func=linear))

        .. manim:: DtUpdater

            class DtUpdater(Scene):
                def construct(self):
                    square = Square()

                    #Let the square rotate 90° per second
                    square.add_updater(lambda mobject, dt: mobject.rotate(dt*90*DEGREES))
                    self.add(square)
                    self.wait(2)

        See also
        --------
        :meth:`get_updaters`
        :meth:`remove_updater`
        :class:`~.UpdateFromFunc`
        :class:`~.Rotating`
        :meth:`rotate`
        :attr:`~.Mobject.animate`
        Nr  r   )rR   appendr   r  r  r	  )rX   r$  r   r&  r	  s        rA   add_updaterzMobject.add_updater  s    J =M  1111M  888 	& *?;;FJz!!a((((%%%rB   c                ^    || j         v r#| j                             |           || j         v #| S )a  Remove an updater.

        If the same updater is applied multiple times, every instance gets removed.

        Parameters
        ----------
        update_function
            The update function to be removed.


        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`clear_updaters`
        :meth:`add_updater`
        :meth:`get_updaters`

        )rR   r   )rX   r$  s     rA   remove_updaterzMobject.remove_updater<  s;    . ..M  111 ..rB   c                T    g | _         |r| j        D ]}|                                 | S )aq  Remove every updater.

        Parameters
        ----------
        recursive
            Whether to recursively call ``clear_updaters`` on all submobjects.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`remove_updater`
        :meth:`add_updater`
        :meth:`get_updaters`

        )rR   rQ   clear_updatersrX   r  rh   s      rA   r-  zMobject.clear_updatersW  s?    (  	(* ( (%%''''rB   c                    |                                   |                                D ]}|                     |           | S )a  Match the updaters of the given mobject.

        Parameters
        ----------
        mobject
            The mobject whose updaters get matched.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Note
        ----
        All updaters from submobjects are removed, but only updaters of the given
        mobject are matched, not those of it's submobjects.

        See also
        --------
        :meth:`add_updater`
        :meth:`clear_updaters`

        )r-  r  r)  )rX   r   r  s      rA   match_updaterszMobject.match_updatersq  sM    0 	++-- 	& 	&GW%%%%rB   c                V    d| _         |r| j        D ]}|                    |           | S )ah  Disable updating from updaters and animations.


        Parameters
        ----------
        recursive
            Whether to recursively suspend updating on all submobjects.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`resume_updating`
        :meth:`add_updater`

        T)rS   rQ   suspend_updatingr.  s      rA   r2  zMobject.suspend_updating  sB    ( #' 	3* 3 3''	2222rB   c                    d| _         |r| j        D ]}|                    |           |                     d|           | S )af  Enable updating from updaters and animations.

        Parameters
        ----------
        recursive
            Whether to recursively enable updating on all submobjects.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`suspend_updating`
        :meth:`add_updater`

        Fr   )r  r  )rS   rQ   resume_updatingr
  r.  s      rA   r4  zMobject.resume_updating  sX    & #( 	2* 2 2&&y1111qI...rB   Callable[[Mobject], None]c                J    |                                  D ]} ||           dS )a  Apply a function to ``self`` and every submobject with points recursively.

        Parameters
        ----------
        func
            The function to apply to each mobject. ``func`` gets passed the respective
            (sub)mobject as parameter.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`family_members_with_points`

        N)family_members_with_points)rX   r   mobs      rA   apply_to_familyzMobject.apply_to_family  s8    & 2244 	 	CDIIII	 	rB   vectorsr-   c                    t          t          j        |          }|                                 D ]1}|j                            d          |_        |xj        |z  c_        2| S )aJ  Shift by the given vectors.

        Parameters
        ----------
        vectors
            Vectors to shift by. If multiple vectors are given, they are added
            together.

        Returns
        -------
        :class:`Mobject`
            ``self``

        See also
        --------
        :meth:`move_to`
        rK   )r
   opr   r7  r   astype)rX   r:  total_vectorr8  s       rA   shiftzMobject.shift  s^    $ bfg..2244 	' 	'C**733CJJJ,&JJJrB   about_point
about_edgescale_factorrA  Point3DLike | NonerB  Vector3DLike | Nonec               <    |                      fd||           | S )u  Scale the size by a factor.

        Default behavior is to scale about the center of the mobject.

        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.
        about_point
            The point about which to apply the scaling.
        about_edge
            The edge about which to apply the scaling.

        Returns
        -------
        :class:`Mobject`
            ``self``

        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 r   r7   )r   rC  s    rA   <lambda>zMobject.scale.<locals>.<lambda>$  s    <&0 rB   !apply_points_function_about_point)rX   rC  rA  rB  s    `  rA   scalezMobject.scale  s5    ` 	..0000+z	
 	
 	
 rB   angleaxisc                <    |                      ||t                    S )zERotates the :class:`~.Mobject` about the ORIGIN, which is at [0,0,0].rA  )rotateORIGIN)rX   rL  rM  s      rA   rotate_about_originzMobject.rotate_about_origin(  s    {{5$F{;;;rB   c               \    t          ||          |                     fd||           | S )aW  Rotates the :class:`~.Mobject` around a specified axis and point.

        Parameters
        ----------
        angle
            The angle of rotation in radians. Predefined constants such as ``DEGREES``
            can also be used to specify the angle in degrees.
        axis
            The rotation axis (see :class:`~.Rotating` for more).
        about_point
            The point about which the mobject rotates. If ``None``, rotation occurs around
            the center of the mobject.
        about_edge
            The edge about which to apply the scaling.

        Returns
        -------
        :class:`Mobject`
            ``self`` (for method chaining)


        .. note::
            To animate a rotation, use :class:`~.Rotating` or :class:`~.Rotate`
            instead of ``.animate.rotate(...)``.
            The ``.animate.rotate(...)`` syntax only applies a transformation
            from the initial state to the final rotated state
            (interpolation between the two states), without showing proper rotational motion
            based on the angle (from 0 to the given angle).

        Examples
        --------

        .. manim:: RotateMethodExample
            :save_last_frame:

            class RotateMethodExample(Scene):
                def construct(self):
                    circle = Circle(radius=1, color=BLUE)
                    line = Line(start=ORIGIN, end=RIGHT)
                    arrow1 = Arrow(start=ORIGIN, end=RIGHT, buff=0, color=GOLD)
                    group1 = VGroup(circle, line, arrow1)

                    group2 = group1.copy()
                    arrow2 = group2[2]
                    arrow2.rotate(angle=PI / 4, about_point=arrow2.get_start())

                    group3 = group1.copy()
                    arrow3 = group3[2]
                    arrow3.rotate(angle=120 * DEGREES, about_point=arrow3.get_start())

                    self.add(VGroup(group1, group2, group3).arrange(RIGHT, buff=1))

        See also
        --------
        :class:`~.Rotating`, :class:`~.Rotate`, :attr:`~.Mobject.animate`, :meth:`apply_points_function_about_point`

        c                8    t          j        | j                  S r   r   dotT)r   
rot_matrixs    rA   rH  z Mobject.rotate.<locals>.<lambda>o  s    26&*,77 rB   )r!   rJ  )rX   rL  rM  rA  rB  rX  s        @rA   rP  zMobject.rotate,  sD    B %UD11
..7777j	
 	
 	
 rB   c               D    |                      t          dz  |||          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   r@  )rP  TAU)rX   rM  rA  rB  s       rA   flipzMobject.flips  s,    . {{!GT{z  
 
 	
rB   factorc               F    dfd}|                      |||           | S )Nr   Point3D_Arrayr3   c                0    | d d fxx         z  cc<   | S r   r7   )r   rH   r\  s    rA   r   zMobject.stretch.<locals>.func  s&    111c6NNNf$NNNMrB   r   r^  r3   r^  rI  )rX   r\  rH   rA  rB  r   s    ``   rA   stretchzMobject.stretch  sF    	 	 	 	 	 	 	 	..t[*MMMrB   functionr%   c               X    |	|t           }dfd}|                     |||           | S )Nr   r^  r3   c                4    t          j        d|           }|S Nr   )r   apply_along_axis)r   r   rb  s     rA   multi_mapping_functionz6Mobject.apply_function.<locals>.multi_mapping_function  s    $&$7!V$L$LFMrB   r`  )rQ  rJ  )rX   rb  rA  rB  rg  s    `   rA   apply_functionzMobject.apply_function  s]     :#5 K	 	 	 	 	 	 	.."	
 	
 	

 rB   c                f    |                       ||                                                      | S r   )move_to
get_center)rX   rb  s     rA   apply_function_to_positionz"Mobject.apply_function_to_position  s-    XXdoo//00111rB   c                D    | j         D ]}|                    |           | S r   )rQ   rl  )rX   rb  rh   s      rA   &apply_function_to_submobject_positionsz.Mobject.apply_function_to_submobject_positions  s0    & 	8 	8F--h7777rB   matrixr&   c                   |	|t           }t          j        | j                  t          j        |          }|d |j        d         d |j        d         f<   |                     fd||           | S )Nr   r   c                8    t          j        | j                  S r   rU  )r   full_matrixs    rA   rH  z&Mobject.apply_matrix.<locals>.<lambda>  s    26&+-88 rB   )rQ  r   identityrH   arrayshaperJ  )rX   ro  rA  rB  rr  s       @rA   apply_matrixzMobject.apply_matrix  s     :#5 Kk$(++&!!<B%fl1o%'8a'889..8888+z	
 	
 	
 rB   Callable[[complex], complex]c               >    fd}|                      |||          S )a  Applies a complex function to a :class:`Mobject`.
        The x and y Point3Ds 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)
        c                `    | \  }}} t          ||                    }|j        |j        |gS r   )complexrealimag)pointxyz
xy_complexrb  s        rA   R3_funcz/Mobject.apply_complex_function.<locals>.R3_func  s6    GAq!!'!Q--00JOZ_a88rB   r@  )rh  )rX   rb  rA  rB  r  s    `   rA   apply_complex_functionzMobject.apply_complex_function  sC    B	9 	9 	9 	9 	9
 "" # 
 
 	
rB   c                `    |                                  D ]}|                    d            | S )Nc                ^    t          j        t          t          |                               S r   )r   rt  r   reversed)arrs    rA   rH  z(Mobject.reverse_points.<locals>.<lambda>  s    28D#<O<O3P3P rB   r7  r   )rX   r8  s     rA   reverse_pointszMobject.reverse_points  s?    2244 	R 	RC&&'P'PQQQQrB   countc                j    fd}|                                  D ]}|                    |           | S )z)This can make transition animations nicerc                .    t          d | gz            S )Nc                0    t          j        | |d          S )Nr   rM  )r   r(  )a1a2s     rA   rH  z6Mobject.repeat.<locals>.repeat_array.<locals>.<lambda>  s    2r)B)B)B rB   )r
   )rt  r  s    rA   repeat_arrayz$Mobject.repeat.<locals>.repeat_array   s    BBUGeOTTTrB   r  )rX   r  r  r8  s    `  rA   repeatzMobject.repeat  sZ    	U 	U 	U 	U 	U 2244 	5 	5C&&|4444rB   c                
   ||t           }|                     |          }t          j        |d          }|                                 D ]7}|xj        |z  c_         ||j                  |_        |xj        |z  c_        8| S )NTr   )rQ  get_critical_pointr   rt  r7  r   )rX   r   rA  rB  r8  s        rA   rJ  z)Mobject.apply_points_function_about_point  s     !#
11*==Kh{6662244 	& 	&CJJ+%JJcj))CJJJ+%JJJrB   c                N     | j         t          dz  t          t          z   fi | | S )N   )rP  rZ  RIGHTUPrX   r?   s     rA   pose_at_anglezMobject.pose_at_angle  s+    C"Hebj33F333rB   c                V    |                      |                                             | S )zMoves the center of the mobject to the center of the scene.

        Returns
        -------
        :class:`.Mobject`
            The centered mobject.
        )r?  rk  r   s    rA   centerzMobject.center$  s(     	

DOO%%%&&&rB   	directionbuffc                <   t          j        |          t          d         t          d         dfz  }|                     |          }||z
  |t          j        |          z  z
  }|t          t          j        |                    z  }|                     |           | S )zeDirection just needs to be a vector pointing towards side or
        corner in the 2d plane.
        frame_x_radiusframe_y_radiusr   )r   signr   r  rt  absr?  )rX   r  r  target_pointpoint_to_align	shift_vals         rA   align_on_borderzMobject.align_on_border/  s     wy))#$#$-
 

 00;; >1D28I;N;N4NN	BGI$6$6 7 77	

9rB   cornerc                .    |                      ||          S )a  Moves this :class:`~.Mobject` to the given corner of the screen.

        Returns
        -------
        :class:`.Mobject`
            The newly positioned mobject.

        Examples
        --------

        .. manim:: ToCornerExample
            :save_last_frame:

            class ToCornerExample(Scene):
                def construct(self):
                    c = Circle()
                    c.to_corner(UR)
                    t = Tex("To the corner!")
                    t2 = MathTex("x^3").shift(DOWN)
                    self.add(c,t,t2)
                    t.to_corner(DL, buff=0)
                    t2.to_corner(UL, buff=1.5)
        r  )rX   r  r  s      rA   	to_cornerzMobject.to_corner@  s    4 ##FD111rB   edgec                .    |                      ||          S )a  Moves this :class:`~.Mobject` to the given edge of the screen,
        without affecting its position in the other dimension.

        Returns
        -------
        :class:`.Mobject`
            The newly positioned mobject.

        Examples
        --------

        .. manim:: ToEdgeExample
            :save_last_frame:

            class ToEdgeExample(Scene):
                def construct(self):
                    tex_top = Tex("I am at the top!")
                    tex_top.to_edge(UP)
                    tex_side = Tex("I am moving to the side!")
                    c = Circle().shift(2*DOWN)
                    self.add(tex_top, tex_side, c)
                    tex_side.to_edge(LEFT)
                    c.to_edge(RIGHT, buff=0)

        r  )rX   r  r  s      rA   to_edgezMobject.to_edge\  s    8 ##D$///rB   )r   r   r   mobject_or_pointMobject | Point3DLikealigned_edgesubmobject_to_alignMobject | 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:`~.Mobject` next to another's :class:`~.Mobject` or Point3D.

        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   asarrayrc   r   r  r?  )rX   r  r  r  r  r  r  r  np_directionnp_aligned_edger8  target_alignerr  alignerr  s                  rA   next_tozMobject.next_toz  s    < z),,*\22&00 
	,"C+7!$%A!B!$)<<,. LL ,L*)GG)578GGG 33Ol4RSS

L>1D<4GG9TUUUrB   c                   t           d         t           d         g}t          t          t          t          fD ]}t          j        t          j        |                    }|                    dt                    }||         |z
  }| 
                    |          }t          j        ||          |k    r | j        |fi | | S )Nr  r  r  )r   r  DOWNLEFTr  r   argmaxr  getDEFAULT_MOBJECT_TO_EDGE_BUFFERget_edge_centerrV  r  )rX   r?   space_lengthsvectrH   r  max_valedge_centers           rA   shift_onto_screenzMobject.shift_onto_screen  s     016:J3KLdE) 	- 	-D)BF4LL))C::f&DEED#C(4/G..t44Kvk4((722T,,V,,,rB   c                Z   |                                  d         t          d         k    rdS |                                 d         t          d          k     rdS |                                 d         t          d         k    rdS |                                 d         t          d          k     S )Nr   r  Tr   r  )get_leftr   	get_right
get_bottomget_topr   s    rA   is_off_screenzMobject.is_off_screen  s    ==??1'7 8884>>A&)9":!:::4??Q&)9":::4||~~a F+;$<#<<<rB   r}  r+   c                2    |                      |||          S )NrO  ra  )rX   r\  rH   r}  s       rA   stretch_about_pointzMobject.stretch_about_point  s    ||FCU|;;;rB   lengthra  c                    |                      |          }|dk    r| S |r | j        ||z  |fi | n | j        ||z  fi | | S Nr   )r   ra  rK  )rX   r  rH   ra  r?   
old_lengths         rA   rescale_to_fitzMobject.rescale_to_fit  su     ))#..
??K 	6DL*,c<<V<<<<DJv
*55f555rB   r   c                $     | j         |dfddi|S )a  Scales the :class:`~.Mobject` to fit a width while keeping height/depth proportional.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> 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   ra  Fr  rX   r   r?   s      rA   r   zMobject.scale_to_fit_width  s&    . #t"5!EEUEfEEErB   c                $     | j         |dfddi|S )a  Stretches the :class:`~.Mobject` to fit a width, not keeping height/depth proportional.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> 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   ra  Tr  r  s      rA   stretch_to_fit_widthzMobject.stretch_to_fit_width  s&    . #t"5!DDTDVDDDrB   r   c                $     | j         |dfddi|S )a  Scales the :class:`~.Mobject` to fit a height while keeping width/depth proportional.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> sq = Square()
            >>> sq.width
            np.float64(2.0)
            >>> sq.scale_to_fit_height(5)
            Square
            >>> sq.height
            np.float64(5.0)
            >>> sq.width
            np.float64(5.0)
        r   ra  Fr  rX   r   r?   s      rA   r   zMobject.scale_to_fit_height  s&    . #t"61FFeFvFFFrB   c                $     | j         |dfddi|S )a  Stretches the :class:`~.Mobject` to fit a height, not keeping width/depth proportional.

        Returns
        -------
        :class:`Mobject`
            ``self``

        Examples
        --------
        ::

            >>> from manim import *
            >>> sq = Square()
            >>> sq.width
            np.float64(2.0)
            >>> sq.stretch_to_fit_height(5)
            Square
            >>> sq.height
            np.float64(5.0)
            >>> sq.width
            np.float64(2.0)
        r   ra  Tr  r  s      rA   stretch_to_fit_heightzMobject.stretch_to_fit_height  s&    . #t"61EEdEfEEErB   r   c                $     | j         |dfddi|S )zUScales the :class:`~.Mobject` to fit a depth while keeping width/height proportional.r   ra  Fr  rX   r   r?   s      rA   r   zMobject.scale_to_fit_depth7  s$    "t"5!EEUEfEEErB   c                $     | j         |dfddi|S )zWStretches the :class:`~.Mobject` to fit a depth, not keeping width/height proportional.r   ra  Tr  r  s      rA   stretch_to_fit_depthzMobject.stretch_to_fit_depth;  s$    "t"5!DDTDVDDDrB   c                    |                      ||          }t          j        | j                  }||z
  ||<   |                     |           | S r   )	get_coordr   r   rH   r?  )rX   r   rH   r  curr
shift_vects         rA   	set_coordzMobject.set_coord?  sJ    ~~c9--Xdh''
$,
3

:rB   r~  c                0    |                      |d|          S )zJSet x value of the center of the :class:`~.Mobject` (``int`` or ``float``)r   r  )rX   r~  r  s      rA   set_xzMobject.set_xF      ~~aI...rB   r  c                0    |                      |d|          S )zJSet y value of the center of the :class:`~.Mobject` (``int`` or ``float``)r   r  )rX   r  r  s      rA   set_yzMobject.set_yJ  r  rB   r  c                0    |                      |d|          S )zJSet z value of the center of the :class:`~.Mobject` (``int`` or ``float``)r   r  )rX   r  r  s      rA   set_zzMobject.set_zN  r  rB         ?c                f     | j         |fi | | j        D ]}|                     d|z             | S )Ng      ?)rK  rQ   )rX   r\  r?   rh   s       rA   space_out_submobjectszMobject.space_out_submobjectsR  sL    
6$$V$$$& 	' 	'FLLv&&&&rB   point_or_mobjectPoint3DLike | Mobjectc                    t          |t                    r|                    |          }n|}|                     |          }|                     ||z
  |z             | S )z9Move center of the :class:`~.Mobject` to certain Point3D.)rc   r   r  r?  )rX   r  r  r  rO   r  s         rA   rj  zMobject.move_toX  se     &00 	&%88FFFF%F00>>

F^+y8999rB   dim_to_matchc                   |                                 s|j        st          d          |r5|                     |j                   |                     |j                   n+|                     |                    |          |d           | 	                    |
                                | 
                                z
             | S )Nz,Attempting to replace mobject with no pointsFr  )get_num_pointsrQ   Warningr  r   r  r   r  r   r?  rk  )rX   r   r  ra  s       rA   replacezMobject.replaceg  s     %%'' 	J0C 	JHIII 	%%gm444&&w~6666''55     
 	

7%%''$//*;*;;<<<rB   c                    |                      |||           |                    |          }|                     ||z   |z             | S r   )r  r   rK  )rX   r   r  ra  r  r  s         rA   surroundzMobject.surroundx  sM     	WlG444((66

FTMV+,,,rB   startendc                   |                                  \  }}||z
  }t          j        |dk              rt          j        |          | _        | S t          j        |          t          j        |          z
  }t          j                            t          j        ||                    dk    r"t          t          j        ||                    nt          }|                     t          j                            |          t          j                            |          z  |           |                     t          ||          ||           |                     ||z
             | S )Nr   rO  )rA  rM  )get_start_and_endr   allrt  r   r  linalgnormcrossr    OUTrK  rP  r   r?  )rX   r  r   
curr_startcurr_end	curr_vecttarget_vectrM  s           rA   put_start_and_end_onzMobject.put_start_and_end_on  sG   #5577
Hz)	6)q.!! 	 (5//DKKjoo
5(9(99 y~~bhy+>>??1DD bhy+66777 	
 	

INN;''")..*C*CC" 	 	
 	
 	
 	!)[99" 	 	
 	
 	

 	

5:%&&&rB         ?ParsableManimColor | Noneopacityc                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:`Mobject`
            ``self``

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

        r   )BackgroundRectangle)rD   fill_opacity)%manim.mobject.geometry.shape_matchersr  background_rectangler   )rX   rD   r  r?   r  s        rA   add_background_rectanglez Mobject.add_background_rectangle  se    @ 	NMMMMM$7$7%
G%
 %
7=%
 %
! 	2333rB   c                4    | j         D ]} |j        di | | S r6   )rQ   r  )rX   r?   
submobjects      rA   'add_background_rectangle_to_submobjectsz/Mobject.add_background_rectangle_to_submobjects  s5    * 	: 	:J/J/99&9999rB   c                N    |                                  D ]} |j        di | | S r6   )r7  r  )rX   r?   r8  s      rA   6add_background_rectangle_to_family_members_with_pointsz>Mobject.add_background_rectangle_to_family_members_with_points  s>    2244 	3 	3C(C(2262222rB   r   familyc                ~    |r!| j         D ]}|                    ||           t          j        |          | _        | S )zCondition is function which takes in one arguments, (x, y, z).
        Here it just recurses to submobjects, but in subclasses this
        should be further implemented based on the the inner workings
        of color
        r  )rQ   	set_colorr   rT   rD   )rX   rD   r  rh   s       rA   r  zMobject.set_color  sQ      	7* 7 7  v 6666%e,,
rB   colorsc                     | j         |  | S )z
        Parameters
        ----------
        colors
            The colors to use for the gradient. Use like `set_color_by_gradient(RED, BLUE, GREEN)`.

        self.color = ManimColor.parse(color)
        return self
        )!set_submobject_colors_by_gradient)rX   r  s     rA   set_color_by_gradientzMobject.set_color_by_gradient  s     	/.77rB   r   r  radiusinner_colorouter_colorc                6    |                      ||||           | S r   )(set_submobject_colors_by_radial_gradient)rX   r  r#  r$  r%  s        rA   set_colors_by_radial_gradientz%Mobject.set_colors_by_radial_gradient  s/     	55		
 	
 	
 rB   Iterable[ParsableManimColor]c                D   t          |          dk    rt          d          t          |          dk    r
 | j        | S |                                 }t	          |t          |                    }t          ||d          D ]\  }}|                    |d           | S )Nr   zNeed at least one colorr   TstrictFr  )r   rf   r  r7  r   zip)rX   r  mobs
new_colorsr8  rD   s         rA   r!  z)Mobject.set_submobject_colors_by_gradient  s    v;;!6777[[A!4>6**..00#FCII66
dJt<<< 	/ 	/JCMM%M....rB   c                >   ||                                  }|                                 D ]q}t          j                            |                                 |z
            |z  }t          |d          }t          |||          }|                    |d           r| S )Nr   Fr  )rk  r7  r   r  r  minr   r  )rX   r  r#  r$  r%  r8  t	mob_colors           rA   r'  z0Mobject.set_submobject_colors_by_radial_gradient  s     >__&&F2244 	3 	3C	s~~//&899FBAAq		A)+{AFFIMM)EM2222rB   c                :    |                      | j                   | S r   )r  rD   r   s    rA   to_original_colorzMobject.to_original_color  s    tz"""rB   alphac                    |                                  dk    r:t          |                                 ||          }|                     |d           |r | j        D ]}|                    ||           | S )Nr   Fr  )r  r   	get_colorr  rQ   fade_to)rX   rD   r6  r  	new_colorrh   s         rA   r9  zMobject.fade_to"  s       1$$)$..*:*:E5IIINN9UN333 	-* - -ue,,,,rB         ?darknessc                J    |r | j         D ]}|                    ||           | S r   )rQ   fade)rX   r<  r  rh   s       rA   r>  zMobject.fade-  s8     	.* . .Hf----rB   r   c                    | j         S )zReturns the color of the :class:`~.Mobject`

        Examples
        --------
        ::

            >>> from manim import Square, RED
            >>> Square(color=RED).get_color() == RED
            True

        )rD   r   s    rA   r8  zMobject.get_color3  s     zrB   c                f    t          | d          rd| _        |                                 | _        | S )z`Save the current state (position, color & size). Can be restored with :meth:`~.Mobject.restore`.saved_stateN)ru   rA  r   r   s    rA   
save_statezMobject.save_stateC  s1    4'' 	$#D99;;rB   c                    t          | d          r| j        t          d          |                     | j                   | S )zORestores the state that was previously saved with :meth:`~.Mobject.save_state`.rA  Nz&Trying to restore without having saved)ru   rB  	ExceptionbecomerA  r   s    rA   restorezMobject.restoreL  sE    t]++ 	Ft/FDEEED$%%%rB   reduce_funcr   c                V   |dk    sJ |dk    sJ t          | j                  dk    rt          | j                  dk    rdS t          | j                  dk    rd}n || j        dd|f                   }| j        D ])}|                    ||          }||n |||g          }*|S )zUFind the min or max value from a dimension across all points in this and submobjects.r   r   N)r   rQ   r   reduce_across_dimension)rX   rG  rH   rvmobjr   s         rA   rI  zMobject.reduce_across_dimensionS  s    axxxxaxxxxt  A%%#dk*:*:a*?*?1 t{q  BB T[C011B $ 	C 	CD00cBBE*++ubk*B*BBB	rB   
list[Self]c                $    d | j         D             S )Nc                r    g | ]4}t          |j                  d k    st          |j                  d k    2|5S r   )r   rQ   r   )r  rh   s     rA   r  z0Mobject.nonempty_submobjects.<locals>.<listcomp>j  sL     
 
 
6%&&!++s6=/A/AQ/F/F /F/F/FrB   )rQ   r   s    rA   nonempty_submobjectszMobject.nonempty_submobjectsi  s&    
 
*
 
 
 	
rB   
array_attr
np.ndarrayc                    t          | |          }| j        D ],}t          j        ||                    |          d          }-|S )zReturn all of a given attribute from this mobject and all submobjects.

        May contain duplicates; the order is in a depth-first (pre-order)
        traversal of the submobjects.
        r   r  )rt   rQ   r   r(  get_merged_array)rX   rQ  r   rh   s       rA   rT  zMobject.get_merged_arrayp  sS     z**& 	T 	TFYvv'>'>z'J'JQRSSSFFrB   r^  c                ,    |                      d          S )zReturn all points from this mobject and all submobjects.

        May contain duplicates; the order is in a depth-first (pre-order)
        traversal of the submobjects.
        r   )rT  r   s    rA   get_all_pointszMobject.get_all_points{  s     $$X...rB   c                *    |                                  S r   )rV  r   s    rA   get_points_defining_boundaryz$Mobject.get_points_defining_boundary  s    ""$$$rB   c                *    t          | j                  S r   r   r   r   s    rA   r  zMobject.get_num_points  s    4;rB   r   Point3DLike_Array | Nonekeyc                .   ||                                  nt          j        |          }|d d |f         }|dk     rt          j        |          S |dk    r,t          j        |          t          j        |          z   dz  S t          j        |          S )Nr   r   )rX  r   r  r1  max)rX   r   rH   r\  	np_pointsvaluess         rA   get_extremum_along_dimzMobject.get_extremum_along_dim  s    
 ~ --///F## 	
 111c6"776&>>!AXXF6NNRVF^^3q886&>>!rB   r*   c                    t          j        | j                  }|                                 }t	          |          dk    r|S t          | j                  D ]#}|                     ||||                   ||<   $|S )a  Picture a box bounding the :class:`~.Mobject`.  Such a box has
        9 'critical points': 4 corners, 4 edge center, the
        center. This returns one of them, along the given direction.

        ::

            sample = Arc(start_angle=PI / 7, angle=PI / 5)

            # These are all equivalent
            max_y_1 = sample.get_top()[1]
            max_y_2 = sample.get_critical_point(UP)[1]
            max_y_3 = sample.get_extremum_along_dim(dim=1, key=1)

        r   rH   r\  )r   r   rH   rX  r   rangera  )rX   r  r   
all_pointsrH   s        rA   r  zMobject.get_critical_point  s     $(##6688
z??aM?? 	 	C55cN 6  F3KK
 rB   c                ,    |                      |          S )z(Get edge Point3Ds for certain direction.r  rX   r  s     rA   r  zMobject.get_edge_center      &&y111rB   c                ,    |                      |          S )z*Get corner Point3Ds for certain direction.rg  rh  s     rA   
get_cornerzMobject.get_corner  ri  rB   c                Z    |                      t          j        | j                            S )zGet center Point3Ds)r  r   r   rH   r   s    rA   rk  zMobject.get_center  s"    &&rx'9'9:::rB   c                f    t          j        t           j        d|                                           S r  )r   rf  meanrV  r   s    rA   get_center_of_masszMobject.get_center_of_mass  s%    "27At/B/B/D/DEEErB   c                    |                                  }t          j        t          j        ||                    }||         S r   )rX  r   r  rV  )rX   r  re  r   s       rA   get_boundary_pointzMobject.get_boundary_point  s9    6688
	"&Y7788%  rB   c                ,    |                      d          S )ad  Get Point3Ds of the middle of the path that forms the  :class:`~.Mobject`.

        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()

        r;  )point_from_proportionr   s    rA   get_midpointzMobject.get_midpoint  s    * ))#...rB   c                6    |                      t                    S )z9Get top Point3Ds of a box bounding the :class:`~.Mobject`)r  r  r   s    rA   r  zMobject.get_top      ##B'''rB   c                6    |                      t                    S )z<Get bottom Point3Ds of a box bounding the :class:`~.Mobject`)r  r  r   s    rA   r  zMobject.get_bottom      ##D)))rB   c                6    |                      t                    S )z;Get right Point3Ds of a box bounding the :class:`~.Mobject`)r  r  r   s    rA   r  zMobject.get_right  s    ##E***rB   c                6    |                      t                    S )z:Get left Point3Ds of a box bounding the :class:`~.Mobject`)r  r  r   s    rA   r  zMobject.get_left  rx  rB   c                6    |                      t                    S )z>Get zenith Point3Ds of a box bounding a 3D :class:`~.Mobject`.)r  r  r   s    rA   
get_zenithzMobject.get_zenith  s    ##C(((rB   c                6    |                      t                    S )zSGet nadir (opposite the zenith) Point3Ds of a box bounding a 3D :class:`~.Mobject`.)r  INr   s    rA   	get_nadirzMobject.get_nadir  rv  rB   c                p    |                      t          |          |                      t          |          z
  S )zCMeasure the length of an :class:`~.Mobject` in a certain direction.)rI  r^  r1  )rX   rH   s     rA   r   zMobject.length_over_dim  s:    ++
 
 ((c223 	3rB   c                <    |                      |||                   S )z6Meant to generalize ``get_x``, ``get_y`` and ``get_z``rc  )ra  )rX   rH   r  s      rA   r  zMobject.get_coord	  s    **s	#*GGGrB   c                .    |                      d|          S )zFReturns x Point3D of the center of the :class:`~.Mobject` as ``float``r   r  rh  s     rA   get_xzMobject.get_x	      ~~a+++rB   c                .    |                      d|          S )zFReturns y Point3D of the center of the :class:`~.Mobject` as ``float``r   r  rh  s     rA   get_yzMobject.get_y
	  r  rB   c                .    |                      d|          S )zFReturns z Point3D of the center of the :class:`~.Mobject` as ``float``r   r  rh  s     rA   get_zzMobject.get_z	  r  rB   c                h    |                                   t          j        | j        d                   S )zQReturns the point, where the stroke that surrounds the :class:`~.Mobject` starts.r   throw_error_if_no_pointsr   rt  r   r   s    rA   	get_startzMobject.get_start	  s*    %%'''xA'''rB   c                h    |                                   t          j        | j        d                   S )zOReturns the point, where the stroke that surrounds the :class:`~.Mobject` ends.r  r   s    rA   get_endzMobject.get_end	  s*    %%'''xB(((rB   tuple[Point3D, Point3D]c                R    |                                  |                                 fS )z=Returns starting and ending point of a stroke as a ``tuple``.)r  r  r   s    rA   r  zMobject.get_start_and_end	  s    ~~//rB   c                     t          d          Nz!Please override in a child class.r   )rX   r6  s     rA   rs  zMobject.point_from_proportion 	      !"EFFFrB   c                     t          d          r  r   )rX   r}  s     rA   proportion_from_pointzMobject.proportion_from_point#	  r  rB   n_piecesr   c           	                                            g _        t          j        dd|dz             }t	           fdt          |d d         |dd          d          D              S )Nr   r   c              3  p   K   | ]0\  }}                                                     ||          V  1d S r   )r   pointwise_become_partial)r  r  r  rX   templates      rA   r  z%Mobject.get_pieces.<locals>.<genexpr>+	  sU        B 88r2FF     rB   r  Tr+  )r   rQ   r   linspacer   r-  )rX   r  alphasr  s   `  @rA   
get_pieceszMobject.get_pieces&	  s    99;;!Q8a<00    !&"+vabbz$GGG  
 	
rB   c                L    t          | d|           }|                                S )Nz_index_group)rt   rk  )rX   r  s     rA   get_z_index_reference_pointz#Mobject.get_z_index_reference_point1	  s%    ot<<'')))rB   c                2    t          | j                  dk    S )z,Check if :class:`~.Mobject` contains points.r   rZ  r   s    rA   
has_pointszMobject.has_points6	  s    4;!##rB   c                ,    |                                   S )z7Check if :class:`~.Mobject` *does not* contains points.)r  r   s    rA   has_no_pointszMobject.has_no_points:	  s    ??$$$$rB   c                P    |                      |                                          S )z=Match the color with the color of another :class:`~.Mobject`.)r  r8  r   s     rA   match_colorzMobject.match_color@	  s     ~~g//11222rB   c                F     | j         |                    |          |fi |S )zOMatch the specified dimension with the dimension of another :class:`~.Mobject`.)r  r   )rX   r   rH   r?   s       rA   match_dim_sizezMobject.match_dim_sizeD	  s-    "t"7#:#:3#?#?OOOOOrB   c                      | j         |dfi |S )z=Match the width with the width of another :class:`~.Mobject`.r   r  rX   r   r?   s      rA   match_widthzMobject.match_widthH	      "t"7A88888rB   c                      | j         |dfi |S )z?Match the height with the height of another :class:`~.Mobject`.r   r  r  s      rA   match_heightzMobject.match_heightL	  r  rB   c                      | j         |dfi |S )z=Match the depth with the depth of another :class:`~.Mobject`.r   r  r  s      rA   match_depthzMobject.match_depthP	  r  rB   c                Z    |                      |                    ||          ||          S )zCMatch the Point3Ds with the Point3Ds of another :class:`~.Mobject`.)rH   r  )r  r  )rX   r   rH   r  s       rA   match_coordzMobject.match_coordT	  s8     ~~c9--  
 
 	
rB   c                0    |                      |d|          S )z=Match x coord. to the x coord. of another :class:`~.Mobject`.r   r  rX   r   r  s      rA   match_xzMobject.match_x^	      I666rB   c                0    |                      |d|          S )z=Match y coord. to the x coord. of another :class:`~.Mobject`.r   r  r  s      rA   match_yzMobject.match_yb	  r  rB   c                0    |                      |d|          S )z=Match z coord. to the x coord. of another :class:`~.Mobject`.r   r  r  s      rA   match_zzMobject.match_zf	  r  rB   c                    t          |t                    r|                    |          }n|}t          | j                  D ]+}||         dk    r|                     ||         ||           ,| S )zAligns mobject to another :class:`~.Mobject` in a certain direction.

        Examples:
        mob1.align_to(mob2, UP) moves mob1 vertically so that its
        top edge lines ups with mob2's top edge.
        r   )rc   r   r  rd  rH   r  )rX   r  r  r}  rH   s        rA   align_tozMobject.align_toj	  sw     &00 	%$77	BBEE$E?? 	; 	;C~""uSz3	:::rB   c                    |                                  }t          |t                    r,|                                 } ||                    |           S |                    |          S r   )splitrc   sliceget_group_class__getitem__)rX   r   	self_list
GroupClasss       rA   r  zMobject.__getitem__	  sa    JJLL	eU## 	=--//J:y44U;;<<$$U+++rB   c                D    t          |                                           S r   )iterr  r   s    rA   __iter__zMobject.__iter__	  s    DJJLL!!!rB   c                D    t          |                                           S r   )r   r  r   s    rA   __len__zMobject.__len__	  s    4::<<   rB   type[Group]c                    t           S r   )r   r   s    rA   r  zMobject.get_group_class	  s    rB   c                     t           S )z+Return the base class of this mobject type.)r   r7   rB   rA   get_mobject_type_classzMobject.get_mobject_type_class	  s	     rB   c                P    t          | j                  dk    r| gng }|| j        z   S r  )r   r   rQ   )rX   r   s     rA   r  zMobject.split	  s/    t{++a//$R(((rB   recursec                    d | j         D             }| gt          t          j        |           z   }t	          |          S )a  Lists all mobjects in the hierarchy (family) of the given mobject,
        including the mobject itself and all its submobjects recursively.

        Parameters
        ----------
        recurse
            Just for consistency with get_family method in OpenGLMobject.

        Returns
        -------
        list[Mobject]
            A list of mobjects in the family of the given mobject.

        Examples
        --------
        ::

            >>> from manim import Square, Rectangle, VGroup, Group, Mobject, VMobject
            >>> s, r, m, v = Square(), Rectangle(), Mobject(), VMobject()
            >>> vg = VGroup(s, r)
            >>> gr = Group(vg, m, v)
            >>> gr.get_family()
            [Group, VGroup(Square, Rectangle), Square, Rectangle, Mobject, VMobject]

        See also
        --------
        :meth:`~.Mobject.family_members_with_points`, :meth:`~.Mobject.align_data`

        c                6    g | ]}|                                 S r7   r"  )r  r~  s     rA   r  z&Mobject.get_family.<locals>.<listcomp>	  s     AAA1AAArB   )rQ   r   r   r!  r   )rX   r  sub_familiesall_mobjectss       rA   r"  zMobject.get_family	  sD    < BA0@AAAvRX|%< = =='555rB   c                >    d |                                  D             S )a  Filters the list of family members (generated by :meth:`.get_family`) to include only mobjects with points.

        Returns
        -------
        list[Mobject]
            A list of mobjects that have points.

        Examples
        --------
        ::

            >>> from manim import Square, Rectangle, VGroup, Group, Mobject, VMobject
            >>> s, r, m, v = Square(), Rectangle(), Mobject(), VMobject()
            >>> vg = VGroup(s, r)
            >>> gr = Group(vg, m, v)
            >>> gr.family_members_with_points()
            [Square, Rectangle]

        See also
        --------
        :meth:`~.Mobject.get_family`

        c                B    g | ]}|                                 d k    |S rO  )r  )r  ms     rA   r  z6Mobject.family_members_with_points.<locals>.<listcomp>	  s.    GGGa0@0@0B0BQ0F0F0F0F0FrB   r  r   s    rA   r7  z"Mobject.family_members_with_points	  s#    0 HG4??,,GGGGrB   c                    t          | j        dd         | j        dd         d          D ]\  }} |j        |||fi | |r|                                  | S )a  Sorts :class:`~.Mobject` 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 = VGroup(s1, s2, s3, s4).set_x(0).arrange(buff=1.0)
                    self.add(x)
        Nr  r   Tr+  )r-  rQ   r  r  )rX   r  r  r  r?   m1m2s          rA   arrangezMobject.arrange	  sy    0 $*3B3/1A!""1EdSSS 	6 	6FBBJr9d55f5555 	KKMMMrB   rdrowscolsfloat | tuple[float, float]cell_alignmentrow_alignmentscol_alignmentsrow_heightsIterable[float | None] | None
col_widths
flow_orderc
           	       	  ddl m} | j                                         |                                 }d } |||           |||          53t          j        t          j        t                                         $t          j        t                     z            $t          j        t                     z            z  t                     k     rt          d          t          |t                    r|d         }|d         }n|x}}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rt          d          |	         	d } ||          } ||          }t#                      }                     |gz  t                     z
  z             	 fdt'                    D             fdt'                    D             }fdt'                    D             }d } |||d          } |||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 )a}  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
        -------
        :class:`Mobject`
            ``self``

        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.

        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.

        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):
                    boxes = VGroup(*[
                        Rectangle(WHITE, 0.5, 0.5).add(Text(str(i+1)).scale(0.5))
                        for i in range(24)
                    ])
                    self.add(boxes)

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


        r   )Linec                R    | | S |t          |          S |t          |          S d S r   )r   )num
alignmentssizess      rA   	init_sizez*Mobject.arrange_in_grid.<locals>.init_size]
  s8    
%:& 5zz! ! rB   Nz0Too few rows and columns to fit all submobjetcs.r   c                    | 	|z  g|z  S t          |           |k    rt          | d          t          |           } t          |          D ]}|| |                  | |<   | S )Nz#_alignments has a mismatching size.)r   rf   r   rd  )r  r  mappingrF   dir_rg   r  s         rA   init_alignmentsz0Mobject.arrange_in_grid.<locals>.init_alignments~
  s    !&-.44:#%% D!M!M!MNNNj))J3ZZ 7 7 '
1 6
1rB   )ucdrow)lr  rcolc                     | z
  dz
  |z  z   S re  r7   r  r  r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    q1D8 rB   c                ,    | z
  dz
  |z
  dz
  z  z   S re  r7   r  r  r  r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s!    q1A0EE rB   c                    | |z  z   S r   r7   r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    q1t8| rB   c                     | |z
  dz
  z  z   S re  r7   r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    qD1HqLD#88 rB   c                     | z
  dz
  z  |z   S re  r7   r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    q14q8 rB   c                ,    | z
  dz
  z  |z
  dz
  z   S re  r7   r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s!    q14q1E rB   c                    | z  |z   S r   r7   r  r  r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    q4x!| rB   c                     | z  |z
  dz
  z   S re  r7   r  s     rA   rH  z)Mobject.arrange_in_grid.<locals>.<lambda>
  s    q4x4!8a<8 rB   )drdlurulr  ldruluz^flow_order must be one of the following values: "dr", "rd", "ld" "dl", "ru", "ur", "lu", "ul".c                T    | %t          |           } |                                  | S d S r   )r   reverse)
maybe_lists    rA   r  z(Mobject.arrange_in_grid.<locals>.reverse
  s5    %!*--
""$$$!! &%rB   c                L    g | ]fd t                    D              S )c                4    g | ]} |                   S r7   r7   )r  r  r  r.  r  s     rA   r  z6Mobject.arrange_in_grid.<locals>.<listcomp>.<listcomp>
  s*    ===AjjA&&'===rB   )rd  )r  r  r  r  r.  s    @rA   r  z+Mobject.arrange_in_grid.<locals>.<listcomp>
  s;    SSS!======t===SSSrB   c                d    g | ]+t          fd t                    D                       ,S )c              3  >   K   | ]}         |         j         V  d S r   )r   )r  r  gridr  s     rA   r  z5Mobject.arrange_in_grid.<locals>.<listcomp>.<genexpr>
  s.      77aQ
!777777rB   r^  rd  )r  r  r  r  s    @rA   r  z+Mobject.arrange_in_grid.<locals>.<listcomp>
  sM     
 
 
<=C777775;;77777
 
 
rB   c                d    g | ]+t          fd t                    D                       ,S )c              3  >   K   | ]}|                  j         V  d S r   )r   )r  r  r  r  s     rA   r  z5Mobject.arrange_in_grid.<locals>.<listcomp>.<genexpr>
  s.      66QQ
 666666rB   r  )r  r  r  r  s    @rA   r  z+Mobject.arrange_in_grid.<locals>.<listcomp>
  sM     
 
 
;<C66666%++66666
 
 
rB   c                      d g|z   t                     |k    rt          | d           fdt          |          D             S )Nz has a mismatching size.c                @    g | ]}|         |         n|         S r   r7   )r  rg   measuresr  s     rA   r  z?Mobject.arrange_in_grid.<locals>.init_sizes.<locals>.<listcomp>
  s;       FGE!H0ahqk  rB   )r   rf   rd  )r  r  r  rF   s   ` ` rA   
init_sizesz+Mobject.arrange_in_grid.<locals>.init_sizes
  ss    }5zzS   D!B!B!BCCC    KPQT::   rB   r  r  )r   r   )manim.mobject.geometry.liner  rQ   r   rk  mathceilsqrtr   rf   rc   tupler  rQ  r  r  r  r   extendrd  rj  )!rX   r  r  r  r  r  r  r  r  r  r?   r  	start_posr  buff_xbuff_yr  mapperr  placeholdermeasured_heigthsmeasured_widthsr  heightswidthsr~  r  r  r  	alignmentliner  r.  s!    `` `    `                     @@rA   arrange_in_gridzMobject.arrange_in_grid	  s}   F 	544444$$&&OO%%		" 	" 	" y~z::y~{;; <DL9TYs4yy1122D
 <9SYY-..D<9SYY-..D$;T""OPPP dE"" 	#!WF!WFF""FV		 		 		 		 		 )6--
 
 )V%00
 
 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	
 	
 V##p   J'
	" 	" 	" !00gk**ii
 	[MTD[3t99%<=>>>SSSSSSuT{{SSS
 
 
 
 
AFt
 
 

 
 
 
 
@Ed
 
 

	 	 	 *[$0@-PPJo|LL1t 	% 	%AA4[[ ( (71:[00 .q 1N14E EI4E	AF*VAY%/1wqz>R2GG D GAJ&&tY777VAY''f$$AAYrB   c                    | d         S r  r7   )ps    rA   rH  zMobject.<lambda>
  s
    ad rB   point_to_num_funcCallable[[Point3DLike], float]submob_funcCallable[[Mobject], Any] | Nonec                N    |dfd}| j                             |           | S )	zOSorts the list of :attr:`submobjects` by a function defined by ``submob_func``.Nr  r   r3   rK   c                >     |                                            S r   )rk  )r  r1  s    rA   r3  z!Mobject.sort.<locals>.submob_func
  s    ((888rB   )r\  )r  r   r3   rK   )rQ   sort)rX   r1  r3  s    ` rA   r7  zMobject.sort
  sJ     9 9 9 9 9 9 	+...rB   c                |    |r | j         D ]}|                    d           t          j        | j                    dS )z)Shuffles the list of :attr:`submobjects`.Tr  N)rQ   shufflerandomr.  s      rA   r9  zMobject.shuffle
  sL     	/* / /....t'(((((rB   c                |    |r | j         D ]}|                    d           | j                                          d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))
        Tr  N)rQ   invertr  r.  s      rA   r<  zMobject.invert
  sP    *  	.* . .----  """""rB   c                     | j         |i |S )ag  Arrange the position of :attr:`submobjects` with a small buffer.

        Examples
        --------

        .. manim:: ArrangeSumobjectsExample
            :save_last_frame:

            class ArrangeSumobjectsExample(Scene):
                def construct(self):
                    s= VGroup(*[Dot().shift(i*0.1*RIGHT*np.random.uniform(-1,1)+UP*np.random.uniform(-1,1)) for i in range(0,15)])
                    s.shift(UP).set_color(BLUE)
                    s2= s.copy().set_color(RED)
                    s2.arrange_submobjects()
                    s2.shift(DOWN)
                    self.add(s,s2)

        )r  rX   argsr?   s      rA   arrange_submobjectszMobject.arrange_submobjects  s    & t|T,V,,,rB   c                     | j         |i |S )zSort the :attr:`submobjects`)r7  r>  s      rA   sort_submobjectszMobject.sort_submobjects*  s    ty$)&)))rB   c                     | j         |i |S )a  Shuffles the order of :attr:`submobjects`

        Examples
        --------

        .. manim:: ShuffleSubmobjectsExample

            class ShuffleSubmobjectsExample(Scene):
                def construct(self):
                    s= VGroup(*[Dot().shift(i*0.1*RIGHT) for i in range(-20,20)])
                    s2= s.copy()
                    s2.shuffle_submobjects()
                    s2.shift(DOWN)
                    self.play(Write(s), Write(s2))
        )r9  r>  s      rA   shuffle_submobjectszMobject.shuffle_submobjects.  s      t|T,V,,,rB   skip_point_alignmentc                    |                      |           |                     |           |s|                     |           t          | j        |j        d          D ]\  }}|                    |           dS )a  Aligns the family structure and data of this mobject with another mobject.

        Afterwards, the two mobjects will have the same number of submobjects
        (see :meth:`.align_submobjects`) and the same parent structure (see
        :meth:`.null_point_align`). If ``skip_point_alignment`` is ``False``,
        they will also have the same number of points (see :meth:`.align_points`).

        Parameters
        ----------
        mobject
            The other mobject this mobject should be aligned to.
        skip_point_alignment
            Controls whether or not the computationally expensive
            point alignment is skipped (default: ``False``).


        .. note::

            This method is primarily used internally by :meth:`.become` and the
            :class:`~.Transform` animation to ensure that mobjects are structurally
            compatible before transformation.

        Examples
        --------
        ::

            >>> from manim import Rectangle, Line, ORIGIN, RIGHT
            >>> rect = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
            >>> line = Line(start=ORIGIN,end=RIGHT)
            >>> line.align_data(rect)
            >>> len(line.get_family()) == len(rect.get_family())
            True
            >>> line.get_num_points() == rect.get_num_points()
            True

        See also
        --------
        :class:`~.Transform`, :meth:`~.Mobject.become`, :meth:`~.VMobject.align_points`, :meth:`~.Mobject.get_family`

        Tr+  N)null_point_alignalign_submobjectsalign_pointsr-  rQ   
align_data)rX   r   rE  r  r  s        rA   rJ  zMobject.align_dataA  s    R 	g&&&w'''# 	'g&&&$*G,?MMM 	 	FBMM"	 	rB   c                >    d| j         j         }t          |          )z}The simplest :class:`~.Mobject` to be transformed to or from self.
        Should by a point of the appropriate type
        z&get_point_mobject not implemented for )r@   rN   r   )rX   r  msgs      rA   get_point_mobjectzMobject.get_point_mobjectr  s%     Qt~7NPP!#&&&rB   c                    |                                  }|                                 }||k     r|                     |           n||k     r|                    |            | S r   )r  align_points_with_larger)rX   r   count1count2s       rA   rI  zMobject.align_pointsy  sf    $$&&''))F??))'2222f__,,T222rB   larger_mobjectc                     t          d          r  r   )rX   rR  s     rA   rO  z Mobject.align_points_with_larger  r  rB   c                    | }|}t          |j                  }t          |j                  }|                    t          d||z
                       |                    t          d||z
                       | S r  )r   rQ   add_n_more_submobjectsr^  )rX   r   mob1mob2n1n2s         rA   rH  zMobject.align_submobjects  sq    !""!""##C27OO444##C27OO444rB   c                    | |f|| ffD ]A\  }}|                                 r(|                                r|                                 B| S )a  If a :class:`~.Mobject` with points is being aligned to
        one without, treat both as groups, and push
        the one with points into its own submobjects
        list.

        Returns
        -------
        :class:`Mobject`
            ``self``
        )r  r  push_self_into_submobjects)rX   r   r  r  s       rA   rG  zMobject.null_point_align  s_     Wo6 	0 	0FB!! 0bmmoo 0--///rB   c                    |                                  }g |_        |                                  |                     |           | S r   )r   rQ   rU   r   )rX   r   s     rA   r[  z"Mobject.push_self_into_submobjects  s=    yy{{rB   nSelf | Nonec                    |dk    rd S t           j                  }|dk    r" fdt          |          D              _        d S ||z   }t          j        |          |z  |z  fdt          |          D             }g }t           j        |d          D ]I\  }|                               |                    fdt          d|          D                        J| _         S )Nr   c                8    g | ]}                                 S r7   )rM  )r  r   rX   s     rA   r  z2Mobject.add_n_more_submobjects.<locals>.<listcomp>  s%    KKKQ 6 6 8 8KKKrB   c                6    g | ]}t          |k              S r7   )sum)r  rg   repeat_indicess     rA   r  z2Mobject.add_n_more_submobjects.<locals>.<listcomp>  s&    GGGa^q011GGGrB   Tr+  c              3  f   K   | ]+}                                                     d           V  ,dS )r   N)r   r>  )r  _rh   s     rA   r  z1Mobject.add_n_more_submobjects.<locals>.<genexpr>  s9      KKv{{}}11!44KKKKKKrB   r   )r   rQ   rd  r   aranger-  r(  r"  )	rX   r]  r  rO   split_factorsnew_submobssfrc  rh   s	   `      @@rA   rU  zMobject.add_n_more_submobjects  s   6644#$$199KKKK%((KKKD4 )F++d2v=GGGG5;;GGGd.dKKK 	L 	LJFBv&&&KKKKeArllKKKKKKK&rB   rh   c                *    |                                 S r   r  )rX   rh   s     rA   repeat_submobjectzMobject.repeat_submobject  s    {{}}rB   mobject1mobject2	path_funcr(   c                l     ||j         |j         |          | _         |                     |||           | S )a	  Turns this :class:`~.Mobject` into an interpolation between ``mobject1``
        and ``mobject2``.

        The interpolation is applied to the points and color of the mobject.

        Parameters
        ----------
        mobject1
            The starting Mobject.
        mobject2
            The target Mobject.
        alpha
            Interpolation factor between 0 (at ``mobject1``) and 1 (at ``mobject2``).
        path_func
            The function defining the interpolation path. Defaults to a straight path.

        Returns
        -------
        :class:`Mobject`
            ``self``


        .. note::

            - Both mobjects must have the same number of points. If not, this will raise an error.
              Use :meth:`~.VMobject.align_points` to match point counts beforehand if needed.
            - This method is used internally by the :class:`~.Transform` animation
              to interpolate between two mobjects during a transformation.

        Examples
        --------

        .. manim:: InterpolateExample
            :save_last_frame:

            class InterpolateExample(Scene):
                def construct(self):
                    # No need for point alignment:
                    dotL = Dot(color=DARK_GREY).to_edge(LEFT)
                    dotR = Dot(color=YELLOW).scale(10).to_edge(RIGHT)
                    dotMid1 = VMobject().interpolate(dotL, dotR, alpha=0.1)
                    dotMid2 = VMobject().interpolate(dotL, dotR, alpha=0.25)
                    dotMid3 = VMobject().interpolate(dotL, dotR, alpha=0.5)
                    dotMid4 = VMobject().interpolate(dotL, dotR, alpha=0.75)
                    dots = VGroup(dotL, dotR, dotMid1, dotMid2, dotMid3, dotMid4)

                    # Needs point alignment:
                    line = Line(ORIGIN, UP).to_edge(LEFT)
                    sq = Square(color=RED, fill_opacity=1, stroke_color=BLUE).to_edge(RIGHT)
                    line.align_points(sq)
                    mid1 = VMobject().interpolate(line, sq, alpha=0.1)
                    mid2 = VMobject().interpolate(line, sq, alpha=0.25)
                    mid3 = VMobject().interpolate(line, sq, alpha=0.5)
                    mid4 = VMobject().interpolate(line, sq, alpha=0.75)
                    linesquares = VGroup(line, sq, mid1, mid2, mid3, mid4)

                    self.add(VGroup(dots, linesquares).arrange(DOWN, buff=1))
        See also
        --------
        :class:`~.Transform`, :meth:`~.VMobject.align_points`, :meth:`~.VMobject.interpolate_color`

        )r   r   )rX   rl  rm  r6  rn  s        rA   interpolatezMobject.interpolate  s;    J  i%HHx5999rB   c                     t          d          r  r   )rX   rl  rm  r6  s       rA   r   zMobject.interpolate_color  r  rB   r  r  r  match_centerc                   |s|s|s|s|r|                                 }|rO|                    | j                   |                    | j                   |                    | j                   nE|r|                    |            |r|                    |            |r|	                    |            |r'|
                    |                                            |                     |d           t          |                                 |                                d          D ]:\  }}t          j        |j                  |_        |                    ||d           ;| S )a"  Edit points, colors and submobjects to be identical
        to another :class:`~.Mobject`

        .. note::

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

        Parameters
        ----------
        match_height
            Whether or not to preserve the height of the original
            :class:`~.Mobject`.
        match_width
            Whether or not to preserve the width of the original
            :class:`~.Mobject`.
        match_depth
            Whether or not to preserve the depth of the original
            :class:`~.Mobject`.
        match_center
            Whether or not to preserve the center of the original
            :class:`~.Mobject`.
        stretch
            Whether or not to stretch the target mobject to match the
            the proportions of the original :class:`~.Mobject`.

        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)


        The following examples illustrate how mobject measurements
        change when using the ``match_...`` and ``stretch`` arguments.
        We start with a rectangle that is 2 units high and 4 units wide,
        which we want to turn into a circle of radius 3::

            >>> from manim import Rectangle, Circle
            >>> import numpy as np
            >>> rect = Rectangle(height=2, width=4)
            >>> circ = Circle(radius=3)

        With ``stretch=True``, the target circle is deformed to match
        the proportions of the rectangle, which results in the target
        mobject being an ellipse with height 2 and width 4. We can
        check that the resulting points satisfy the ellipse equation
        :math:`x^2/a^2 + y^2/b^2 = 1` with :math:`a = 4/2` and :math:`b = 2/2`
        being the semi-axes::

            >>> result = rect.copy().become(circ, stretch=True)
            >>> result.height, result.width
            (np.float64(2.0), np.float64(4.0))
            >>> ellipse_points = np.array(result.get_anchors())
            >>> ellipse_eq = np.sum(ellipse_points**2 * [1/4, 1, 0], axis=1)
            >>> np.allclose(ellipse_eq, 1)
            True

        With ``match_height=True`` and ``match_width=True`` the circle is
        scaled such that the height or the width of the rectangle will
        be preserved, respectively.
        The points of the resulting mobject satisfy the circle equation
        :math:`x^2 + y^2 = r^2` for the corresponding radius :math:`r`::

            >>> result = rect.copy().become(circ, match_height=True)
            >>> result.height, result.width
            (np.float64(2.0), np.float64(2.0))
            >>> circle_points = np.array(result.get_anchors())
            >>> circle_eq = np.sum(circle_points**2, axis=1)
            >>> np.allclose(circle_eq, 1)
            True
            >>> result = rect.copy().become(circ, match_width=True)
            >>> result.height, result.width
            (np.float64(4.0), np.float64(4.0))
            >>> circle_points = np.array(result.get_anchors())
            >>> circle_eq = np.sum(circle_points**2, axis=1)
            >>> np.allclose(circle_eq, 2**2)
            True

        With ``match_center=True``, the resulting mobject is moved such that
        its center is the same as the center of the original mobject::

            >>> rect = rect.shift(np.array([0, 1, 0]))
            >>> np.allclose(rect.get_center(), circ.get_center())
            False
            >>> result = rect.copy().become(circ, match_center=True)
            >>> np.allclose(rect.get_center(), result.get_center())
            True

        See also
        --------
        :meth:`~.Mobject.align_data`, :meth:`~.VMobject.interpolate_color`
        T)rE  r+  r   )r   r  r   r  r   r  r   r  r  r  rj  rk  rJ  r-  r"  r   rt  r   r   )	rX   r   r  r  r  rr  ra  sm1sm2s	            rA   rE  zMobject.become
  s|   Z  	3l 	3k 	3[ 	3L 	3llnnG 
.--dk:::,,TZ888,,TZ8888 /((... .''--- .''--- 3 1 1222d;;;DOO--w/A/A/C/CDQQQ 	/ 	/HC#*--CJ!!#sA....rB   copy_submobjectsc                    t          |                                 |                                d          D ]#\  }}t          j        |j                  |_        $| S )aW  Edit points, positions, and submobjects to be identical
        to another :class:`~.Mobject`, 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)
        Fr+  )r-  r"  r   rt  r   )rX   r   rv  rt  ru  s        rA   match_pointszMobject.match_points  sV    " DOO--w/A/A/C/CERRR 	. 	.HC#*--CJJrB   c                    |                                  r1t          j        d          j        j        }t          d| d          d S )Nr   zCannot call Mobject.z for a Mobject with no points)r  sys	_getframef_codeco_namerD  )rX   caller_names     rA   r  z Mobject.throw_error_if_no_points  sU     	-**19KQ{QQQ  	 	rB   z_index_valuec                Z    |r!| j         D ]}|                    ||           || _        | S )a  Sets the :class:`~.Mobject`'s :attr:`z_index` to the value specified in `z_index_value`.

        Parameters
        ----------
        z_index_value
            The new value of :attr:`z_index` set.
        family
            If ``True``, the :attr:`z_index` value of all submobjects is also set.

        Returns
        -------
        :class:`Mobject`
            The Mobject itself, after :attr:`z_index` is set. For chaining purposes. (Returns `self`.)

        Examples
        --------
        .. manim:: SetZIndex
            :save_last_frame:

            class SetZIndex(Scene):
                def construct(self):
                    text = Text('z_index = 3', color = PURE_RED).shift(UP).set_z_index(3)
                    square = Square(2, fill_opacity=1).set_z_index(2)
                    tex = Tex(r'zIndex = 1', color = PURE_BLUE).shift(DOWN).set_z_index(1)
                    circle = Circle(radius = 1.7, color = GREEN, fill_opacity = 1) # z_index = 0

                    # Displaying order is now defined by z_index values
                    self.add(text)
                    self.add(square)
                    self.add(tex)
                    self.add(circle)
        r  )rQ   set_z_indexrJ   )rX   r  r  rh   s       rA   r  zMobject.set_z_index  sJ    J  	A* A A""="@@@@$rB   c                d    |                                  d         }|                     |           | S )zSets the :class:`~.Mobject`'s z Point3D to the value of :attr:`z_index`.

        Returns
        -------
        :class:`Mobject`
            The Mobject itself, after :attr:`z_index` is set. (Returns `self`.)
        r  )rk  r  )rX   z_coords     rA   set_z_index_by_z_Point3Dz Mobject.set_z_index_by_z_Point3D  s1     //##B'!!!rB   r3   r4   )
rD   rE   rF   rG   rH   rI   rJ   rK   r3   r4   )rQ   rY   r3   r"   )rQ   r]   r^   r_   r3   r"   )rj   rk   r3   rl   )rj   rk   ry   r$   r3   r4   )r3   r~   r3   r"   )r3   r   )r3   r   )r   r   r3   r"   )r   rI   r   r   r3   r4   r   r   )r   r   r3   r   )r3   rK   )r   rK   )r3   r   )r   r'   r3   r"   r   )r3   r)   )rF   rG   r3   r4   )F)r   r   r3   r"   )r   T)r  rK   r  r   r3   r"   )r3   r  )r3   r   )r3   r  rM   )r$  r1   r   r%  r&  r   r3   r"   )r$  r1   r3   r"   )T)r  r   r3   r"   )r   r   r3   r"   )r   r5  r3   r4   )r:  r-   r3   r"   )rC  rK   rA  rD  rB  rE  r3   r"   )rL  rK   rM  r-   r3   r"   )
rL  rK   rM  r-   rA  rD  rB  rE  r3   r"   )rM  r-   rA  rD  rB  rE  r3   r"   )
r\  rK   rH   rI   rA  rD  rB  rE  r3   r"   )rb  r%   rA  rD  rB  rE  r3   r"   )rb  r%   r3   r"   )ro  r&   rA  rD  rB  rE  r3   r"   )rb  rw  rA  rD  rB  rE  r3   r"   )r  rI   r3   r"   )NN)r   r'   rA  rD  rB  rE  r3   r"   )r  r-   r  rK   r3   r"   )r  r-   r  rK   r3   r"   )r  r-   r  rK   r3   r"   )r  r  r  r-   r  rK   r  r-   r  r  r  r%  r  r-   r3   r"   )r\  rK   rH   rI   r}  r+   r3   r"   )r  rK   rH   rI   ra  r   r3   r"   )r   rK   r3   r"   )r   rK   r3   r"   )r   rK   r3   r"   )rH   rI   r  r-   r3   r"   )r~  rK   r  r-   r3   r"   )r  rK   r  r-   r3   r"   )r  rK   r  r-   r3   r"   )r  )r\  rK   r3   r"   )r  r  r  r-   r  r-   r3   r"   )r   F)r   r   r  rI   ra  r   r3   r"   )
r   r   r  rI   ra  r   r  rK   r3   r"   )r  r+   r   r+   r3   r"   )Nr  )rD   r  r  rK   r3   r"   )rD   r   r  r   r3   r"   )r  r   r3   r"   )
r  rD  r#  rK   r$  r   r%  r   r3   r"   )r  r)  )rD   r   r6  rK   r  r   r3   r"   )r;  T)r<  rK   r  r   r3   r"   )r3   r   )rG  r   rH   rI   )r3   rL  )rQ  r   r3   rR  )r3   r^  )r3   rI   )Nr   r   )r   r[  rH   rI   r\  rI   r3   rK   )r  r-   r3   r*   )r3   r*   )rH   rI   r3   rK   )rH   rI   r  r-   r3   rK   )r  r-   r3   rK   )r3   r  )r6  rK   r3   r*   )r}  r+   r3   rK   )r  rK   r3   r   )r   r   rH   rI   r3   r"   )r   r   rH   rI   r  r-   r3   r"   )r  r  r  r-   r3   r"   )r3   r  )r3   r_   )r  r   r3   rL  )r  r-   r  rK   r  r   r3   r"   )r  r%  r  r%  r  r  r  r-   r  rG   r  rG   r  r  r  r  r  r   r3   r"   )r1  r2  r3  r4  r3   r"   )r  r   r3   r4   )r   r   rE  r   r3   r4   )rR  r   )r]  rI   r3   r^  )rh   r   r3   r"   )
rl  r   rm  r   r6  rK   rn  r(   r3   r"   )rl  r   rm  r   r6  rK   )FFFFF)r   r   r  r   r  r   r  r   rr  r   ra  r   r3   r"   )r   r   rv  r   r3   r"   )r  rK   r  r   r3   r"   )rN   
__module__r{   __doc__r:   classmethodr9   r   r<   r\   r[   rn   r;   rv   r}   propertyr   r   r   r   rU   rW   rV   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#  r)  r+  r-  r0  r2  r4  r9  r?  rK  r  rR  rP  r  r[  ra  rh  rl  rn  rv  r  r  r  rJ  r  r  r  r  DLr  r  r  r  !DEFAULT_MOBJECT_TO_MOBJECT_BUFFERrQ  r   rt  r  r  r  r  r  r   r  r   r  r   r  r  r  r  r  r  rj  r  MED_SMALL_BUFFr  r  r  r  r  r   r  r"  r   r(  r!  r'  r5  r9  r>  r8  rB  rF  rI  rP  rT  rV  rX  r  ra  r  r  rk  rk  ro  rq  rt  r  r  r  r  r|  r  r   r  r  r  r  r  r  r  rs  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  staticmethodr  r  r"  r7  r  r.  r7  r9  r<  r@  rB  rD  rJ  rM  rI  rO  rH  rG  r[  rU  rk  r   rp  r   rE  rx  r  r  r  __classcell__r@   s   @rA   r   r   B   sE        & - - - - - [- @E    ,M M M M@   2    [, D D D [D    [@ -1 -1 -1 [-1^ a' a' a' Xa'F !% !% !% X!%F         
      V V V Vp0 0 0 0$" " " "" " " "0 0 0 0d   6" " "" " "6 6 6 6p-X -X -X -X^ ' ' ' X'> \' ' ' \' ' ' ' X'> ]( ( ( ]( ' ' ' X' \' ' ' \'      " " " " "- - - - -
 
 
 
 
# # # #    ! ! ! ! !F
 
 
 
,
 
 
 
$    P P P P !"	O O O O Ob   6    4   :    4    8   ,   : +/*.3 3 3 3 3 3j FI < < < < < !E
 +/*.E E E E E ER  
 +/*.
 
 
 
 
 
@ +/*.     & +/*.     ,       +/*.     , +/*.(
 (
 (
 (
 (
 (
T   
   $ +/*.	    $  	 	 	 	 6T    $ &(7U2 2 2 2 2: $(7U0 0 0 0 0B #(7%+.237"*"(999"5"54 4 4 4 4l	 	 	 	= = =< < < < 8=
 
 
 
 
F F F F2E E E E2G G G G2F F F F2F F F FE E E E DJ      9? / / / / / 9? / / / / / 9? / / / / /     &,"*"(999"5"5	      HM    ( $
 
 
 
 
   : IM& & & & &P   
    +6d        &**/*/        &**/*/    $   
 GK	 	 	 	 	                 ,
 
 
 
	 	 	 	/ / / /% % % %        QR" " " " "    :2 2 2 22 2 2 2; ; ; ;F F F F! ! ! !
/ / / /.( ( ( (* * * *+ + + +* * * *) ) ) )( ( ( (3 3 3 3 =C H H H H H /5 , , , , , /5 , , , , , /5 , , , , ,( ( ( (
) ) ) )
0 0 0 0G G G GG G G G	
 	
 	
 	
* * * *
$ $ $ $% % % %3 3 3 3P P P P9 9 9 99 9 9 99 9 9 9
 EK
 
 
 
 
 39 7 7 7 7 7 39 7 7 7 7 7 39 7 7 7 7 7 #)    ., , ," " "! ! ! !       \) ) ) ) 6  6  6  6  6DH H H H8 #(7	    @  ,:'-%)%)5948o o o o of =KN7;    ) ) ) ) )# # # # #6- - - -** * * *- - - -&/ / / / /b' ' ' '   G G G G             ,    #0-//G G G G GRG G G G #!!"B B B B BH    ,    ) ) ) ) )V
 
 
 
 
 
 
 
rB   c                  $     e Zd ZdZd fdZ xZS )r   zGroups together multiple :class:`Mobjects <.Mobject>`.

    Notes
    -----
    When adding the same mobject more than once, repetitions are ignored.
    Use :meth:`.Mobject.copy` to create a separate copy which can then
    be added to the group.
    r3   r4   c                N     t                      j        di |  | j        |  d S r6   )r8   r<   r   )rX   r   r?   r@   s      rA   r<   zGroup.__init__  s5    ""6"""(rB   r  )rN   r  r{   r  r<   r  r  s   @rA   r   r     sG                  rB   r   )	metaclassc                  .    e Zd ZddZddZddZdd	Zd
S )r   r3   r4   c                    || _         | j                                          d | _        d| _        g | _        d| _        i | _        d S rM   )r   r  overridden_animationis_chainingmethodscannot_pass_args	anim_argsr   s     rA   r<   z_AnimationBuilder.__init__  sI    $$&&&$(! -/ !&rB   r"   c                N    | j         rt          d          || _        d| _         | S )NzWAnimation arguments must be passed before accessing methods and can only be passed onceT)r  rf   r  r  s     rA   __call__z_AnimationBuilder.__call__   s8      	i     $rB   r   c                     t           j        j        |          t          d           j        rs j        rt          d           fd}d _        d _        |S )N_override_animatezDMethod chaining is currently not supported for overridden animationsc                     r# j         j        g| R dj        i|_        n1j                            t          | |                      | i | S )Nr  )r  r   r  r  r  r(  r   )method_argsmethod_kwargshas_overridden_animationrx   rX   s     rA   update_targetz4_AnimationBuilder.__getattr__.<locals>.update_target  s    ' 	6,DF,DL- - - - #n- $	- -)) ##N6;$V$VWWW5}555KrB   T)rt   r   rO   ru   r  r  r   r  )rX   rw   r  r  rx   s   `  @@rA   r   z_AnimationBuilder.__getattr__  s    ,k::#*63F#G#G  	!9 	d>W 	%V  	 	 	 	 	 	 	   $rB   r.   c                    ddl m} | j        p || j        | j                  }| j                                        D ]\  }}t          |||           |S )Nr   )_MethodAnimation)animation.transformr  r  r   r  r  r   r   )rX   r  animr   r   s        rA   buildz_AnimationBuilder.build&  s|    	
 	
 	
 	
 	
 	
 (X,<,<T\4<,X,X>//11 	' 	'KD%D$&&&&rB   Nr  r  )r3   r   )r3   r.   )rN   r  r{   r<   r  r   r  r7   rB   rA   r   r     sd        
 
 
 
	 	 	 	   6
 
 
 
 
 
rB   r   c                  "    e Zd ZdZddZdd	Zd
S )r   z0Syntactic sugar for adding updaters to mobjects.r   r   c                    || _         d S r   )_mobjectr   s     rA   r<   z_UpdaterBuilder.__init__6  s    rB   rF   r   r3   Callable[..., Self]c                    d fd}|S )Nr3   r"   c                 N     j                              fdd           S )Nc                0     t          |           i S r   )rt   )r  r  r  rF   s    rA   rH  zB_UpdaterBuilder.__getattr__.<locals>.add_updater.<locals>.<lambda>=  s!    *'!T**KI=II rB   T)r&  )r  r)  )r  r  rF   rX   s   ``rA   r)  z0_UpdaterBuilder.__getattr__.<locals>.add_updater;  s@    M%%IIIIII! &    KrB   r  r7   )rX   rF   r)  s   `` rA   r   z_UpdaterBuilder.__getattr__9  s/    	 	 	 	 	 	 	 rB   Nr  )rF   r   r3   r  )rN   r  r{   r  r<   r   r7   rB   rA   r   r   3  sB        ::       	 	 	 	 	 	rB   r   r3   types.FunctionTypec                      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:`~.Mobject.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()

    c                    | _         | S r   )r  )animation_methodrx   s    rA   	decoratorz#override_animate.<locals>.decoratory  s    #3 rB   r7   )rx   r  s   ` rA   r   r   E  s%    h          rB   )r3   r  )Qr  
__future__r   __all__r   r  	itertoolsr   r  operatorr<  r:  rz  r   r   collections.abcr   r   	functoolsr	   r
   pathlibr   typingr   r   numpyr   manim.data_structuresr   )manim.mobject.opengl.opengl_compatibilityr    r   r   	constantsutils.colorr   r   r   r   r   r   r   utils.exceptionsr   utils.iterablesr   r   utils.pathsr   utils.space_opsr   r    r!   r"   r#   manim.typingr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   animation.animationr.   rK   r   r/   __annotations__r0   r1   r   r   r   r   r   r7   rB   rA   <module>r     s   5 5 5 " " " " " "
2
2
2             



   . . . . . . . . + + + + + + + +       % % % % % % % %     0 0 0 0 0 0 E E E E E E                              ? > > > > > C C C C C C C C ' ' ' ' ' ' O O O O O O O O O O @&&&&&&&&                        0/////"*Iu+=v+E"FFFFF%-yk6.A%BBBBB,/??G????_2 _2 _2 _2 _2 _2 _2 _2De    G    = = = = = = = =@       $8 8 8 8 8 8rB   