
    lj#                        d Z ddlmZ dgZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ dd	lmZ dd
lmZ ddlmZmZmZmZ ddlmZ ddlmZ ddlmZmZ  G d de          ZdS )zDefines the MovingCamera class, a camera that can pan and zoom through a scene.

.. SEEALSO::

    :mod:`.moving_camera_scene`
    )annotationsMovingCamera)Iterable)Any)Context)
PixelArrayPoint3DPoint3DLike   )config)Camera)DOWNLEFTRIGHTUP)ScreenRectangle)Mobject)WHITE
ManimColorc                      e Zd ZdZddedfd1 fdZed2d            Zej        d3d            Zed2d            Z	e	j        d4d            Z	ed5d            Z
e
j        d6d            Z
d7 fdZd8d!Zd9d$Zd:d&Z	 	 	 d;d<d.Zd=d0Z xZS )>r   a  A camera that follows and matches the size and position of its 'frame', a Rectangle (or similar Mobject).

    The frame defines the region of space the camera displays and can move or resize dynamically.

    .. SEEALSO::

        :class:`.MovingCameraScene`
    Nr   frameMobject | Nonefixed_dimensionintdefault_frame_stroke_colorr   default_frame_stroke_widthkwargsr   c                    || _         || _        || _        |;t          t          d                   }|                    | j        | j                   || _         t                      j        di | dS )zFrame is a Mobject, (should almost certainly be a rectangle)
        determining which region of space the camera displays
        Nframe_heightheight )	r   r   r   r   r   
