Skip to content

Conversation

@henrikmidtiby
Copy link
Contributor

Overview: What does this pull request change?

Motivation and Explanation: Why and how do your changes improve the library?

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@github-project-automation github-project-automation bot moved this to 🆕 New in Dev Board Dec 1, 2025
@henrikmidtiby henrikmidtiby added the typehints For adding/discussing typehints label Dec 1, 2025
@henrikmidtiby henrikmidtiby marked this pull request as ready for review December 1, 2025 22:27
@henrikmidtiby henrikmidtiby mentioned this pull request Dec 2, 2025
22 tasks
Copy link
Contributor

@chopan050 chopan050 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I left suggestions on the code. Most of them are minor changes, but there's a specific suggestion which is probably controversial and might require some discussion: making the checkerboard_colors None instead of False. Maybe it's better to simply use Literal[False] in this PR, discuss the topic, and then possibly change it to None in a follow-up PR?

Comment on lines +122 to +125
checkerboard_colors: Sequence[ParsableManimColor] | Literal[False] = [
BLUE_D,
BLUE_E,
],
Copy link
Contributor

Choose a reason for hiding this comment

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

More generally, checkerboard_colors could be any Iterable.
Based on how checkerboard_colors is used in the code, it seems more proper to use None instead of bool or Literal[False]. There are some caveats to that, however: there are some parts where the default value is explicitly False and making this change would require changing those default values as well, so feel free to disagree with me here.

Suggested change
checkerboard_colors: Sequence[ParsableManimColor] | Literal[False] = [
BLUE_D,
BLUE_E,
],
checkerboard_colors: Iterable[ParsableManimColor] | None = [BLUE_D, BLUE_E],

u_range: Sequence[float] = [0, 1],
v_range: Sequence[float] = [0, 1],
resolution: Sequence[int] = 32,
resolution: Sequence[int] | int = 32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: I would prefer to have int first, since it's the simplest data type.

Since the sequence is always expected to contain 2 integers, tuple[int, int] seems to be more fitting.

Since

Suggested change
resolution: Sequence[int] | int = 32,
resolution: int | tuple[int, int] = 32,

if checkerboard_colors is False:
self.checkerboard_colors = checkerboard_colors
else:
self.checkerboard_colors = [ManimColor(i) for i in checkerboard_colors]
Copy link
Contributor

Choose a reason for hiding this comment

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

Following the previous suggestion, this could be something like:

Suggested change
self.checkerboard_colors = [ManimColor(i) for i in checkerboard_colors]
self.checkerboard_colors: list[ManimColor] | None
if checkerboard_colors is None: # if not checkerboard_colors:
self.checkerboard_colors = checkerboard_colors
else:
self.checkerboard_colors = [ManimColor(i) for i in checkerboard_colors]

or:

Suggested change
self.checkerboard_colors = [ManimColor(i) for i in checkerboard_colors]
self.checkerboard_colors = (
[ManimColor(i) for i in checkerboard_colors]
if checkerboard_colors is not None else None # if checkerboard_colors else None
)

Note, however, that this might be a breaking change if people still passes checkerboard_colors=False, so you could consider the commented statements instead.

Comment on lines 116 to 117
u_range: Sequence[float] = [0, 1],
v_range: Sequence[float] = [0, 1],
Copy link
Contributor

@chopan050 chopan050 Dec 3, 2025

Choose a reason for hiding this comment

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

Based on the code which always expects them to have two floats, would it be possible for these two to be tuple[float, float]?

Suggested change
u_range: Sequence[float] = [0, 1],
v_range: Sequence[float] = [0, 1],
u_range: tuple[float, float] = (0, 1),
v_range: tuple[float, float] = (0, 1),

u_res = v_res = self.resolution
else:
u_res, v_res = res
u_res, v_res = self.resolution[0:2]
Copy link
Contributor

Choose a reason for hiding this comment

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

By having resolution typed as tuple[int, int] by a previous suggestion, this slicing would no longer be necessary:

Suggested change
u_res, v_res = self.resolution[0:2]
u_res, v_res = self.resolution

self._current_theta = theta
self._current_phi = phi

def set_direction(self, direction: np.ndarray) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

We could make this a Vector3DLike if we later convert it to a NumPy array inside the method:

Suggested change
def set_direction(self, direction: Vector3DLike) -> None:

checkerboard_colors: Sequence[ParsableManimColor] | Literal[False] = False,
**kwargs: Any,
) -> None:
self.direction = direction
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sure that the direction is copied and not referenced. References have caused some bugs in Manim:

Suggested change
self.direction = direction
self.direction = np.array(direction)

direction
The direction of the apex.
"""
self.direction = direction
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as with the constructor: make sure to copy the direction rather than referencing it.

Suggested change
self.direction = np.array(direction)

self.direction = direction
self._rotate_to_direction()

def get_direction(self) -> np.ndarray:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def get_direction(self) -> Vector3D:

return self.direction

def _set_start_and_end_attributes(self, direction):
def _set_start_and_end_attributes(self, direction: Vector3DLike) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an internal method where direction is going to be exclusively a NumPy array. Having it be something else like a list will raise errors on the first line, where it's multiplied by a float.

Suggested change
def _set_start_and_end_attributes(self, direction: Vector3DLike) -> None:
def _set_start_and_end_attributes(self, direction: Vector3D) -> None:

@github-project-automation github-project-automation bot moved this from 🆕 New to 👀 In review in Dev Board Dec 4, 2025
Copy link
Contributor

@chopan050 chopan050 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I left suggestions on the code. Most of them are minor changes, but there's a specific suggestion which is probably controversial and might require some discussion: making the checkerboard_colors None instead of False. Maybe it's better to simply use Literal[False] in this PR, discuss the topic, and then possibly change it to None in a follow-up PR?

@henrikmidtiby henrikmidtiby linked an issue Dec 5, 2025 that may be closed by this pull request
22 tasks
@henrikmidtiby henrikmidtiby removed a link to an issue Dec 5, 2025
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typehints For adding/discussing typehints

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

2 participants