58 lines
1.3 KiB
C
Raw Normal View History

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