Skip to content

Commit 4716331

Browse files
authored
Fix bugs in OpenGLMobject class and Fix ApplyMethod to support OpenGLMobject (#1115)
* fix undefind variables and convert Mobject to OpenGLMobject * fix assert with OpenGLMobject * refactor
1 parent 83be833 commit 4716331

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

manim/animation/transform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..animation.animation import Animation
3232
from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, OUT
3333
from ..mobject.mobject import Group, Mobject
34+
from ..mobject.opengl_mobject import OpenGLMobject
3435
from ..utils.paths import path_along_arc, straight_path
3536
from ..utils.rate_functions import smooth, squish_rate_func
3637

@@ -217,7 +218,7 @@ def check_validity_of_input(self, method: types.MethodType) -> None:
217218
"Whoops, looks like you accidentally invoked "
218219
"the method you want to animate"
219220
)
220-
assert isinstance(method.__self__, Mobject)
221+
assert isinstance(method.__self__, (Mobject, OpenGLMobject))
221222

222223
def create_target(self) -> Mobject:
223224
method = self.method

manim/mobject/opengl_mobject.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111

12+
from .. import config
1213
from ..constants import *
1314

1415
from ..utils.color import color_gradient
@@ -336,7 +337,7 @@ def digest_mobject_attrs(self):
336337
in the submobjects list.
337338
"""
338339
mobject_attrs = [
339-
x for x in list(self.__dict__.values()) if isinstance(x, Mobject)
340+
x for x in list(self.__dict__.values()) if isinstance(x, OpenGLMobject)
340341
]
341342
self.set_submobjects(list_update(self.submobjects, mobject_attrs))
342343
return self
@@ -694,7 +695,11 @@ def align_on_border(self, direction, buff=DEFAULT_MOBJECT_TO_EDGE_BUFFER):
694695
Direction just needs to be a vector pointing towards side or
695696
corner in the 2d plane.
696697
"""
697-
target_point = np.sign(direction) * (FRAME_X_RADIUS, FRAME_Y_RADIUS, 0)
698+
target_point = np.sign(direction) * (
699+
config["frame_x_radius"],
700+
config["frame_y_radius"],
701+
0,
702+
)
698703
point_to_align = self.get_bounding_box_point(direction)
699704
shift_val = target_point - point_to_align - buff * np.array(direction)
700705
shift_val = shift_val * abs(np.sign(direction))
@@ -717,7 +722,7 @@ def next_to(
717722
index_of_submobject_to_align=None,
718723
coor_mask=np.array([1, 1, 1]),
719724
):
720-
if isinstance(mobject_or_point, Mobject):
725+
if isinstance(mobject_or_point, OpenGLMobject):
721726
mob = mobject_or_point
722727
if index_of_submobject_to_align is not None:
723728
target_aligner = mob[index_of_submobject_to_align]
@@ -739,7 +744,7 @@ def next_to(
739744
return self
740745

741746
def shift_onto_screen(self, **kwargs):
742-
space_lengths = [FRAME_X_RADIUS, FRAME_Y_RADIUS]
747+
space_lengths = [config["frame_x_radius"], config["frame_y_radius"]]
743748
for vect in UP, DOWN, LEFT, RIGHT:
744749
dim = np.argmax(np.abs(vect))
745750
buff = kwargs.get("buff", DEFAULT_MOBJECT_TO_EDGE_BUFFER)
@@ -750,13 +755,13 @@ def shift_onto_screen(self, **kwargs):
750755
return self
751756

752757
def is_off_screen(self):
753-
if self.get_left()[0] > FRAME_X_RADIUS:
758+
if self.get_left()[0] > config["frame_x_radius"]:
754759
return True
755-
if self.get_right()[0] < -FRAME_X_RADIUS:
760+
if self.get_right()[0] < -config["frame_x_radius"]:
756761
return True
757-
if self.get_bottom()[1] > FRAME_Y_RADIUS:
762+
if self.get_bottom()[1] > config["frame_y_radius"]:
758763
return True
759-
if self.get_top()[1] < -FRAME_Y_RADIUS:
764+
if self.get_top()[1] < -config["frame_y_radius"]:
760765
return True
761766
return False
762767

@@ -1086,7 +1091,7 @@ def get_pieces(self, n_pieces):
10861091
template = self.copy()
10871092
template.set_submobjects([])
10881093
alphas = np.linspace(0, 1, n_pieces + 1)
1089-
return Group(
1094+
return OpenGLGroup(
10901095
*[
10911096
template.copy().pointwise_become_partial(self, a1, a2)
10921097
for a1, a2 in zip(alphas[:-1], alphas[1:])
@@ -1141,7 +1146,7 @@ def align_to(self, mobject_or_point, direction=ORIGIN):
11411146
horizontally so that it's center is directly above/below
11421147
the center of mob2
11431148
"""
1144-
if isinstance(mobject_or_point, Mobject):
1149+
if isinstance(mobject_or_point, OpenGLMobject):
11451150
point = mobject_or_point.get_bounding_box_point(direction)
11461151
else:
11471152
point = mobject_or_point

0 commit comments

Comments
 (0)