From 84c9cdca45dd2f5ba843f9daf1d395f047f69a22 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Sun, 29 Oct 2023 10:16:50 +0100 Subject: [PATCH] Apply feedback --- manim/_config/utils.py | 1 - manim/mobject/geometry/arc.py | 6 +- manim/mobject/graphing/coordinate_systems.py | 1 - manim/mobject/mobject.py | 59 ++++++++++--------- .../opengl/opengl_vectorized_mobject.py | 7 +-- manim/utils/bezier.py | 7 ++- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/manim/_config/utils.py b/manim/_config/utils.py index d5512b491f..e7b1d0cdc8 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -1094,7 +1094,6 @@ def format(self, val: str) -> None: doc="Frame rate in frames per second.", ) - # TODO: This was parsed before maybe add ManimColor(val), but results in circular import background_color = property( lambda self: self._d["background_color"], lambda self, val: self._d.__setitem__("background_color", ManimColor(val)), diff --git a/manim/mobject/geometry/arc.py b/manim/mobject/geometry/arc.py index f1390d3874..bd15d84927 100644 --- a/manim/mobject/geometry/arc.py +++ b/manim/mobject/geometry/arc.py @@ -44,10 +44,10 @@ def construct(self): import itertools import warnings -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING import numpy as np -from typing_extensions import Self, TypeAlias +from typing_extensions import Self from manim.constants import * from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL @@ -70,8 +70,6 @@ def construct(self): from manim.typing import CubicBezierPoints, Point3D, QuadraticBezierPoints, Vector -Angle: TypeAlias = Union[float, np.float64] - class TipableVMobject(VMobject, metaclass=ConvertToOpenGL): """Meant for shared functionality between Arc and Line. diff --git a/manim/mobject/graphing/coordinate_systems.py b/manim/mobject/graphing/coordinate_systems.py index 2e1ac919a4..c2f5744ca8 100644 --- a/manim/mobject/graphing/coordinate_systems.py +++ b/manim/mobject/graphing/coordinate_systems.py @@ -1713,7 +1713,6 @@ def get_T_label( label_color: ParsableManimColor | None = None, triangle_size: float = MED_SMALL_BUFF, triangle_color: ParsableManimColor | None = WHITE, - # TODO: May have to be made a generic but it can be more than just a line. line_func: type[Line] = Line, line_color: ParsableManimColor = YELLOW, ) -> VGroup: diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 331c2ea06a..1afa091cca 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -57,6 +57,7 @@ Point3D, Point3D_Array, Vector, + Vector3, ) from ..animation.animation import Animation @@ -1148,7 +1149,7 @@ def apply_to_family(self, func: Callable[[Mobject], None]) -> None: for mob in self.family_members_with_points(): func(mob) - def shift(self, *vectors: Vector) -> Self: + def shift(self, *vectors: Vector3) -> Self: """Shift by the given vectors. Parameters @@ -1220,14 +1221,14 @@ def construct(self): ) return self - def rotate_about_origin(self, angle: float, axis: Vector = OUT, axes=[]) -> Self: + def rotate_about_origin(self, angle: float, axis: Vector3 = OUT, axes=[]) -> Self: """Rotates the :class:`~.Mobject` about the ORIGIN, which is at [0,0,0].""" return self.rotate(angle, axis, about_point=ORIGIN) def rotate( self, angle: float, - axis: Vector = OUT, + axis: Vector3 = OUT, about_point: Point3D | None = None, **kwargs, ) -> Self: @@ -1238,7 +1239,7 @@ def rotate( ) return self - def flip(self, axis: Vector = UP, **kwargs) -> Self: + def flip(self, axis: Vector3 = UP, **kwargs) -> Self: """Flips/Mirrors an mobject about its center. Examples @@ -1332,7 +1333,7 @@ def R3_func(point): return self.apply_function(R3_func) def wag( - self, direction: Vector = RIGHT, axis: Vector = DOWN, wag_factor: float = 1.0 + self, direction: Vector3 = RIGHT, axis: Vector3 = DOWN, wag_factor: float = 1.0 ) -> Self: for mob in self.family_members_with_points(): alphas = np.dot(mob.points, np.transpose(axis)) @@ -1398,7 +1399,7 @@ def center(self) -> Self: return self def align_on_border( - self, direction: Vector, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER + self, direction: Vector3, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER ) -> Self: """Direction just needs to be a vector pointing towards side or corner in the 2d plane. @@ -1415,24 +1416,24 @@ def align_on_border( return self def to_corner( - self, corner: Vector = DL, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER + self, corner: Vector3 = DL, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER ) -> Self: return self.align_on_border(corner, buff) def to_edge( - self, edge: Vector = LEFT, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER + self, edge: Vector3 = LEFT, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER ) -> Self: return self.align_on_border(edge, buff) def next_to( self, mobject_or_point: Mobject | Point3D, - direction: Vector = RIGHT, + direction: Vector3 = RIGHT, buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, - aligned_edge: Vector = ORIGIN, + aligned_edge: Vector3 = ORIGIN, submobject_to_align: Mobject | None = None, index_of_submobject_to_align: int | None = None, - coor_mask: Vector = np.array([1, 1, 1]), + coor_mask: Vector3 = np.array([1, 1, 1]), ) -> Self: """Move this :class:`~.Mobject` next to another's :class:`~.Mobject` or Point3D. @@ -1624,22 +1625,22 @@ def stretch_to_fit_depth(self, depth: float, **kwargs) -> Self: return self.rescale_to_fit(depth, 2, stretch=True, **kwargs) - def set_coord(self, value, dim: int, direction: Vector = ORIGIN) -> Self: + def set_coord(self, value, dim: int, direction: Vector3 = ORIGIN) -> Self: curr = self.get_coord(dim, direction) shift_vect = np.zeros(self.dim) shift_vect[dim] = value - curr self.shift(shift_vect) return self - def set_x(self, x: float, direction: Vector = ORIGIN) -> Self: + def set_x(self, x: float, direction: Vector3 = ORIGIN) -> Self: """Set x value of the center of the :class:`~.Mobject` (``int`` or ``float``)""" return self.set_coord(x, 0, direction) - def set_y(self, y: float, direction: Vector = ORIGIN) -> Self: + def set_y(self, y: float, direction: Vector3 = ORIGIN) -> Self: """Set y value of the center of the :class:`~.Mobject` (``int`` or ``float``)""" return self.set_coord(y, 1, direction) - def set_z(self, z: float, direction: Vector = ORIGIN) -> Self: + def set_z(self, z: float, direction: Vector3 = ORIGIN) -> Self: """Set z value of the center of the :class:`~.Mobject` (``int`` or ``float``)""" return self.set_coord(z, 2, direction) @@ -1652,8 +1653,8 @@ def space_out_submobjects(self, factor: float = 1.5, **kwargs) -> Self: def move_to( self, point_or_mobject: Point3D | Mobject, - aligned_edge: Vector = ORIGIN, - coor_mask: Vector = np.array([1, 1, 1]), + aligned_edge: Vector3 = ORIGIN, + coor_mask: Vector3 = np.array([1, 1, 1]), ) -> Self: """Move center of the :class:`~.Mobject` to certain Point3D.""" if isinstance(point_or_mobject, Mobject): @@ -1958,7 +1959,7 @@ def get_extremum_along_dim( else: return np.max(values) - def get_critical_point(self, direction: Vector) -> Point3D: + def get_critical_point(self, direction: Vector3) -> Point3D: """Picture a box bounding the :class:`~.Mobject`. Such a box has 9 'critical points': 4 corners, 4 edge center, the center. This returns one of them, along the given direction. @@ -1987,11 +1988,11 @@ def get_critical_point(self, direction: Vector) -> Point3D: # Pseudonyms for more general get_critical_point method - def get_edge_center(self, direction: Vector) -> Point3D: + def get_edge_center(self, direction: Vector3) -> Point3D: """Get edge Point3Ds for certain direction.""" return self.get_critical_point(direction) - def get_corner(self, direction: Vector) -> Point3D: + def get_corner(self, direction: Vector3) -> Point3D: """Get corner Point3Ds for certain direction.""" return self.get_critical_point(direction) @@ -2002,7 +2003,7 @@ def get_center(self) -> Point3D: def get_center_of_mass(self) -> Point3D: return np.apply_along_axis(np.mean, 0, self.get_all_points()) - def get_boundary_point(self, direction: Vector) -> Point3D: + def get_boundary_point(self, direction: Vector3) -> Point3D: all_points = self.get_points_defining_boundary() index = np.argmax(np.dot(all_points, np.array(direction).T)) return all_points[index] @@ -2061,19 +2062,19 @@ def length_over_dim(self, dim: int) -> float: dim, ) - self.reduce_across_dimension(min, dim) - def get_coord(self, dim: int, direction: Vector = ORIGIN): + def get_coord(self, dim: int, direction: Vector3 = ORIGIN): """Meant to generalize ``get_x``, ``get_y`` and ``get_z``""" return self.get_extremum_along_dim(dim=dim, key=direction[dim]) - def get_x(self, direction: Vector = ORIGIN) -> ManimFloat: + def get_x(self, direction: Vector3 = ORIGIN) -> ManimFloat: """Returns x Point3D of the center of the :class:`~.Mobject` as ``float``""" return self.get_coord(0, direction) - def get_y(self, direction: Vector = ORIGIN) -> ManimFloat: + def get_y(self, direction: Vector3 = ORIGIN) -> ManimFloat: """Returns y Point3D of the center of the :class:`~.Mobject` as ``float``""" return self.get_coord(1, direction) - def get_z(self, direction: Vector = ORIGIN) -> ManimFloat: + def get_z(self, direction: Vector3 = ORIGIN) -> ManimFloat: """Returns z Point3D of the center of the :class:`~.Mobject` as ``float``""" return self.get_coord(2, direction) @@ -2144,7 +2145,7 @@ def match_depth(self, mobject: Mobject, **kwargs) -> Self: return self.match_dim_size(mobject, 2, **kwargs) def match_coord( - self, mobject: Mobject, dim: int, direction: Vector = ORIGIN + self, mobject: Mobject, dim: int, direction: Vector3 = ORIGIN ) -> Self: """Match the Point3Ds with the Point3Ds of another :class:`~.Mobject`.""" return self.set_coord( @@ -2168,7 +2169,7 @@ def match_z(self, mobject: Mobject, direction=ORIGIN) -> Self: def align_to( self, mobject_or_point: Mobject | Point3D, - direction: Vector = ORIGIN, + direction: Vector3 = ORIGIN, ) -> Self: """Aligns mobject to another :class:`~.Mobject` in a certain direction. @@ -2223,7 +2224,7 @@ def family_members_with_points(self) -> list[Self]: def arrange( self, - direction: Vector = RIGHT, + direction: Vector3 = RIGHT, buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER, center: bool = True, **kwargs, @@ -2256,7 +2257,7 @@ def arrange_in_grid( rows: int | None = None, cols: int | None = None, buff: float | tuple[float, float] = MED_SMALL_BUFF, - cell_alignment: Vector = ORIGIN, + cell_alignment: Vector3 = ORIGIN, row_alignments: str | None = None, # "ucd" col_alignments: str | None = None, # "lcr" row_heights: Iterable[float | None] | None = None, diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index d0c62d893b..0e9aefc0c3 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -1284,17 +1284,14 @@ def insert_n_curves_to_point_list(self, n: int, points: np.ndarray) -> np.ndarra for _ in range(-diff): ipc[np.argmax(ipc)] -= 1 - new_length = sum(x + 1 for x in ipc) - new_points = np.empty((new_length, nppc, 3)) - i = 0 + new_points = [] for group, n_inserts in zip(bezier_groups, ipc): # What was once a single quadratic curve defined # by "group" will now be broken into n_inserts + 1 # smaller quadratic curves alphas = np.linspace(0, 1, n_inserts + 2) for a1, a2 in zip(alphas, alphas[1:]): - new_points[i] = partial_quadratic_bezier_points(group, a1, a2) - i = i + 1 + new_points += partial_quadratic_bezier_points(group, a1, a2) return np.vstack(new_points) def interpolate(self, mobject1, mobject2, alpha, *args, **kwargs): diff --git a/manim/utils/bezier.py b/manim/utils/bezier.py index d687364abc..205d817e28 100644 --- a/manim/utils/bezier.py +++ b/manim/utils/bezier.py @@ -302,8 +302,11 @@ def integer_interpolate( returned integer and the next one of the list. - For example, if start=0, end=10, alpha=0.46, This - would return (4, 0.6). + Example + ------- + .. code-block:: pycon + >>> integer_interpolate(start=0, end=10, alpha=0.46) + (4, 0.6) """ if alpha >= 1: return (int(end - 1), 1.0)