-
-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathMathUtils.cpp
More file actions
24 lines (20 loc) · 804 Bytes
/
MathUtils.cpp
File metadata and controls
24 lines (20 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*---------------------------------------------------------*\
| MathUtils.cpp |
| |
| Math utility functions |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <math.h>
#include "MathUtils.h"
int MathUtils::IntInterpolate(int y0, int y1, int x0, int x1, int x)
{
if(x1 == x0)
return y0;
if(y0 == y1)
return y0;
double t = (double)(x - x0) / (double)(x1 - x0);
double y = y0 * (1.0 - t) + y1 * t;
return (int)round(y);
}