diff --git a/include/blt/std/math.h b/include/blt/std/math.h index 8c9b1d8..0d6ed4b 100644 --- a/include/blt/std/math.h +++ b/include/blt/std/math.h @@ -560,6 +560,38 @@ namespace blt { // << " {" << v.m30() << ", " << v.m31() << ", " << v.m32() << ", " << v.m33() << "} \n"; // } + template + class averagizer_o_matic { + private: + T* data = new T[Size]; + int index = 0; + public: + averagizer_o_matic(): averagizer_o_matic(0) {} + explicit averagizer_o_matic(T default_value){ + for (int i = 0; i < Size; i++){ + data[i] = default_value; + } + } + + void insert(T t){ + data[index++] = t; + if (index >= Size) + index = 0; + } + + T average(){ + T total = 0; + for (int i = 0; i < Size; i++){ + total += data[i]; + } + return total / Size; + } + + ~averagizer_o_matic(){ + delete[] data; + } + }; + } #endif //BLT_MATH_H