Skip to content

Commit

Permalink
Add type annotations to manim/camera/multi_camera.py - part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmidtiby committed Jan 21, 2025
1 parent 90f0dec commit b1a3508
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions manim/camera/multi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
__all__ = ["MultiCamera"]


from manim.mobject.types.image_mobject import ImageMobject
from collections.abc import Iterable
from typing import Any

from typing_extensions import Self

from manim.mobject.mobject import Mobject
from manim.mobject.types.image_mobject import ImageMobjectFromCamera

from ..camera.moving_camera import MovingCamera
from ..utils.iterables import list_difference_update
Expand All @@ -16,10 +22,10 @@ class MultiCamera(MovingCamera):

def __init__(
self,
image_mobjects_from_cameras: ImageMobject | None = None,
allow_cameras_to_capture_their_own_display=False,
**kwargs,
):
image_mobjects_from_cameras: Iterable[ImageMobjectFromCamera] | None = None,
allow_cameras_to_capture_their_own_display: bool = False,
**kwargs: Any,
) -> None:
"""Initialises the MultiCamera
Parameters
Expand All @@ -29,7 +35,7 @@ def __init__(
kwargs
Any valid keyword arguments of MovingCamera.
"""
self.image_mobjects_from_cameras = []
self.image_mobjects_from_cameras: list[ImageMobjectFromCamera] = []
if image_mobjects_from_cameras is not None:
for imfc in image_mobjects_from_cameras:
self.add_image_mobject_from_camera(imfc)
Expand All @@ -38,7 +44,9 @@ def __init__(
)
super().__init__(**kwargs)

def add_image_mobject_from_camera(self, image_mobject_from_camera: ImageMobject):
def add_image_mobject_from_camera(
self, image_mobject_from_camera: ImageMobjectFromCamera
) -> None:
"""Adds an ImageMobject that's been obtained from the camera
into the list ``self.image_mobject_from_cameras``
Expand All @@ -53,7 +61,7 @@ def add_image_mobject_from_camera(self, image_mobject_from_camera: ImageMobject)
assert isinstance(imfc.camera, MovingCamera)
self.image_mobjects_from_cameras.append(imfc)

def update_sub_cameras(self):
def update_sub_cameras(self) -> None:
"""Reshape sub_camera pixel_arrays"""
for imfc in self.image_mobjects_from_cameras:
pixel_height, pixel_width = self.pixel_array.shape[:2]
Expand All @@ -66,7 +74,7 @@ def update_sub_cameras(self):
int(pixel_width * imfc.width / self.frame_width),
)

def reset(self):
def reset(self) -> Self:
"""Resets the MultiCamera.
Returns
Expand All @@ -79,7 +87,7 @@ def reset(self):
super().reset()
return self

def capture_mobjects(self, mobjects, **kwargs):
def capture_mobjects(self, mobjects: Iterable[Mobject], **kwargs: Any) -> None:
self.update_sub_cameras()
for imfc in self.image_mobjects_from_cameras:
to_add = list(mobjects)
Expand All @@ -88,7 +96,7 @@ def capture_mobjects(self, mobjects, **kwargs):
imfc.camera.capture_mobjects(to_add, **kwargs)
super().capture_mobjects(mobjects, **kwargs)

def get_mobjects_indicating_movement(self):
def get_mobjects_indicating_movement(self) -> list[Mobject]:
"""Returns all mobjects whose movement implies that the camera
should think of all other mobjects on the screen as moving
Expand Down

0 comments on commit b1a3508

Please sign in to comment.