Skip to content

Commit

Permalink
Fix incorrect assignment in Mobject.put_start_and_end_on
Browse files Browse the repository at this point in the history
PR ManimCommunity#3718 changed the behavior of `Mobject.put_start_and_end_on` when
`start == end`, however the assigment to `self.points` was
incorrect. The existing code assigned the Point3D directly to
`self.points`, that then becomes an array with shape `(3,)`, while
instead it should really have shape `(1, 3)`.

This commit fixes the incorrect code and associated test.
  • Loading branch information
dark committed Nov 13, 2024
1 parent a21a5e5 commit 4849bdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ 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):
self.points = start
self.points = np.array([start])
return self
target_vect = np.array(end) - np.array(start)
axis = (
Expand Down
9 changes: 5 additions & 4 deletions tests/module/mobject/graphing/test_number_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from manim import DashedLine, NumberLine
from manim import Line, NumberLine
from manim.mobject.text.numbers import Integer


Expand Down Expand Up @@ -126,7 +126,8 @@ def test_point_to_number():


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]))
point = [1.0, 2.0, 3.0]
line = Line(point, point)
line.put_start_and_end_on(point, point)

np.testing.assert_array_equal(np.round(np.zeros(3), 4), np.round(line.points, 4))
np.testing.assert_array_equal(np.round([point], 4), np.round(line.points, 4))

0 comments on commit 4849bdd

Please sign in to comment.