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

67 lines
1.4 KiB
C
Raw Normal View History

2022-07-12 14:20:20 -04:00
#pragma once
//
// FILE: SparseMatrix.h
// AUTHOR: Rob Tillaart
2022-11-25 08:22:25 -05:00
// VERSION: 0.1.4
2022-07-12 14:20:20 -04:00
// DATE: 2022-07-12
// PURPOSE: Arduino library for sparse matrices
2022-07-14 11:28:24 -04:00
// URL: https://github.com/RobTillaart/SparseMatrix
2022-07-12 14:20:20 -04:00
//
#include "Arduino.h"
2022-11-25 08:22:25 -05:00
#define SPARSEMATRIX_LIB_VERSION (F("0.1.4"))
2022-07-14 11:28:24 -04:00
#ifndef SPARSEMATRIX_MAX_SIZE
#define SPARSEMATRIX_MAX_SIZE 1000
#endif
2022-07-12 14:20:20 -04:00
class SparseMatrix
{
public:
2022-07-14 11:28:24 -04:00
SparseMatrix(uint16_t sz);
2022-07-12 14:20:20 -04:00
~SparseMatrix();
2022-07-14 11:28:24 -04:00
uint16_t size();
uint16_t count();
2022-07-12 14:20:20 -04:00
float sum();
2022-07-13 11:47:55 -04:00
void clear();
2022-07-12 14:20:20 -04:00
// returns false if no slots free
// could return # free slots?
bool set(uint8_t x, uint8_t y, float value);
2022-07-13 11:47:55 -04:00
// adds value to element x,y
bool add(uint8_t x, uint8_t y, float value);
2022-07-12 14:20:20 -04:00
float get(uint8_t x, uint8_t y);
2022-07-16 07:42:58 -04:00
// returns four sides between all values != 0 are located.
void boundingBox(uint8_t &minX, uint8_t &maxX, uint8_t &minY, uint8_t &maxY);
2022-07-12 14:20:20 -04:00
private:
2022-07-14 11:28:24 -04:00
uint16_t _size = 0;
uint16_t _count = 0;
2022-07-12 14:20:20 -04:00
uint8_t *_x = NULL;
uint8_t *_y = NULL;
float *_value = NULL;
2022-07-14 11:28:24 -04:00
// returns index of x, y if in set
2022-07-12 14:20:20 -04:00
// otherwise -1
2022-07-14 11:28:24 -04:00
int32_t findPos(uint8_t x, uint8_t y);
2022-07-16 07:42:58 -04:00
// removes element at pos (from findPos)
// pre: count > 0
void removeElement(uint16_t pos);
// creates a new element if value != 0 and if there is room
bool newElement(uint8_t x, uint8_t y, float value);
2022-07-12 14:20:20 -04:00
};
// -- END OF FILE --