Skip to content

Commit

Permalink
replaced np.ndarray with more appropriate type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
behackl committed Oct 28, 2023
1 parent 351353a commit 3616c50
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)

import numpy as np
import numpy.typing as npt
from PIL.Image import Image
from typing_extensions import Self

Expand Down Expand Up @@ -220,7 +221,7 @@ def generate_rgbas_array(
opacities: list[float] = [
o if (o is not None) else 0.0 for o in tuplify(opacity)
]
rgbas: np.ndarray[RGBA_Array_Float] = np.array(
rgbas: npt.NDArray[RGBA_Array_Float] = np.array(
[c.to_rgba_with_alpha(o) for c, o in zip(*make_even(colors, opacities))],
)

Expand Down Expand Up @@ -473,7 +474,7 @@ def get_fill_colors(self) -> list[ManimColor | None]:
for rgba in self.get_fill_rgbas()
]

def get_fill_opacities(self) -> np.ndarray[ManimFloat]:
def get_fill_opacities(self) -> npt.NDArray[ManimFloat]:
return self.get_fill_rgbas()[:, 3]

def get_stroke_rgbas(self, background: bool = False) -> RGBA_Array_float | Zeros:
Expand Down Expand Up @@ -512,7 +513,7 @@ def get_stroke_colors(self, background: bool = False) -> list[ManimColor | None]
for rgba in self.get_stroke_rgbas(background)
]

def get_stroke_opacities(self, background: bool = False) -> np.ndarray[ManimFloat]:
def get_stroke_opacities(self, background: bool = False) -> npt.NDArray[ManimFloat]:
return self.get_stroke_rgbas(background)[:, 3]

def get_color(self) -> ManimColor:
Expand Down Expand Up @@ -670,7 +671,7 @@ def set_points(self, points: Point3D_Array) -> Self:
def resize_points(
self,
new_length: int,
resize_func: Callable[[np.ndarray, int], np.ndarray] = resize_array,
resize_func: Callable[[Point3D, int], Point3D] = resize_array,
) -> Self:
"""Resize the array of anchor points and handles to have
the specified size.
Expand Down Expand Up @@ -1068,7 +1069,7 @@ def consider_points_equals_2d(self, p0: Point2D, p1: Point2D) -> bool:
# Information about line
def get_cubic_bezier_tuples_from_points(
self, points: Point3D_Array
) -> np.ndarray[Point3D_Array]:
) -> npt.NDArray[Point3D_Array]:
return np.array(self.gen_cubic_bezier_tuples_from_points(points))

def gen_cubic_bezier_tuples_from_points(
Expand Down Expand Up @@ -1097,7 +1098,7 @@ def gen_cubic_bezier_tuples_from_points(
# Basically take every nppcc element.
return tuple(points[i : i + nppcc] for i in range(0, len(points), nppcc))

def get_cubic_bezier_tuples(self) -> np.ndarray[Point3D_Array]:
def get_cubic_bezier_tuples(self) -> npt.NDArray[Point3D_Array]:
return self.get_cubic_bezier_tuples_from_points(self.points)

def _gen_subpaths_from_points(
Expand Down Expand Up @@ -1198,7 +1199,7 @@ def get_nth_curve_length_pieces(
self,
n: int,
sample_points: int | None = None,
) -> np.ndarray[ManimFloat]:
) -> npt.NDArray[ManimFloat]:
"""Returns the array of short line lengths used for length approximation.
Parameters
Expand All @@ -1210,7 +1211,6 @@ def get_nth_curve_length_pieces(
Returns
-------
np.ndarray[ManimFloat]
The short length-pieces of the nth curve.
"""
if sample_points is None:
Expand Down Expand Up @@ -1597,7 +1597,7 @@ def insert_n_curves(self, n: int) -> Self:

def insert_n_curves_to_point_list(
self, n: int, points: Point3D_Array
) -> np.ndarray[BezierPoints]:
) -> npt.NDArray[BezierPoints]:
"""Given an array of k points defining a bezier curves (anchors and handles), returns points defining exactly k + n bezier curves.
Parameters
Expand All @@ -1609,7 +1609,6 @@ def insert_n_curves_to_point_list(
Returns
-------
np.ndarray
Points generated.
"""

Expand Down Expand Up @@ -2410,7 +2409,7 @@ def __init__(self, vmobject: VMobject, **kwargs) -> None:
part.match_style(vmobject)
self.add(part)

def point_from_proportion(self, alpha: float) -> np.ndarray:
def point_from_proportion(self, alpha: float) -> Point3D:

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
"""Gets the point at a proportion along the path of the :class:`CurvesAsSubmobjects`.
Parameters
Expand Down

0 comments on commit 3616c50

Please sign in to comment.