From 4849bddf1713d7274f016b8f75297a4e236ab62c Mon Sep 17 00:00:00 2001 From: Marco Leogrande Date: Sun, 10 Nov 2024 15:29:55 -0800 Subject: [PATCH] Fix incorrect assignment in Mobject.put_start_and_end_on PR #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. --- manim/mobject/mobject.py | 2 +- tests/module/mobject/graphing/test_number_line.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 0359f66045..16e12d31e7 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -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 = ( diff --git a/tests/module/mobject/graphing/test_number_line.py b/tests/module/mobject/graphing/test_number_line.py index 1f0f7c343c..786d37aaff 100644 --- a/tests/module/mobject/graphing/test_number_line.py +++ b/tests/module/mobject/graphing/test_number_line.py @@ -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 @@ -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))