2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2015-06-19 15:06:14 -04:00
|
|
|
//
|
|
|
|
// FILE: DistanceTable.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2021-10-26 06:22:01 -04:00
|
|
|
// VERSION: 0.2.1
|
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
|
2015-06-19 15:06:14 -04:00
|
|
|
//
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-06-19 15:06:14 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-10-26 06:22:01 -04:00
|
|
|
#define DISTANCETABLE_LIB_VERSION (F("0.2.1"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-06-19 15:06:14 -04: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);
|
|
|
|
void set(uint8_t x, uint8_t y, float value );
|
|
|
|
float get(uint8_t x, uint8_t y);
|
|
|
|
|
|
|
|
|
|
|
|
// minimum and maximum skip x == y pairs as these are 0.
|
|
|
|
float minimum(uint8_t &x, uint8_t &y);
|
|
|
|
float maximum(uint8_t &x, uint8_t &y);
|
|
|
|
|
|
|
|
|
|
|
|
// epsilon allows 'almost equal' searches
|
|
|
|
// count counts (x,y) but not (y,x) again.
|
|
|
|
// count skips x == y pairs...
|
|
|
|
uint16_t count(float value, float epsilon = 0.0);
|
|
|
|
|
|
|
|
|
|
|
|
// debug
|
|
|
|
// default dumps to Serial but other stream are possible
|
|
|
|
void dump(Print * stream = &Serial);
|
|
|
|
uint8_t dimension() { return _dimension; };
|
|
|
|
uint16_t elements() { return _elements; };
|
|
|
|
uint16_t memoryUsed() { return _elements * sizeof(float); };
|
|
|
|
|
2015-06-19 15:06:14 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
// Obsolete in future
|
|
|
|
uint16_t size() { return memoryUsed(); };
|
2015-06-19 15:06:14 -04:00
|
|
|
|
|
|
|
protected:
|
2021-01-29 06:31:58 -05:00
|
|
|
uint8_t _dimension;
|
|
|
|
uint16_t _elements;
|
|
|
|
float * _distanceTable;
|
2020-11-27 05:10:47 -05:00
|
|
|
|
2015-06-19 15:06:14 -04:00
|
|
|
};
|
|
|
|
|
2021-10-26 06:22:01 -04:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// --- END OF FILE ---
|