Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix scaling and family assembly

Devin Neal835311cf87cd
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.py
index f84ccc682..c855b6b56 100644
--- a/manim/mobject/opengl_mobject.py
+++ b/manim/mobject/opengl_mobject.py
@@ -134,7 +134,101 @@ class OpenGLMobject:
# Borrowed from https://github.com/ManimCommunity/manim/
return _AnimationBuilder(self)
+ @property
+ def width(self):
+ """The width of the mobject.
+
+ Returns
+ -------
+ :class:`float`
+
+ Examples
+ --------
+ .. manim:: WidthExample
+
+ class WidthExample(Scene):
+ def construct(self):
+ decimal = DecimalNumber().to_edge(UP)
+ rect = Rectangle(color=BLUE)
+ rect_copy = rect.copy().set_stroke(GRAY, opacity=0.5)
+
+ decimal.add_updater(lambda d: d.set_value(rect.width))
+
+ self.add(rect_copy, rect, decimal)
+ self.play(rect.animate.set(width=7))
+ self.wait()
+
+ See also
+ --------
+ :meth:`length_over_dim`
+
+ """
+
+ # Get the length across the X dimension
+ return self.length_over_dim(0)
+
# Only these methods should directly affect points
+ @width.setter
+ def width(self, value):
+ self.rescale_to_fit(value, 0, stretch=False)
+
+ @property
+ def height(self):
+ """The height of the mobject.
+
+ Returns
+ -------
+ :class:`float`
+
+ Examples
+ --------
+ .. manim:: HeightExample
+
+ class HeightExample(Scene):
+ def construct(self):
+ decimal = DecimalNumber().to_edge(UP)
+ rect = Rectangle(color=BLUE)
+ rect_copy = rect.copy().set_stroke(GRAY, opacity=0.5)
+
+ decimal.add_updater(lambda d: d.set_value(rect.height))
+
+ self.add(rect_copy, rect, decimal)
+ self.play(rect.animate.set(height=5))
+ self.wait()
+
+ See also
+ --------
+ :meth:`length_over_dim`
+
+ """
+
+ # Get the length across the Y dimension
+ return self.length_over_dim(1)
+
+ @height.setter
+ def height(self, value):
+ self.rescale_to_fit(value, 1, stretch=False)
+
+ @property
+ def depth(self):
+ """The depth of the mobject.
+
+ Returns
+ -------
+ :class:`float`
+
+ See also
+ --------
+ :meth:`length_over_dim`
+
+ """
+
+ # Get the length across the Z dimension
+ return self.length_over_dim(2)
+
+ @depth.setter
+ def depth(self, value):
+ self.rescale_to_fit(value, 2, stretch=False)
def resize_points(self, new_length, resize_func=resize_array):
if new_length != len(self.data["points"]):
diff --git a/manim/mobject/svg/opengl_tex_mobject.py b/manim/mobject/svg/opengl_tex_mobject.py
index 9987a1e86..4371b6664 100644
--- a/manim/mobject/svg/opengl_tex_mobject.py
+++ b/manim/mobject/svg/opengl_tex_mobject.py
@@ -442,13 +442,16 @@ class OpenGLMathTex(OpenGLSingleStringMathTex):
# part of the whole MathTex to be a VectorizedPoint
# positioned in the right part of the MathTex
sub_tex_mob.submobjects = [OpenGLVectorizedPoint()]
+ sub_tex_mob.assemble_family()
last_submob_index = min(curr_index, len(self.submobjects) - 1)
sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)
else:
sub_tex_mob.submobjects = self.submobjects[curr_index:new_index]
+ sub_tex_mob.assemble_family()
new_submobjects.append(sub_tex_mob)
curr_index = new_index
self.submobjects = new_submobjects
+ self.assemble_family()
return self
def get_parts_by_tex(self, tex, substring=True, case_sensitive=True):