Rewrite VMobject
subpath getters by calculating split indices
#3759
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
Related PR: #3292
Taking inspiration from ManimGL, I added new methods
VMobject.get_subpath_split_indices()
andVMobject.get_subpath_split_indices_from_points()
, which instead of explicitly obtaining a Python list of subpaths, it obtains an(n_subpaths, 2)
ndarray of indices indicating where every subpath starts and ends.These methods also accept parameters
n_dims
(which allows us to choose between 2D or 3D point comparison) andstrip_null_end_curves
(useful in a future PR forVMobject.align_points()
, where the null end curves at every subpath must be removed as a fix to certain bug).Then I rewrote
VMobject.get_subpaths_from_points()
andVMobject.gen_subpaths_from_points_2d()
to use this new methodVMobject.get_subpath_split_indices_from_points()
.TODO: vectorize
VMobject.consider_points_equals()
in a subsequent PR for extra optimization inVMobject.get_subpath_split_indices_from_points()
.Motivation and Explanation: Why and how do your changes improve the library?
Methods like
VMobject.change_anchor_mode()
andVMobject.align_points()
could benefit from calculating split indices, since they allow for things such as calculating the lengths of the subpaths in a vectorized fashion, which then allows for creating a single NumPy empty array with the right length from the beginning, rather than appending into a NumPy array.Links to added or changed documentation pages
Further Information and Comments
Reviewer Checklist