Skip to content

Commit 0fd16b8

Browse files
Fixed Mobject.put_start_and_end_on with same start and end point (#3718)
* fix put_start_and_end_on() at the same point * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 563810a commit 0fd16b8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

manim/mobject/mobject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,8 @@ def put_start_and_end_on(self, start: Point3D, end: Point3D) -> Self:
17341734
curr_start, curr_end = self.get_start_and_end()
17351735
curr_vect = curr_end - curr_start
17361736
if np.all(curr_vect == 0):
1737-
raise Exception("Cannot position endpoints of closed loop")
1737+
self.points = start
1738+
return self
17381739
target_vect = np.array(end) - np.array(start)
17391740
axis = (
17401741
normalize(np.cross(curr_vect, target_vect))

tests/module/mobject/graphing/test_number_line.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import numpy as np
44

5-
from manim import NumberLine
5+
from manim import DashedLine, NumberLine
66
from manim.mobject.text.numbers import Integer
77

88

@@ -121,3 +121,10 @@ def test_point_to_number():
121121
np.testing.assert_array_equal(np.round(num_1, 4), np.round(expected, 4))
122122
np.testing.assert_array_equal(np.round(num_2, 4), np.round(expected, 4))
123123
np.testing.assert_array_equal(np.round(num_3, 4), np.round(expected, 4))
124+
125+
126+
def test_start_and_end_at_same_point():
127+
line = DashedLine(np.zeros(3), np.zeros(3))
128+
line.put_start_and_end_on(np.zeros(3), np.array([0, 0, 0]))
129+
130+
np.testing.assert_array_equal(np.round(np.zeros(3), 4), np.round(line.points, 4))

0 commit comments

Comments
 (0)