You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Keyframe interpolation selection: Use switch instead of if
Using switch allows (some) compilers to emit a warning if a possible enum value for the interpolation type has been forgotten. This is not the case now, but might guard against future errors (e.g. adding an interpolation type)
This commit is contained in:
@@ -235,18 +235,18 @@ double Keyframe::GetValue(int64_t index) const {
|
||||
assert(index < candidate->co.X);
|
||||
|
||||
// CONSTANT and LINEAR interpolations are fast to compute!
|
||||
if (candidate->interpolation == CONSTANT) {
|
||||
return predecessor->co.Y;
|
||||
}
|
||||
if (candidate->interpolation == LINEAR) {
|
||||
switch (candidate->interpolation) {
|
||||
case CONSTANT: return predecessor->co.Y;
|
||||
case LINEAR: {
|
||||
double const diff_Y = candidate->co.Y - predecessor->co.Y;
|
||||
double const diff_X = candidate->co.X - predecessor->co.X;
|
||||
double const slope = diff_Y / diff_X;
|
||||
return predecessor->co.Y + slope * (index - predecessor->co.X);
|
||||
}
|
||||
case BEZIER: break;
|
||||
}
|
||||
|
||||
// BEZIER curve!
|
||||
// TODO: use switch instead of if for compiler warning support!
|
||||
assert(candidate->interpolation == BEZIER);
|
||||
|
||||
double const X_diff = candidate->co.X - predecessor->co.X;
|
||||
|
||||
Reference in New Issue
Block a user