Skip to content

Commit a67fb95

Browse files
committed
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)
1 parent b546b6a commit a67fb95

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/KeyFrame.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,18 @@ double Keyframe::GetValue(int64_t index) const {
235235
assert(index < candidate->co.X);
236236

237237
// CONSTANT and LINEAR interpolations are fast to compute!
238-
if (candidate->interpolation == CONSTANT) {
239-
return predecessor->co.Y;
240-
}
241-
if (candidate->interpolation == LINEAR) {
238+
switch (candidate->interpolation) {
239+
case CONSTANT: return predecessor->co.Y;
240+
case LINEAR: {
242241
double const diff_Y = candidate->co.Y - predecessor->co.Y;
243242
double const diff_X = candidate->co.X - predecessor->co.X;
244243
double const slope = diff_Y / diff_X;
245244
return predecessor->co.Y + slope * (index - predecessor->co.X);
246245
}
246+
case BEZIER: break;
247+
}
247248

248249
// BEZIER curve!
249-
// TODO: use switch instead of if for compiler warning support!
250250
assert(candidate->interpolation == BEZIER);
251251

252252
double const X_diff = candidate->co.X - predecessor->co.X;

0 commit comments

Comments
 (0)