mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Add type annotations to point_cloud_mobject.py (#4586)
* Add type annotations to point_cloud_mobject.py * Make reset_points return Self instead of None * Fix return type of get_array_attrs() * Change return type of reset_points() to Self in image_mobject.py
This commit is contained in:
parent
601a007192
commit
ab7cfc54d8
4 changed files with 9 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ import warnings
|
|||
from collections.abc import Callable, Iterable
|
||||
from functools import partialmethod, reduce
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
|
@ -442,9 +442,10 @@ class Mobject:
|
|||
def __repr__(self) -> str:
|
||||
return str(self.name)
|
||||
|
||||
def reset_points(self) -> None:
|
||||
def reset_points(self) -> Self:
|
||||
"""Sets :attr:`points` to be an empty array."""
|
||||
self.points = np.zeros((0, self.dim))
|
||||
return self
|
||||
|
||||
def init_colors(self) -> object:
|
||||
"""Initializes the colors.
|
||||
|
|
@ -851,7 +852,7 @@ class Mobject:
|
|||
self.scale_to_fit_depth(value)
|
||||
|
||||
# Can't be staticmethod because of point_cloud_mobject.py
|
||||
def get_array_attrs(self) -> list[Literal["points"]]:
|
||||
def get_array_attrs(self) -> list[str]:
|
||||
return ["points"]
|
||||
|
||||
def apply_over_attr_arrays(self, func: MultiMappingFunction) -> Self:
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class AbstractImageMobject(Mobject):
|
|||
self.resampling_algorithm = resampling_algorithm
|
||||
return self
|
||||
|
||||
def reset_points(self) -> None:
|
||||
def reset_points(self) -> Self:
|
||||
"""Sets :attr:`points` to be the four image corners."""
|
||||
self.points = np.array(
|
||||
[
|
||||
|
|
@ -127,6 +127,7 @@ class AbstractImageMobject(Mobject):
|
|||
height = 3 # this is the case for ImageMobjectFromCamera
|
||||
self.stretch_to_fit_height(height)
|
||||
self.stretch_to_fit_width(height * w / h)
|
||||
return self
|
||||
|
||||
|
||||
class ImageMobject(AbstractImageMobject):
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
|
|||
|
||||
def set_color_by_gradient(self, *colors: ParsableManimColor) -> Self:
|
||||
self.rgbas = np.array(
|
||||
list(map(color_to_rgba, color_gradient(*colors, len(self.points)))),
|
||||
list(map(color_to_rgba, color_gradient(colors, len(self.points)))),
|
||||
)
|
||||
return self
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
|
|||
for mob in self.family_members_with_points():
|
||||
num_points = self.get_num_points()
|
||||
mob.apply_over_attr_arrays(
|
||||
lambda arr, n=num_points: arr[np.arange(0, n, factor)],
|
||||
lambda arr, n=num_points: arr[np.arange(0, n, factor)], # type: ignore[misc]
|
||||
)
|
||||
return self
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ class PMobject(Mobject, metaclass=ConvertToOpenGL):
|
|||
"""Function is any map from R^3 to R"""
|
||||
for mob in self.family_members_with_points():
|
||||
indices = np.argsort(np.apply_along_axis(function, 1, mob.points))
|
||||
mob.apply_over_attr_arrays(lambda arr, idx=indices: arr[idx])
|
||||
mob.apply_over_attr_arrays(lambda arr, idx=indices: arr[idx]) # type: ignore[misc]
|
||||
return self
|
||||
|
||||
def fade_to(
|
||||
|
|
|
|||
3
mypy.ini
3
mypy.ini
|
|
@ -100,9 +100,6 @@ ignore_errors = True
|
|||
[mypy-manim.mobject.table]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-manim.mobject.types.point_cloud_mobject]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-manim.mobject.types.vectorized_mobject]
|
||||
ignore_errors = True
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue