From 375e536f96f9c23c61dd76273cffad3540231480 Mon Sep 17 00:00:00 2001 From: MontroyJosh <122334909+MontroyJosh@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:32:47 -0400 Subject: [PATCH 1/2] fix put_start_and_end_on() at the same point --- manim/mobject/mobject.py | 3 ++- tests/module/mobject/graphing/test_number_line.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 73b1920ff6..40bcd46336 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -1734,7 +1734,8 @@ def put_start_and_end_on(self, start: Point3D, end: Point3D) -> Self: curr_start, curr_end = self.get_start_and_end() curr_vect = curr_end - curr_start if np.all(curr_vect == 0): - raise Exception("Cannot position endpoints of closed loop") + self.points = start + return self target_vect = np.array(end) - np.array(start) axis = ( normalize(np.cross(curr_vect, target_vect)) diff --git a/tests/module/mobject/graphing/test_number_line.py b/tests/module/mobject/graphing/test_number_line.py index 3fededfab8..216e1b170c 100644 --- a/tests/module/mobject/graphing/test_number_line.py +++ b/tests/module/mobject/graphing/test_number_line.py @@ -3,6 +3,7 @@ import numpy as np from manim import NumberLine +from manim import DashedLine from manim.mobject.text.numbers import Integer @@ -121,3 +122,9 @@ def test_point_to_number(): np.testing.assert_array_equal(np.round(num_1, 4), np.round(expected, 4)) np.testing.assert_array_equal(np.round(num_2, 4), np.round(expected, 4)) np.testing.assert_array_equal(np.round(num_3, 4), np.round(expected, 4)) + +def test_start_and_end_at_same_point(): + line = DashedLine(np.zeros(3),np.zeros(3)) + line.put_start_and_end_on(np.zeros(3),np.array([0,0,0])) + + np.testing.assert_array_equal(np.round(np.zeros(3), 4), np.round(line.points, 4)) \ No newline at end of file From 19db2f5b4403d642323ec7363a8bb559f49b8176 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:18:19 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/module/mobject/graphing/test_number_line.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/module/mobject/graphing/test_number_line.py b/tests/module/mobject/graphing/test_number_line.py index 216e1b170c..56cd7267ed 100644 --- a/tests/module/mobject/graphing/test_number_line.py +++ b/tests/module/mobject/graphing/test_number_line.py @@ -2,8 +2,7 @@ import numpy as np -from manim import NumberLine -from manim import DashedLine +from manim import DashedLine, NumberLine from manim.mobject.text.numbers import Integer @@ -123,8 +122,9 @@ def test_point_to_number(): np.testing.assert_array_equal(np.round(num_2, 4), np.round(expected, 4)) np.testing.assert_array_equal(np.round(num_3, 4), np.round(expected, 4)) + def test_start_and_end_at_same_point(): - line = DashedLine(np.zeros(3),np.zeros(3)) - line.put_start_and_end_on(np.zeros(3),np.array([0,0,0])) - - np.testing.assert_array_equal(np.round(np.zeros(3), 4), np.round(line.points, 4)) \ No newline at end of file + line = DashedLine(np.zeros(3), np.zeros(3)) + line.put_start_and_end_on(np.zeros(3), np.array([0, 0, 0])) + + np.testing.assert_array_equal(np.round(np.zeros(3), 4), np.round(line.points, 4))