From a67fb9555cc4bd84f95b1c2ce0f6144c25621ccd Mon Sep 17 00:00:00 2001 From: Daniel Jour Date: Mon, 25 Nov 2019 10:37:51 +0100 Subject: [PATCH] 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) --- src/KeyFrame.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index 7e4daeab..8f89d1da 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -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;