Skip to content

Improved readability, grammar, as well as added docstrings for consistency #4267

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions manim/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@

parser = make_config_parser()

# The logger can be accessed from anywhere as manim.logger, or as
# logging.getLogger("manim"). The console must be accessed as manim.console.
# Throughout the codebase, use manim.console.print() instead of print().
# Use error_console to print errors so that it outputs to stderr.
# Logger usage: accessible globally as `manim.logger` or via `logging.getLogger("manim")`.
# For printing, use `manim.console.print()` instead of the built-in `print()`.
# For error output, use `error_console`, which prints to stderr.
logger, console, error_console = make_logger(
parser["logger"],
parser["CLI"]["verbosity"],
Expand All @@ -45,7 +44,7 @@
# This has to go here because it needs access to this module's config
@contextmanager
def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None]:
"""Context manager that temporarily modifies the global ``config`` object.
"""Temporarily modifies the global ``config`` object using a context manager.

Inside the ``with`` statement, the modified config will be used. After
context manager exits, the config will be restored to its original state.
Expand Down
7 changes: 7 additions & 0 deletions manim/_config/cli_colors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Parses CLI context settings from the configuration file and returns a Cloup Context settings dictionary.

This module reads configuration values for help formatting, theme styles, and alignment options
used when rendering command-line interfaces in Manim.
"""

from __future__ import annotations

import configparser
Expand Down Expand Up @@ -28,6 +34,7 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> dict[str, Any]:
"col2",
"epilog",
}
# Extract and apply any style-related keys defined in the config section.
for k, v in parser.items():
if k in theme_keys and v:
theme_settings.update({k: Style(v)})
Expand Down
4 changes: 4 additions & 0 deletions manim/animation/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@


class Rotating(Animation):
"""Continuously rotates a mobject over time.
Useful for animations like orbiting planets or spinning logos.
"""

def __init__(
self,
mobject: Mobject,
Expand Down
36 changes: 33 additions & 3 deletions manim/camera/mapping_camera.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""A camera that allows mapping between objects."""
"""A camera module that supports spatial mapping between objects for distortion effects."""

from __future__ import annotations

Expand All @@ -17,8 +17,16 @@


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

def __init__(
Expand All @@ -34,12 +42,18 @@ def __init__(
super().__init__(**kwargs)

def points_to_pixel_coords(self, mobject, points):
# Map points with custom function before converting to pixels
return super().points_to_pixel_coords(
mobject,
np.apply_along_axis(self.mapping_func, 1, points),
)

def capture_mobjects(self, mobjects, **kwargs):
"""Capture mobjects for rendering after applying the spatial mapping.

Copies mobjects unless intrusion is allowed, and ensures
vector objects have enough curves for smooth distortion.
"""
mobjects = self.get_mobjects_to_display(mobjects, **kwargs)
if self.allow_object_intrusion:
mobject_copies = mobjects
Expand Down Expand Up @@ -67,6 +81,13 @@ def capture_mobjects(self, mobjects, **kwargs):

# TODO, the classes below should likely be deleted
class OldMultiCamera(Camera):
"""Parameters
----------
*cameras_with_start_positions : tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it is recommended to document starred args / kwargs without including the asterisks.

Suggested change
*cameras_with_start_positions : tuple
cameras_with_start_positions : tuple

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we're not including them in our docstrings. However, our docs say that we're following the NumPy style guide, which does recommend to include the leading stars. In the future, there should probably be a PR to make our docstrings conform more to that style guide.

Tuples of (Camera, (start_y, start_x)) indicating camera and
its pixel offset on the final frame.
"""

def __init__(self, *cameras_with_start_positions, **kwargs):
self.shifted_cameras = [
DictAsObject(
Expand Down Expand Up @@ -125,6 +146,15 @@ def init_background(self):


class SplitScreenCamera(OldMultiCamera):
"""Initializes a split screen camera setup with two side-by-side cameras.

Parameters
----------
left_camera : Camera
right_camera : Camera
kwargs : dict
"""

def __init__(self, left_camera, right_camera, **kwargs):
Camera.__init__(self, **kwargs) # to set attributes such as pixel_width
self.left_camera = left_camera
Expand Down
21 changes: 8 additions & 13 deletions manim/camera/moving_camera.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""A camera able to move through a scene.
"""Defines the MovingCamera class, a camera that can pan and zoom through a scene.

.. SEEALSO::

:mod:`.moving_camera_scene`

"""

from __future__ import annotations
Expand All @@ -21,13 +20,13 @@


class MovingCamera(Camera):
"""
Stays in line with the height, width and position of it's 'frame', which is a Rectangle
"""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`

"""

def __init__(
Expand All @@ -38,8 +37,7 @@ def __init__(
default_frame_stroke_width=0,
**kwargs,
):
"""
Frame is a Mobject, (should almost certainly be a rectangle)
"""Frame is a Mobject, (should almost certainly be a rectangle)
determining which region of space the camera displays
"""
self.fixed_dimension = fixed_dimension
Expand Down Expand Up @@ -132,16 +130,14 @@ def capture_mobjects(self, mobjects, **kwargs):
# context used for updating should be regenerated
# at each frame. So no caching.
def get_cached_cairo_context(self, pixel_array):
"""
Since the frame can be moving around, the cairo
"""Since the frame can be moving around, the cairo
context used for updating should be regenerated
at each frame. So no caching.
"""
return None

def cache_cairo_context(self, pixel_array, ctx):
"""
Since the frame can be moving around, the cairo
"""Since the frame can be moving around, the cairo
context used for updating should be regenerated
at each frame. So no caching.
"""
Expand All @@ -159,8 +155,7 @@ def cache_cairo_context(self, pixel_array, ctx):
# self.resize_frame_shape(fixed_dimension=self.fixed_dimension)

def get_mobjects_indicating_movement(self):
"""
Returns all mobjects whose movement implies that the camera
"""Returns all mobjects whose movement implies that the camera
should think of all other mobjects on the screen as moving

Returns
Expand Down