GY-63_MS5611/libraries/DistanceTable/DistanceTable.h

71 lines
1.8 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
// FILE: DistanceTable.h
// AUTHOR: Rob Tillaart
2023-09-25 14:41:00 -04:00
// VERSION: 0.3.3
2020-11-27 05:10:47 -05:00
// PURPOSE: Arduino library to store a symmetrical distance table in less memory
// URL: https://github.com/RobTillaart/DistanceTable
//
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
2023-09-25 14:41:00 -04:00
#define DISTANCETABLE_LIB_VERSION (F("0.3.3"))
2021-01-29 06:31:58 -05:00
class DistanceTable
{
public:
2021-10-26 06:22:01 -04:00
explicit DistanceTable(uint8_t dimension, float value = 0);
2021-01-29 06:31:58 -05:00
~DistanceTable();
void clear() { setAll(0); };
void setAll(float value);
2022-07-22 16:43:52 -04:00
bool set(uint8_t x, uint8_t y, float value );
2021-01-29 06:31:58 -05:00
float get(uint8_t x, uint8_t y);
2022-01-07 08:29:16 -05:00
// the invert flag tells that get(x, y) == -get(y, x);
void setInvert(bool invert = false) { _invert = invert; };
bool getInvert() { return _invert; };
2022-11-02 06:24:05 -04:00
// minimum and maximum skip x == y pairs as these are 0.
2021-01-29 06:31:58 -05:00
float minimum(uint8_t &x, uint8_t &y);
float maximum(uint8_t &x, uint8_t &y);
2022-07-22 16:43:52 -04:00
float sum();
float average();
2021-01-29 06:31:58 -05:00
2022-11-02 06:24:05 -04:00
// epsilon allows 'almost equal' searches
// if (invert == false) count counts both (x,y) and (y,x) => always even nr.
// if (invert == true) count counts (x,y) and (y,x) separately.
// count skips x == y pairs so counting zero's is missing the diagonal.
2021-01-29 06:31:58 -05:00
uint16_t count(float value, float epsilon = 0.0);
2022-01-07 08:29:16 -05:00
uint16_t countAbove(float value);
uint16_t countBelow(float value);
2021-01-29 06:31:58 -05:00
2022-11-02 06:24:05 -04:00
// debug
// default dumps to Serial but other stream are possible
2021-01-29 06:31:58 -05:00
void dump(Print * stream = &Serial);
uint8_t dimension() { return _dimension; };
uint16_t elements() { return _elements; };
uint16_t memoryUsed() { return _elements * sizeof(float); };
2022-11-02 06:24:05 -04:00
// Obsolete in future 0.4.0
2021-01-29 06:31:58 -05:00
uint16_t size() { return memoryUsed(); };
protected:
2021-01-29 06:31:58 -05:00
uint8_t _dimension;
uint16_t _elements;
float * _distanceTable;
2022-01-07 08:29:16 -05:00
bool _invert;
};
2021-10-26 06:22:01 -04:00
2023-09-25 14:41:00 -04:00
// --- END OF FILE ---
2021-12-17 04:50:55 -05:00