Update to get_subpath_end_indices_from_points

This commit is contained in:
Grant Sanderson 2023-01-13 20:35:54 -08:00
parent 42909a94ac
commit 12c3af9647

View file

@ -690,13 +690,16 @@ class VMobject(Mobject):
return self.get_bezier_tuples_from_points(self.get_points())
def get_subpath_end_indices_from_points(self, points: Vect3Array):
# Find internal end points
a0, h, a1 = points[0:-1:2], points[1::2], points[2::2]
atol = self.tolerance_for_point_equality
is_end = (a0 == h).all(1) & (np.linalg.norm(h - a1, axis=1) > atol)
# Mark the final point as an end
is_end = np.hstack([is_end, [True]])
return np.arange(0, len(points), 2)[is_end]
a0, h, a1 = points[0:-1:2], points[1::2], points[2::2]
# An anchor point is considered the end of a path
# if its following handle is sitting on top of it.
# To disambiguate this from cases with many null
# curves in a row, we also check that the following
# anchor is genuinely distinct
is_end = (a0 == h).all(1) & (abs(h - a1) > atol).any(1)
inner_ends = (2 * n for n, end in enumerate(is_end) if end)
return np.array([*inner_ends, len(points) - 1])
def get_subpath_end_indices(self):
return self.get_subpath_end_indices_from_points(self.get_points())