2021-01-29 06:31:58 -05:00
[![Arduino CI ](https://github.com/RobTillaart/Distancetable/workflows/Arduino%20CI/badge.svg )](https://github.com/marketplace/actions/arduino_ci)
2021-10-26 06:22:01 -04:00
[![Arduino-lint ](https://github.com/RobTillaart/DistanceTable/actions/workflows/arduino-lint.yml/badge.svg )](https://github.com/RobTillaart/DistanceTable/actions/workflows/arduino-lint.yml)
[![JSON check ](https://github.com/RobTillaart/DistanceTable/actions/workflows/jsoncheck.yml/badge.svg )](https://github.com/RobTillaart/DistanceTable/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT ](https://img.shields.io/badge/license-MIT-green.svg )](https://github.com/RobTillaart/Distancetable/blob/master/LICENSE)
[![GitHub release ](https://img.shields.io/github/release/RobTillaart/Distancetable.svg?maxAge=3600 )](https://github.com/RobTillaart/Distancetable/releases)
2020-11-27 05:10:47 -05:00
# Distancetable
2017-07-27 10:24:22 -04:00
2021-01-29 06:31:58 -05:00
Arduino library to store a symmetrical distance table in less memory.
2017-07-27 10:24:22 -04:00
2020-11-27 05:10:47 -05:00
## Description
2017-07-27 10:24:22 -04:00
2020-11-27 05:10:47 -05:00
The DistanceTable library is a class that stores a symmetrical distance table
which is typically N x N entries in less memory space.
2021-10-26 06:22:01 -04:00
It uses (N x (N-1))/2 ("in a triangle") as an euclidean distance table is
2020-11-27 05:10:47 -05:00
symmetrical around its main diagonal.
Furthermore as the main diagonal are all zero it does not need to be stored either.
2017-07-27 10:24:22 -04:00
2020-11-27 05:10:47 -05:00
An ATMEL328 (Arduino) can store a 30 x 30 matrix = 900 floats in 1740 bytes,
where it typically would take 900 x 4 = 3600 bytes.
2017-07-27 10:24:22 -04:00
2020-11-27 05:10:47 -05:00
Within the 2K RAM of an Arduino one could store normally a 21 x 21 matrix (1764 bytes).
2017-07-27 10:24:22 -04:00
2021-01-29 06:31:58 -05:00
## Interface
2021-10-26 06:22:01 -04:00
- **DistanceTable(uint8_t size, float value = 0.0)** Constructor, allocates memory and sets initial value to all elements.
2021-01-29 06:31:58 -05:00
- **~DistanceTable();** Destructor, frees memory
- **void clear()** sets all entries to 0.0.
2021-10-26 06:22:01 -04:00
- **void setAll(float value)** sets all entries to value;
2021-01-29 06:31:58 -05:00
- **void set(uint8_t x, uint8_t y, float value )** sets a value for (x,y) and automatically for (y, x)
- **float get(uint8_t x, uint8_t y)** gets a value from (x,y). If x == y it will return 0.
2021-10-26 06:22:01 -04:00
- **float minimum(uint8_t & x, uint8_t & y)** Returns minimum and first occurrence in x and y. It does skip x == y pairs as these are 0.
- **float maximum(uint8_t & x, uint8_t & y)** Returns maximum and first occurrence in x and y. It does skip x == y pairs as these are 0.
- **uint16_t count(value, epsilon)** counts the number of occurrences of value. As we are comparing floats the epsilon can set a margin for 'almost equal'.
2021-01-29 06:31:58 -05:00
### Debug
- **void dump(Print \* stream = & Serial)** dumps distance table , default to serial.
- **uint8_t dimension()** dimension of the table == parameter in constructor.
- **uint16_t elements()** amount of elements allocated.
- **uint16_t memoryUsed()** amount of memory used.
## Future
2021-10-26 06:22:01 -04:00
- **clear()** could set all to NAN? is that better as it indicates unknown?
2021-01-29 06:31:58 -05:00
setAll() let the user decide.
2021-10-26 06:22:01 -04:00
Note: table can be used for other symmetrical 2D tables.
And therefore include negative values.
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
## Operational
2017-07-27 10:24:22 -04:00
2020-11-27 05:10:47 -05:00
See examples.