set_stroker   super__init__)selfr   r   r   r   r   	__class__s         U/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/camera/moving_camera.pyr%   zMovingCamera.__init__%   s      /*D'*D'=#6.+ABBBE//   
""6"""""    returnfloatc                    | j         j        S )z}Returns the height of the frame.

        Returns
        -------
        float
            The height of the frame.
        )r   r!   r&   s    r(   r   zMovingCamera.frame_height=   s     z  r)   r   Nonec                :    | j                             |           dS )zSets the height of the frame in MUnits.

        Parameters
        ----------
        frame_height
            The new frame_height.
        N)r   stretch_to_fit_height)r&   r   s     r(   r   zMovingCamera.frame_heightH   s      	
((66666r)   c                    | j         j        S )zzReturns the width of the frame

        Returns
        -------
        float
            The width of the frame.
        )r   widthr-   s    r(   frame_widthzMovingCamera.frame_widthS   s     zr)   r3   c                :    | j                             |           dS )zSets the width of the frame in MUnits.

        Parameters
        ----------
        frame_width
            The new frame_width.
        N)r   stretch_to_fit_width)r&   r3   s     r(   r3   zMovingCamera.frame_width^   s      	
''44444r)   r	   c                4    | j                                         S )zReturns the centerpoint of the frame in cartesian coordinates.

        Returns
        -------
        np.array
            The cartesian coordinates of the center of the frame.
        )r   
get_centerr-   s    r(   frame_centerzMovingCamera.frame_centeri   s     z$$&&&r)   r8   Point3DLike | Mobjectc                :    | j                             |           dS )a  Sets the centerpoint of the frame.

        Parameters
        ----------
        frame_center
            The point to which the frame must be moved.
            If is of type mobject, the frame will be moved to
            the center of that mobject.
        N)r   move_to)r&   r8   s     r(   r8   zMovingCamera.frame_centert   s      	
<(((((r)   mobjectsIterable[Mobject]c                <     t                      j        |fi | d S )N)r$   capture_mobjects)r&   r<   r   r'   s      r(   r?   zMovingCamera.capture_mobjects   s*     	! 44V44444r)   pixel_arrayr   c                    dS zSince the frame can be moving around, the cairo
        context used for updating should be regenerated
        at each frame.  So no caching.
        Nr"   )r&   r@   s     r(   get_cached_cairo_contextz%MovingCamera.get_cached_cairo_context   s	    
 tr)   ctxr   c                    dS rB   r"   )r&   r@   rD   s      r(   cache_cairo_contextz MovingCamera.cache_cairo_context   s	    
 	r)   list[Mobject]c                    | j         gS )zReturns all mobjects whose movement implies that the camera
        should think of all other mobjects on the screen as moving

        Returns
        -------
        list[Mobject]
        )r   r-   s    r(    get_mobjects_indicating_movementz-MovingCamera.get_mobjects_indicating_movement   s     
|r)   FTmarginonly_mobjects_in_frameboolanimater   c                   |                      ||          \  }}}}||z   dz  }	||z   dz  }
t          ||z
            }t          ||z
            }|r| j        j        n| j        }|| j        j        z  || j        j        z  k    r?|                    |	                              |
                              ||z             S |                    |	                              |
                              ||z             S )a  Zooms on to a given array of mobjects (or a singular mobject)
        and automatically resizes to frame all the mobjects.

        .. NOTE::

            This method only works when 2D-objects in the XY-plane are considered, it
            will not work correctly when the camera has been rotated.

        Parameters
        ----------
        mobjects
            The mobject or array of mobjects that the camera will focus on.

        margin
            The width of the margin that is added to the frame (optional, 0 by default).

        only_mobjects_in_frame
            If set to ``True``, only allows focusing on mobjects that are already in frame.

        animate
            If set to ``False``, applies the changes instead of returning the corresponding animation

        Returns
        -------
        Union[_AnimationBuilder, ScreenRectangle]
            _AnimationBuilder that zooms the camera view to a given list of mobjects
            or ScreenRectangle with position and size updated to zoomed position.

        r   )r2   r    )	_get_bounding_boxabsr   rM   r2   r!   set_xset_yset)r&   r<   rJ   rK   rM   scene_critical_x_leftscene_critical_x_rightscene_critical_y_upscene_critical_y_downxy	new_width
new_heightm_targets                 r(   	auto_zoomzMovingCamera.auto_zoom   s   R ""8-CDD	
!"! #%;;q@ #88A= -0FFGG	,/DDEE
)0@4:%%djtz''*tz7H*HHH>>!$$**1--11	F8J1KKK>>!$$**1--11f9L1MMMr)   !tuple[float, float, float, float]c                   d}d}d}d}d}|D ]}|| j         k    s|r|                     |          s&|s|                    t                    d         }|                    t                    d         }|                    t
                    d         }|                    t                    d         }d}|                    t                    d         |k     r |                    t                    d         }|                    t                    d         |k    r |                    t                    d         }|                    t
                    d         |k    r |                    t
                    d         }|                    t                    d         |k     r |                    t                    d         }|st          d          ||||fS )NFr      TzFCould not determine bounding box of the mobjects given to 'auto_zoom'.)r   is_in_frameget_critical_pointr   r   r   r   	Exception)	r&   r<   rK   bounding_box_locatedrT   rU   rV   rW   ms	            r(   rO   zMovingCamera._get_bounding_box   s     %'(()%&'( 	J 	JATZ&  /3/?/?/B/B    ( J()(<(<T(B(B1(E%)*)=)=e)D)DQ)G&&'&:&:2&>&>q&A#()(<(<T(B(B1(E%'+$$ ''--a03HHH,-,@,@,F,Fq,I)''..q14JJJ-.-A-A%-H-H-K*''++A.1DDD*+*>*>r*B*B1*E'''--a03HHH,-,@,@,F,Fq,I)# 	X  
 ""!	
 	
r)   )
r   r   r   r   r   r   r   r   r   r   )r*   r+   )r   r+   r*   r.   )r3   r+   r*   r.   )r*   r	   )r8   r9   r*   r.   )r<   r=   r   r   r*   r.   )r@   r   r*   r.   )r@   r   rD   r   r*   r.   )r*   rG   )r   FT)
r<   r=   rJ   r+   rK   rL   rM   rL   r*   r   )r<   r=   rK   rL   r*   r^   )__name__
__module____qualname____doc__r   r%   propertyr   setterr3   r8   r?   rC   rF   rI   r]   rO   __classcell__)r'   s   @r(   r   r      s         !% 16*+# # # # # # #0 ! ! ! X! 7 7 7 7       X  5 5 5 5 ' ' ' X' 
) 
) 
) 
)5 5 5 5 5 5
      $    ',8N 8N 8N 8N 8Nt/
 /
 /
 /
 /
 /
 /
 /
r)   N)ri   
__future__r   __all__collections.abcr   typingr   cairor   manim.typingr   r	   r
    r   camera.camerar   	constantsr   r   r   r   mobject.framer   mobject.mobjectr   utils.colorr   r   r   r"   r)   r(   <module>ry      sA    # " " " " "
 $ $ $ $ $ $             9 9 9 9 9 9 9 9 9 9       " " " " " " - - - - - - - - - - - - + + + + + + % % % % % % + + + + + + + +w
 w
 w
 w
 w
6 w
 w
 w
 w
 w
r)   