forked from RobTillaart/FastMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastMap.h
More file actions
57 lines (40 loc) · 1.34 KB
/
FastMap.h
File metadata and controls
57 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
//
// FILE: FastMap.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.0
// PURPOSE: class with fast map function - library for Arduino
// URL: https://github.com/RobTillaart/FastMap
#include "Arduino.h"
#define FASTMAP_LIB_VERSION (F("0.4.0"))
class FastMap
{
public:
FastMap();
bool init(float in_min, float in_max, float out_min, float out_max);
float inline map (const float value) { return _base + value * _factor; }
float inline back (const float value) { return _backbase + value * _backfactor; }
float constrainedMap(const float value);
float lowerConstrainedMap(const float value);
float upperConstrainedMap(const float value);
private:
float _in_min, _in_max, _out_min, _out_max;
float _factor, _base;
float _backfactor, _backbase;
};
class FastMapDouble
{
public:
FastMapDouble();
bool init(double in_min, double in_max, double out_min, double out_max);
double inline map (const double value) { return _base + value * _factor; }
double inline back (const double value) { return _backbase + value * _backfactor; }
double constrainedMap(const double value);
double lowerConstrainedMap(const double value);
double upperConstrainedMap(const double value);
private:
double _in_min, _in_max, _out_min, _out_max;
double _factor, _base;
double _backfactor, _backbase;
};
// -- END OF FILE --