A library that maps one range onto another range.
Map.cpp@2:ac294c579449, 2019-12-27 (annotated)
- Committer:
- drorbalbul
- Date:
- Fri Dec 27 17:52:39 2019 +0000
- Revision:
- 2:ac294c579449
- Parent:
- 1:dad975e2e150
cantran for noam
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kerneels Bezuidenhout |
1:dad975e2e150 | 1 | #include "Map.hpp" |
Kerneels Bezuidenhout |
1:dad975e2e150 | 2 | |
Kerneels Bezuidenhout |
1:dad975e2e150 | 3 | Map::Map(float inMin, float inMax, float outMin, float outMax) |
Kerneels Bezuidenhout |
1:dad975e2e150 | 4 | { |
Kerneels Bezuidenhout |
1:dad975e2e150 | 5 | _inMin = inMin; |
Kerneels Bezuidenhout |
1:dad975e2e150 | 6 | _inMax = inMax; |
Kerneels Bezuidenhout |
1:dad975e2e150 | 7 | _outMin = outMin; |
Kerneels Bezuidenhout |
1:dad975e2e150 | 8 | _outMax = outMax; |
Kerneels Bezuidenhout |
1:dad975e2e150 | 9 | } |
Kerneels Bezuidenhout |
1:dad975e2e150 | 10 | |
Kerneels Bezuidenhout |
1:dad975e2e150 | 11 | float Map::Calculate(float inVal) |
Kerneels Bezuidenhout |
1:dad975e2e150 | 12 | { |
drorbalbul | 2:ac294c579449 | 13 | float rval = (inVal - _inMin)*(_outMax - _outMin)/(_inMax - _inMin) + _outMin ; |
drorbalbul | 2:ac294c579449 | 14 | if (rval < _outMin) { |
drorbalbul | 2:ac294c579449 | 15 | rval = _outMin; |
drorbalbul | 2:ac294c579449 | 16 | } |
drorbalbul | 2:ac294c579449 | 17 | if (rval > _outMax) { |
drorbalbul | 2:ac294c579449 | 18 | rval = _outMax; |
drorbalbul | 2:ac294c579449 | 19 | } |
drorbalbul | 2:ac294c579449 | 20 | return rval; |
Kerneels Bezuidenhout |
1:dad975e2e150 | 21 | } |