borrwoed a lot code from https://github.com/foriequal0/devterm_keyboard in order to optimize the trackball

This commit is contained in:
cuu
2021-12-16 20:41:37 +08:00
parent 1a1be01dbb
commit b1370d2124
18 changed files with 538 additions and 118 deletions

View File

@@ -0,0 +1,56 @@
#ifndef MATH_H
#define MATH_H
#include <cstdint>
#include <limits>
#include <cmath>
uint32_t getDelta(uint32_t prev, uint32_t now);
uint32_t getDelta(uint32_t prev, uint32_t now, uint32_t max);
template<typename T>
T sign(T value) {
if (value > 0) {
return 1;
}
if (value < 0) {
return -1;
}
return 0;
}
template<typename T, typename U>
T clamp(U value) {
if (value >= std::numeric_limits<T>().max()) {
return std::numeric_limits<T>().max();
}
if (value <= std::numeric_limits<T>().min()) {
return std::numeric_limits<T>().min();
}
return value;
}
template<typename T>
T min(T x, T y) {
if (x < y) {
return x;
}
return y;
}
template<typename T>
T max(T x, T y) {
if (x > y) {
return x;
}
return y;
}
template<typename T>
T hypot(T x, T y) {
return std::sqrt(x * x + y * y);
}
#endif