From c44a33a9ebaf2b9d50706a28ccd69d0d872cde5c Mon Sep 17 00:00:00 2001 From: Irvanal Haq Date: Mon, 17 Mar 2025 21:58:30 +0700 Subject: [PATCH 1/2] Fix Line failing with buff and path_arc - make copy of vmobject.points if necessary --- manim/mobject/types/vectorized_mobject.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 321fe4287b..7734b86a08 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1938,24 +1938,32 @@ def pointwise_become_partial( upper_residue, ) else: + # Copy points if self.points is vmobject.points before setting + # self.points = np.empty(...) to avoid in-place modification + vmobject_points = ( + vmobject.points.copy() + if self.points is vmobject.points + else vmobject.points + ) + # Allocate space for (upper_index-lower_index+1) Bézier curves. self.points = np.empty((nppc * (upper_index - lower_index + 1), self.dim)) # Look at the "lower_index"-th Bezier curve and select its part from # t=lower_residue to t=1. This is the first curve in self.points. self.points[:nppc] = partial_bezier_points( - vmobject.points[nppc * lower_index : nppc * (lower_index + 1)], + vmobject_points[nppc * lower_index : nppc * (lower_index + 1)], lower_residue, 1, ) # If there are more curves between the "lower_index"-th and the # "upper_index"-th Béziers, add them all to self.points. - self.points[nppc:-nppc] = vmobject.points[ + self.points[nppc:-nppc] = vmobject_points[ nppc * (lower_index + 1) : nppc * upper_index ] # Look at the "upper_index"-th Bézier curve and select its part from # t=0 to t=upper_residue. This is the last curve in self.points. self.points[-nppc:] = partial_bezier_points( - vmobject.points[nppc * upper_index : nppc * (upper_index + 1)], + vmobject_points[nppc * upper_index : nppc * (upper_index + 1)], 0, upper_residue, ) From 27741fead00674a4271952d4cb45dd5dd1dfdb58 Mon Sep 17 00:00:00 2001 From: Irvanal Haq Date: Sun, 30 Mar 2025 06:52:22 +0700 Subject: [PATCH 2/2] change self to self.copy() in Line, and remove the previous change in pointwise_become_partial() --- manim/mobject/geometry/line.py | 2 +- manim/mobject/types/vectorized_mobject.py | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.py index be6c3a77ba..8c3fb5c3ef 100644 --- a/manim/mobject/geometry/line.py +++ b/manim/mobject/geometry/line.py @@ -133,7 +133,7 @@ def _account_for_buff(self, buff: float) -> None: if length < 2 * buff: return buff_proportion = buff / length - self.pointwise_become_partial(self, buff_proportion, 1 - buff_proportion) + self.pointwise_become_partial(self.copy(), buff_proportion, 1 - buff_proportion) return def _set_start_and_end_attrs( diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 7734b86a08..321fe4287b 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1938,32 +1938,24 @@ def pointwise_become_partial( upper_residue, ) else: - # Copy points if self.points is vmobject.points before setting - # self.points = np.empty(...) to avoid in-place modification - vmobject_points = ( - vmobject.points.copy() - if self.points is vmobject.points - else vmobject.points - ) - # Allocate space for (upper_index-lower_index+1) Bézier curves. self.points = np.empty((nppc * (upper_index - lower_index + 1), self.dim)) # Look at the "lower_index"-th Bezier curve and select its part from # t=lower_residue to t=1. This is the first curve in self.points. self.points[:nppc] = partial_bezier_points( - vmobject_points[nppc * lower_index : nppc * (lower_index + 1)], + vmobject.points[nppc * lower_index : nppc * (lower_index + 1)], lower_residue, 1, ) # If there are more curves between the "lower_index"-th and the # "upper_index"-th Béziers, add them all to self.points. - self.points[nppc:-nppc] = vmobject_points[ + self.points[nppc:-nppc] = vmobject.points[ nppc * (lower_index + 1) : nppc * upper_index ] # Look at the "upper_index"-th Bézier curve and select its part from # t=0 to t=upper_residue. This is the last curve in self.points. self.points[-nppc:] = partial_bezier_points( - vmobject_points[nppc * upper_index : nppc * (upper_index + 1)], + vmobject.points[nppc * upper_index : nppc * (upper_index + 1)], 0, upper_residue, )