Skip to content

Commit

Permalink
Fix VMobject.add_points_as_corners() to return self and safely handle…
Browse files Browse the repository at this point in the history
… case where no points are passed
  • Loading branch information
chopan050 committed Jan 4, 2025
1 parent 17d4a7f commit e996c62
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def close_path(self) -> None:
if not self.is_closed():
self.add_line_to(self.get_subpaths()[-1][0])

def add_points_as_corners(self, points: Point3DLike_Array) -> Point3D_Array:
def add_points_as_corners(self, points: Point3DLike_Array) -> Self:
"""Append multiple straight lines at the end of
:attr:`VMobject.points`, which connect the given ``points`` in order
starting from the end of the current path. These ``points`` would be
Expand All @@ -1058,10 +1058,14 @@ def add_points_as_corners(self, points: Point3DLike_Array) -> Point3D_Array:
path.
"""
points = np.asarray(points).reshape(-1, self.dim)
num_points = points.shape[0]
if num_points == 0:
return self

if self.has_new_path_started():
# Pop the last point from self.points and
# add it to start_corners
start_corners = np.empty((len(points), self.dim))
start_corners = np.empty((num_points, self.dim))
start_corners[0] = self.points[-1]
start_corners[1:] = points[:-1]
end_corners = points
Expand All @@ -1078,8 +1082,7 @@ def add_points_as_corners(self, points: Point3DLike_Array) -> Point3D_Array:
new_points[i::nppcc] = interpolate(start_corners, end_corners, t)

self.append_points(new_points)
# TODO: shouldn't this method return self instead of points?
return points
return self

def set_points_as_corners(self, points: Point3DLike_Array) -> Self:
"""Given an array of points, set them as corners of the
Expand Down

0 comments on commit e996c62

Please sign in to comment.