6 #ifndef INCLUDE_IMUNANO33_MATHUTIL_HPP_
7 #define INCLUDE_IMUNANO33_MATHUTIL_HPP_
18 #ifdef IMUNANO33_EMBED
26 #ifdef IMUNANO33_EMBED
60 return fabs(num) < tol;
84 #ifdef IMUNANO33_EMBED
85 return fabs(vec.
x) < tol && fabs(vec.
y) < tol && fabs(vec.
z) < tol;
87 return std::none_of(vec.
begin(), vec.
end(), [tol](
const num_t &el) {
88 return std::fabs(el) >= tol;
107 return nearEq(num1, num2, NEAR_ZERO);
124 return fabs(num1 - num2) < tol;
141 template <
typename T>
static T
clamp(
const T &num,
const T &lo,
const T &hi) {
142 return num < lo ? lo : num > hi ? hi : num;
146 #ifdef IMUNANO33_EMBED
147 static constexpr
num_t NEAR_ZERO = FLT_EPSILON;
149 static constexpr
num_t NEAR_ZERO = std::numeric_limits<num_t>::epsilon();
A minimized version of vectors for embedded devices without access to the STL (such as on an Arduino,...
Contains imunano33::TempUnit and imunano33::PressureUnit enums, in addition to number type.
double num_t
Alias to number type depending on embed.
Definition: unit.hpp:34
Utility static methods for math calculations.
Definition: mathutil.hpp:37
static T clamp(const T &num, const T &lo, const T &hi)
Restricts num between lo and hi.
Definition: mathutil.hpp:141
static bool nearZero(const num_t num)
Determines if number is near zero with given precision.
Definition: mathutil.hpp:48
static bool nearZero(const Vector3D &vec, const num_t tol)
Determines if vector is near zero with given precision.
Definition: mathutil.hpp:83
static bool nearEq(const num_t num1, const num_t num2, const num_t tol)
Determines if num1 is nearly equal to num2.
Definition: mathutil.hpp:123
static bool nearZero(const num_t num, const num_t tol)
Determines if number is near zero with given precision.
Definition: mathutil.hpp:59
static bool nearZero(const Vector3D &vec)
Determines if vector is near zero with given precision.
Definition: mathutil.hpp:72
static bool nearEq(const num_t num1, const num_t num2)
Determines if num1 is nearly equal to num2.
Definition: mathutil.hpp:106
iterator begin() noexcept
Iterator of first element.
Definition: simplevectors.hpp:554
iterator end() noexcept
Interator of last element + 1.
Definition: simplevectors.hpp:581
A simple 3D vector representation.
Definition: simplevectors.hpp:844
double z() const
Gets z-component.
Definition: simplevectors.hpp:913
double x() const
Gets x-component.
Definition: simplevectors.hpp:877
double y() const
Gets y-component.
Definition: simplevectors.hpp:895
A minimal 3D vector representation.
Definition: sv_embed.hpp:168