[DRAFT] New ManimBezier
class, and new utils/linear_interpolation.py
file
#3336
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?
[DRAFT; SUBJECT TO CHANGES]
As discussed in the Discord channel, I propose taking all of the Bézier-related methods and functions, which are scattered all around the code (in
utils/bezier.py
,VMobject
,Mobject
,OpenGLVMobject
,OpenGLMobject
, etc) and gathering them all into a single class:ManimBezier
(name subject to change, still wondering how to avoid ambiguity with theCubicBezier
mobject).This class has two subclasses,
ManimQuadraticBezier
(intended forOpenGLVMobject
andOpenGLMobject
, because OpenGL works better with quadratic Béziers) andManimCubicBezier
(intended forVMobject
andMobject
, which currently use Cairo which requires cubic Béziers). Both of these subclasses attempt to implement the same methods, but in a different way depending on the degree of the Bézier.I also moved the
interpolate
,integer_interpolate
,mid
,inverse_interpolate
andmatch_interpolate
functions (defined inutils/bezier.py
) into a new file,utils/linear_interpolation.py
, to separate them from the other Bézier methods. The reason is that these linear interpolations are ubiquitous all around the source code, and their use cases are much broader than with just "linear Béziers", so I thought they didnt' really belong that much among the other Bézier methods.CURRENTLY THIS IS ONLY A DRAFT. This is far from being ready for review: there are still many, many changes I need to apply, methods in Mobjects to redirect to
ManimBezier
, functions to optimize, and all of that. I only publish my current changes so that everyone else can see what I'm planning to do. Any suggestions will be gratefully accepted!Motivation and Explanation: Why and how do your changes improve the library?
ManimBezier
,ManimQuadraticBezier
andManimCubicBezier
for convenience.ManimBezier
is that Cairo Mobjects use instances ofManimCubicBezier
, and OpenGL Mobjects use instances ofManimQuadraticBezier
. Both of these subclasses implement the same methods, but in a different way depending on the degree of the curve. In this way,ManimBezier
sort of exposes an API to Mobjects: they can just call the Bézier methods from their respectiveManimBezier
and they do not have to worry about the underlying implementation.split_quadratic_bezier
vs. an hypotheticalsplit_cubic_bezier
, orsubdivide_quadratic_bezier
vs. an hypotheticalsubdivide_cubic_bezier
: they would be just calledsplit_bezier
andsubdivide_bezier
.VMobject
and quadratic Bézier logic inOpenGLMobject
, as happens in methods such asVMobject.set_anchors_and_handles
, where there are 4 hardcoded parameters rather than a variable amount of parameters.Currently, I'm also adding the changes I proposed in #3281 and #3292.
Links to added or changed documentation pages
Further Information and Comments
Reviewer Checklist