From 7b2c803b26dd8689d4dd38cdea2f8e020378627a 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)`. PR #4027 added a comment that this should be fixed, but did not fix the issue. The comment is now superfluous. This commit fixes the incorrect code and associated test. --- manim/mobject/mobject.py | 5 +---- tests/module/mobject/graphing/test_number_line.py | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 8557490ed9..5fe08eafc3 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -1776,10 +1776,7 @@ def put_start_and_end_on(self, start: Point3DLike, end: Point3DLike) -> Self: curr_start, curr_end = self.get_start_and_end() curr_vect = curr_end - curr_start if np.all(curr_vect == 0): - # TODO: this looks broken. It makes self.points a Point3D instead - # of a Point3D_Array. However, modifying this breaks some tests - # where this is currently expected. - self.points = np.array(start) + self.points = np.array([start]) return self target_vect = np.asarray(end) - np.asarray(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))