Skip to content

Commit d6e3aaf

Browse files
committed
Fix align_points() when end null curves are actually stripped
1 parent 403c2bf commit d6e3aaf

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

manim/mobject/types/vectorized_mobject.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,15 +1293,13 @@ def get_subpath_split_indices_from_points(
12931293
n_dims: int = 3,
12941294
strip_null_end_curves: bool = False,
12951295
) -> npt.NDArray[ManimInt]:
1296+
points = np.asarray(points)
1297+
12961298
nppcc = self.n_points_per_cubic_curve
12971299
starts = points[::nppcc]
12981300
ends = points[nppcc - 1 :: nppcc]
12991301
# This ensures that there are no more starts than ends.
1300-
# TODO: ends.shape[0] would be more efficient, but some test cases
1301-
# regarding Flash and ShowPassingFlash expect a Python list instead of
1302-
# an ndarray, so ends.shape[0] breaks those test cases.
1303-
# Fix these inconsistencies.
1304-
n_curves = len(ends)
1302+
n_curves = ends.shape[0]
13051303
starts = starts[:n_curves]
13061304

13071305
# Zero curves case: if nothing was done to handle this, the statement
@@ -1910,16 +1908,34 @@ def align_points(self, vmobject: VMobject) -> Self:
19101908
self_new_path[max_start:max_end] = self_subpath
19111909
vmob_new_path[max_start:max_end] = vmob_subpath
19121910

1911+
# Because strip_null_end_curves=True, maybe the old points have to
1912+
# be cut earlier. Extract the end points from the split indices
1913+
self_end, vmob_end = self_split_i[-1, 1], vmob_split_i[-1, 1]
1914+
19131915
# If any of the original paths had more subpaths than the other,
19141916
# add them to the corresponding new path and complete the other
19151917
# one by appending its last anchor as many times as necessary.
19161918
if self_n_subpaths < vmob_n_subpaths:
19171919
vmob_start = vmob_split_i[least_n_subpaths, 0]
19181920
self_new_path[max_n_points:] = self_new_path[max_n_points - 1]
1919-
vmob_new_path[max_n_points:] = vmobject.points[vmob_start:]
1921+
vmob_new_path[max_n_points:] = vmobject.points[vmob_start:vmob_end]
19201922
elif self_n_subpaths > vmob_n_subpaths:
19211923
self_start = self_split_i[least_n_subpaths, 0]
1922-
self_new_path[max_n_points:] = self.points[self_start:]
1924+
try:
1925+
self_new_path[max_n_points:] = self.points[self_start:self_end]
1926+
except Exception as e:
1927+
print("SELF SHAPE:", self.points.shape)
1928+
print("VMOB SHAPE:", vmobject.points.shape)
1929+
print("SELF SUBSPLIT:", self_split_i)
1930+
print("VMOB SUBSPLIT:", vmob_split_i)
1931+
print("MAX SUBSPLIT:", max_split_i)
1932+
print("Least subpaths:", least_n_subpaths)
1933+
print("Max points:", max_n_points)
1934+
print("Remainder points:", remainder_n_points)
1935+
print("Self start:", self_start)
1936+
print("SELF NEW SHAPE:", self_new_path.shape)
1937+
print("VMOB NEW SHAPE:", vmob_new_path.shape)
1938+
raise e
19231939
vmob_new_path[max_n_points:] = vmob_new_path[max_n_points - 1]
19241940

19251941
self.set_points(self_new_path)

0 commit comments

Comments
 (0)