Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17ajf by
Math/Math.cpp
- Committer:
- el17ajf
- Date:
- 2019-04-13
- Revision:
- 29:d59fbe128d1f
- Parent:
- 28:e09b7ac11dea
File content as of revision 29:d59fbe128d1f:
#include "Math.h"
int Math::lerp(int a, int b) {
return lerp(a, b, 0.6);
}
int Math::lerp(int a, int b, double t) {
if (a < b) {
int lerped = (a * (1 - t)) + (b * t) + 0.5;
if (lerped > a + 1) {
return lerped;
} else if (a + 1 <= b) {
return a + 1;
} else {
return b;
}
} else {
int lerped = (a * (1 - t)) + (b * t);
if (lerped < a - 1) {
return lerped;
} else if (a - 1 >= b) {
return a - 1;
} else {
return b;
}
}
}
