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
Diff: Math/Math.cpp
- Revision:
- 29:d59fbe128d1f
- Parent:
- 28:e09b7ac11dea
--- a/Math/Math.cpp Fri Apr 12 20:53:00 2019 +0000
+++ b/Math/Math.cpp Sat Apr 13 08:33:49 2019 +0000
@@ -1,10 +1,27 @@
#include "Math.h"
int Math::lerp(int a, int b) {
- const double t = 0.6;
- return (b * t) + (a * (1 - t)) + 0.5;
+ return lerp(a, b, 0.6);
}
int Math::lerp(int a, int b, double t) {
- return (b * t) + (a * (1 - t)) + 0.5;
+ 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;
+ }
+ }
}
\ No newline at end of file
