Skip to content

Add type annotations for most of camera and mobject.graphing #4125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c8a2228
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jan 20, 2025
8249c13
Add type annotations to camera/camera.py
henrikmidtiby Jan 10, 2025
bddb6ad
Part 2
henrikmidtiby Jan 20, 2025
ea60db4
Part 3
henrikmidtiby Jan 20, 2025
d9dcb3d
Part 1
henrikmidtiby Jan 17, 2025
97cc36a
Add type annotations to mobject/graphing/scale.py
henrikmidtiby Jan 17, 2025
65129cc
Add type annotations to most of mobject/graphing/probability.py
henrikmidtiby Jan 17, 2025
785ad1a
Add type annotations to mobject/graphing/number_line.py
henrikmidtiby Jan 17, 2025
859358e
Avoid a circular import.
henrikmidtiby Jan 21, 2025
f8e1bae
Add type annotations to mobject/graphing/functions.py
henrikmidtiby Jan 17, 2025
d5d3928
In progress: Add typehints to graphing/coordinate_systems.py part1
henrikmidtiby Jan 20, 2025
3969b7e
In progress: Add typehints to graphing/coordinate_systems.py part 2
henrikmidtiby Jan 21, 2025
90f0dec
Add type annotations to manim/camera/multi_camera.py - part 1
henrikmidtiby Jan 17, 2025
b1a3508
Add type annotations to manim/camera/multi_camera.py - part 2
henrikmidtiby Jan 21, 2025
f767e8a
Add type annotations to manim/camera/multi_camera.py - part 3
henrikmidtiby Jan 21, 2025
8d13460
Merge branch 'main' into Typing_graphing_and_camera
chopan050 Mar 11, 2025
7edb642
Merge branch 'main' into Typing_graphing_and_camera
chopan050 Jul 29, 2025
9db34ef
Reducing the scope of the PR and fixed a number of small items
henrikmidtiby Jul 30, 2025
3ff1095
Removing type ignore statements.
henrikmidtiby Jul 30, 2025
967ef1e
Fixing two type issues
henrikmidtiby Jul 30, 2025
9f148ea
...
henrikmidtiby Jul 30, 2025
297be56
Merge branch 'main' into Typing_graphing_and_camera
henrikmidtiby Jul 30, 2025
efe5565
Updates based on input from Chopan50
henrikmidtiby Jul 30, 2025
e613eb1
Reverting to type ignores and assert statements to fix the last type …
henrikmidtiby Jul 30, 2025
a673de3
Merge remote-tracking branch 'upstream/main' into Typing_graphing_and…
henrikmidtiby Jul 30, 2025
c03c8d8
Update manim/mobject/graphing/functions.py
henrikmidtiby Jul 31, 2025
0da8a6a
Update manim/mobject/graphing/functions.py
henrikmidtiby Jul 31, 2025
9a9e412
Update manim/mobject/graphing/functions.py
henrikmidtiby Jul 31, 2025
efc7a61
Update manim/mobject/graphing/number_line.py
henrikmidtiby Jul 31, 2025
14c339a
Update manim/mobject/graphing/number_line.py
henrikmidtiby Jul 31, 2025
ff789bb
Update manim/mobject/graphing/number_line.py
henrikmidtiby Jul 31, 2025
1b1798d
Suggestions from Chopan50
henrikmidtiby Jul 31, 2025
9263abd
More suggestions from Chopan50
henrikmidtiby Jul 31, 2025
8309fe9
Updates
henrikmidtiby Jul 31, 2025
1c582b7
Minor improvements to coordinate_systems.py
henrikmidtiby Jul 31, 2025
603779c
Minor improvements to number_line.py
henrikmidtiby Jul 31, 2025
3307494
Minor improvements to functions.py
henrikmidtiby Jul 31, 2025
55dac2f
Update manim/mobject/graphing/scale.py
chopan050 Aug 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 118 additions & 90 deletions manim/camera/camera.py

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions manim/camera/moving_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

__all__ = ["MovingCamera"]

from collections.abc import Iterable
from typing import Any

import numpy as np

from .. import config
from ..camera.camera import Camera
from ..constants import DOWN, LEFT, RIGHT, UP
from ..mobject.frame import ScreenRectangle
from ..mobject.mobject import Mobject
from ..utils.color import WHITE
from ..utils.color import WHITE, ManimColor


class MovingCamera(Camera):
Expand All @@ -32,10 +35,10 @@ class MovingCamera(Camera):
def __init__(
self,
frame=None,
fixed_dimension=0, # width
default_frame_stroke_color=WHITE,
default_frame_stroke_width=0,
**kwargs,
fixed_dimension: int = 0, # width
default_frame_stroke_color: ManimColor = WHITE,
default_frame_stroke_width: int = 0,
**kwargs: Any,
) -> None:
"""Frame is a Mobject, (should almost certainly be a rectangle)
determining which region of space the camera displays
Expand Down Expand Up @@ -121,7 +124,7 @@ def frame_center(self, frame_center: np.ndarray | list | tuple | Mobject):
"""
self.frame.move_to(frame_center)

def capture_mobjects(self, mobjects, **kwargs):
def capture_mobjects(self, mobjects: Iterable[Mobject], **kwargs: Any) -> None:
# self.reset_frame_center()
# self.realign_frame_shape()
super().capture_mobjects(mobjects, **kwargs)
Expand Down
38 changes: 23 additions & 15 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,20 +61,20 @@ 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]
imfc.camera.frame_shape = (
imfc.camera.frame.height,
imfc.camera.frame.width,
)
# imfc.camera.frame_shape = (
# imfc.camera.frame.height,
# imfc.camera.frame.width,
# )
imfc.camera.reset_pixel_shape(
int(pixel_height * imfc.height / self.frame_height),
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
Loading