comparison core/Utilities.cpp @ 0:8a575ba3ab52

Initial commit.
author andrewm
date Fri, 31 Oct 2014 19:10:17 +0100
parents
children 579c86316008
comparison
equal deleted inserted replaced
-1:000000000000 0:8a575ba3ab52
1 /*
2 * Utilities.cpp
3 *
4 * Created on: Oct 27, 2014
5 * Author: parallels
6 */
7
8 #include "../include/Utilities.h"
9
10 // map()
11 //
12 // Scale an input value from one range to another. Works like its Wiring language equivalent.
13 // x is the value to scale; in_min and in_max are the input range; out_min and out_max
14 // are the output range.
15
16 float map(float x, float in_min, float in_max, float out_min, float out_max)
17 {
18 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
19 }
20
21 // constrain()
22 //
23 // Clips an input value to be between two end points
24 // x is the value to constrain; min_val and max_val are the range
25
26 float constrain(float x, float min_val, float max_val)
27 {
28 if(x < min_val) return min_val;
29 if(x > max_val) return max_val;
30 return x;
31 }