Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix OpenGLMobject.get_boundary_point (#4956)

GniLudiob79fb6a94a81
diff --git a/manim/mobject/opengl/opengl_mobject.py b/manim/mobject/opengl/opengl_mobject.py
index 57c7e7c7e..32f073697 100644
--- a/manim/mobject/opengl/opengl_mobject.py
+++ b/manim/mobject/opengl/opengl_mobject.py
@@ -2384,10 +2384,7 @@ class OpenGLMobject:
def get_boundary_point(self, direction: Vector3DLike) -> Point3D:
all_points = self.get_all_points()
- boundary_directions = all_points - self.get_center()
- norms = np.linalg.norm(boundary_directions, axis=1)
- boundary_directions /= np.repeat(norms, 3).reshape((len(norms), 3))
- index = np.argmax(np.dot(boundary_directions, direction))
+ index = np.argmax(np.dot(all_points, direction))
return all_points[index]
def get_continuous_bounding_box_point(self, direction: Vector3DLike) -> Point3D:
diff --git a/tests/opengl/test_opengl_mobject.py b/tests/opengl/test_opengl_mobject.py
index 64b15d651..947448f4c 100644
--- a/tests/opengl/test_opengl_mobject.py
+++ b/tests/opengl/test_opengl_mobject.py
@@ -65,6 +65,15 @@ def test_opengl_mobject_remove(using_opengl_renderer):
assert obj.remove(OpenGLMobject()) is obj
+def test_opengl_mobject_get_boundary_point(using_opengl_renderer):
+ """Test that get_boundary_point returns the furthest point in a direction."""
+ obj = OpenGLMobject().set_points(
+ np.array([[-2.0, 0.0, 0.0], [1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]),
+ )
+
+ np.testing.assert_array_equal(obj.get_boundary_point([1, 0, 0]), [2, 0, 0])
+
+
def test_opengl_mobject_stretch_to_fit_depth(using_opengl_renderer):
"""Test that stretch_to_fit_depth changes the depth dimension."""
obj = OpenGLMobject().set_points(