Skip to content

Commit 2790a70

Browse files
NASAnerd05pre-commit-ci[bot]behackl
authored
Improved readability, grammar, as well as added docstrings for consistency (#4267)
* Improve MappingCamera, MovingCamera, Rotation, CliColors, and _init_.py readability and docstrings * Readibility and docsstrings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestion from @behackl --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Benjamin Hackl <[email protected]>
1 parent fdb5cb9 commit 2790a70

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

manim/_config/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
parser = make_config_parser()
2525

26-
# The logger can be accessed from anywhere as manim.logger, or as
27-
# logging.getLogger("manim"). The console must be accessed as manim.console.
28-
# Throughout the codebase, use manim.console.print() instead of print().
29-
# Use error_console to print errors so that it outputs to stderr.
26+
# Logger usage: accessible globally as `manim.logger` or via `logging.getLogger("manim")`.
27+
# For printing, use `manim.console.print()` instead of the built-in `print()`.
28+
# For error output, use `error_console`, which prints to stderr.
3029
logger, console, error_console = make_logger(
3130
parser["logger"],
3231
parser["CLI"]["verbosity"],
@@ -45,7 +44,7 @@
4544
# This has to go here because it needs access to this module's config
4645
@contextmanager
4746
def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None]:
48-
"""Context manager that temporarily modifies the global ``config`` object.
47+
"""Temporarily modifies the global ``config`` object using a context manager.
4948
5049
Inside the ``with`` statement, the modified config will be used. After
5150
context manager exits, the config will be restored to its original state.

manim/_config/cli_colors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""Parses CLI context settings from the configuration file and returns a Cloup Context settings dictionary.
2+
3+
This module reads configuration values for help formatting, theme styles, and alignment options
4+
used when rendering command-line interfaces in Manim.
5+
"""
6+
17
from __future__ import annotations
28

39
import configparser
@@ -28,6 +34,7 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
2834
"col2",
2935
"epilog",
3036
}
37+
# Extract and apply any style-related keys defined in the config section.
3138
for k, v in parser.items():
3239
if k in theme_keys and v:
3340
theme_settings.update({k: Style(v)})

manim/camera/mapping_camera.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""A camera that allows mapping between objects."""
1+
"""A camera module that supports spatial mapping between objects for distortion effects."""
22

33
from __future__ import annotations
44

@@ -17,8 +17,16 @@
1717

1818

1919
class MappingCamera(Camera):
20-
"""Camera object that allows mapping
21-
between objects.
20+
"""Parameters
21+
----------
22+
mapping_func : callable
23+
Function to map 3D points to new 3D points (identity by default).
24+
min_num_curves : int
25+
Minimum number of curves for VMobjects to avoid visual glitches.
26+
allow_object_intrusion : bool
27+
If True, modifies original mobjects; else works on copies.
28+
kwargs : dict
29+
Additional arguments passed to Camera base class.
2230
"""
2331

2432
def __init__(
@@ -34,12 +42,18 @@ def __init__(
3442
super().__init__(**kwargs)
3543

3644
def points_to_pixel_coords(self, mobject, points):
45+
# Map points with custom function before converting to pixels
3746
return super().points_to_pixel_coords(
3847
mobject,
3948
np.apply_along_axis(self.mapping_func, 1, points),
4049
)
4150

4251
def capture_mobjects(self, mobjects, **kwargs):
52+
"""Capture mobjects for rendering after applying the spatial mapping.
53+
54+
Copies mobjects unless intrusion is allowed, and ensures
55+
vector objects have enough curves for smooth distortion.
56+
"""
4357
mobjects = self.get_mobjects_to_display(mobjects, **kwargs)
4458
if self.allow_object_intrusion:
4559
mobject_copies = mobjects
@@ -67,6 +81,13 @@ def capture_mobjects(self, mobjects, **kwargs):
6781

6882
# TODO, the classes below should likely be deleted
6983
class OldMultiCamera(Camera):
84+
"""Parameters
85+
----------
86+
cameras_with_start_positions : tuple
87+
Tuples of (Camera, (start_y, start_x)) indicating camera and
88+
its pixel offset on the final frame.
89+
"""
90+
7091
def __init__(self, *cameras_with_start_positions, **kwargs):
7192
self.shifted_cameras = [
7293
DictAsObject(
@@ -125,6 +146,15 @@ def init_background(self):
125146

126147

127148
class SplitScreenCamera(OldMultiCamera):
149+
"""Initializes a split screen camera setup with two side-by-side cameras.
150+
151+
Parameters
152+
----------
153+
left_camera : Camera
154+
right_camera : Camera
155+
kwargs : dict
156+
"""
157+
128158
def __init__(self, left_camera, right_camera, **kwargs):
129159
Camera.__init__(self, **kwargs) # to set attributes such as pixel_width
130160
self.left_camera = left_camera

manim/camera/moving_camera.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""A camera able to move through a scene.
1+
"""Defines the MovingCamera class, a camera that can pan and zoom through a scene.
22
33
.. SEEALSO::
44
55
:mod:`.moving_camera_scene`
6-
76
"""
87

98
from __future__ import annotations
@@ -21,13 +20,13 @@
2120

2221

2322
class MovingCamera(Camera):
24-
"""
25-
Stays in line with the height, width and position of it's 'frame', which is a Rectangle
23+
"""A camera that follows and matches the size and position of its 'frame', a Rectangle (or similar Mobject).
24+
25+
The frame defines the region of space the camera displays and can move or resize dynamically.
2626
2727
.. SEEALSO::
2828
2929
:class:`.MovingCameraScene`
30-
3130
"""
3231

3332
def __init__(
@@ -38,8 +37,7 @@ def __init__(
3837
default_frame_stroke_width=0,
3938
**kwargs,
4039
):
41-
"""
42-
Frame is a Mobject, (should almost certainly be a rectangle)
40+
"""Frame is a Mobject, (should almost certainly be a rectangle)
4341
determining which region of space the camera displays
4442
"""
4543
self.fixed_dimension = fixed_dimension
@@ -132,16 +130,14 @@ def capture_mobjects(self, mobjects, **kwargs):
132130
# context used for updating should be regenerated
133131
# at each frame. So no caching.
134132
def get_cached_cairo_context(self, pixel_array):
135-
"""
136-
Since the frame can be moving around, the cairo
133+
"""Since the frame can be moving around, the cairo
137134
context used for updating should be regenerated
138135
at each frame. So no caching.
139136
"""
140137
return None
141138

142139
def cache_cairo_context(self, pixel_array, ctx):
143-
"""
144-
Since the frame can be moving around, the cairo
140+
"""Since the frame can be moving around, the cairo
145141
context used for updating should be regenerated
146142
at each frame. So no caching.
147143
"""
@@ -159,8 +155,7 @@ def cache_cairo_context(self, pixel_array, ctx):
159155
# self.resize_frame_shape(fixed_dimension=self.fixed_dimension)
160156

161157
def get_mobjects_indicating_movement(self):
162-
"""
163-
Returns all mobjects whose movement implies that the camera
158+
"""Returns all mobjects whose movement implies that the camera
164159
should think of all other mobjects on the screen as moving
165160
166161
Returns

0 commit comments

Comments
 (0)