Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Oct 29, 2023
1 parent 672b0e3 commit 84c9cdc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
1 change: 0 additions & 1 deletion manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 2 additions & 4 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/graphing/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
59 changes: 30 additions & 29 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Point3D,
Point3D_Array,
Vector,
Vector3,
)

from ..animation.animation import Animation
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 84c9cdc

Please sign in to comment.