2020-11-27 05:16:22 -05:00
|
|
|
#pragma once
|
2014-11-02 11:24:21 -05:00
|
|
|
//
|
|
|
|
// FILE: FastMap.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2024-02-03 06:26:08 -05:00
|
|
|
// VERSION: 0.4.2
|
2015-03-08 17:17:20 -04:00
|
|
|
// PURPOSE: class with fast map function - library for Arduino
|
2020-11-27 05:16:22 -05:00
|
|
|
// URL: https://github.com/RobTillaart/FastMap
|
2021-12-17 08:46:34 -05:00
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "Arduino.h"
|
2014-11-02 11:24:21 -05:00
|
|
|
|
2024-02-03 06:26:08 -05:00
|
|
|
#define FASTMAP_LIB_VERSION (F("0.4.2"))
|
2021-12-17 08:46:34 -05:00
|
|
|
|
2014-11-02 11:24:21 -05:00
|
|
|
|
|
|
|
class FastMap
|
|
|
|
{
|
|
|
|
public:
|
2022-11-05 05:57:25 -04:00
|
|
|
FastMap();
|
2014-11-02 11:24:21 -05:00
|
|
|
|
2022-11-05 05:57:25 -04:00
|
|
|
bool init(float in_min, float in_max, float out_min, float out_max);
|
2014-11-02 16:20:21 -05:00
|
|
|
|
2022-11-05 05:57:25 -04:00
|
|
|
float inline map (const float value) { return _base + value * _factor; }
|
|
|
|
float inline back (const float value) { return _backbase + value * _backfactor; }
|
2017-07-15 12:28:01 -04:00
|
|
|
|
2022-11-05 05:57:25 -04:00
|
|
|
float constrainedMap(const float value);
|
|
|
|
float lowerConstrainedMap(const float value);
|
|
|
|
float upperConstrainedMap(const float value);
|
2014-11-02 11:24:21 -05:00
|
|
|
|
|
|
|
private:
|
2022-11-05 05:57:25 -04:00
|
|
|
float _in_min, _in_max, _out_min, _out_max;
|
|
|
|
float _factor, _base;
|
|
|
|
float _backfactor, _backbase;
|
2014-11-02 11:24:21 -05:00
|
|
|
};
|
|
|
|
|
2017-07-27 09:26:36 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
class FastMapDouble
|
|
|
|
{
|
|
|
|
public:
|
2022-11-05 05:57:25 -04:00
|
|
|
FastMapDouble();
|
|
|
|
bool init(double in_min, double in_max, double out_min, double out_max);
|
2020-11-27 05:16:22 -05:00
|
|
|
|
2022-11-05 05:57:25 -04:00
|
|
|
double inline map (const double value) { return _base + value * _factor; }
|
|
|
|
double inline back (const double value) { return _backbase + value * _backfactor; }
|
2020-11-27 05:16:22 -05:00
|
|
|
|
2022-11-05 05:57:25 -04:00
|
|
|
double constrainedMap(const double value);
|
|
|
|
double lowerConstrainedMap(const double value);
|
|
|
|
double upperConstrainedMap(const double value);
|
2020-11-27 05:16:22 -05:00
|
|
|
|
|
|
|
private:
|
2022-11-05 05:57:25 -04:00
|
|
|
double _in_min, _in_max, _out_min, _out_max;
|
|
|
|
double _factor, _base;
|
|
|
|
double _backfactor, _backbase;
|
2020-11-27 05:16:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-10-31 06:37:49 -04:00
|
|
|
// -- END OF FILE --
|
2021-12-17 08:46:34 -05:00
|
|
|
|