prime/include/Kyoto/Math/CloseEnough.hpp

30 lines
895 B
C++
Raw Normal View History

2022-04-16 07:50:32 +00:00
#ifndef __CLOSEENOUGH_HPP__
#define __CLOSEENOUGH_HPP__
#include "types.h"
2022-04-16 07:50:32 +00:00
2022-08-09 23:03:51 +00:00
#include "Kyoto/Math/CVector2f.hpp"
#include "Kyoto/Math/CVector3f.hpp"
#include "math.h"
struct Real32 {
static inline float Epsilon() { return FLT_EPSILON; }
};
struct Double {
static inline double Epsilon() { return DBL_EPSILON; }
};
static inline float vector3_epsilon() { return FLT_EPSILON; }
static inline float vector2_epsilon() { return FLT_EPSILON; }
2022-10-05 23:26:05 +00:00
bool close_enough(const CVector2f& a, const CVector2f& b, float epsilon = vector2_epsilon());
bool close_enough(const CVector3f& a, const CVector3f& b, float epsilon = vector3_epsilon());
inline bool close_enough(float a, float b, float epsilon = Real32::Epsilon()) {
return fabs(a - b) < epsilon;
}
inline bool close_enough(double a, double b, double epsilon = Double::Epsilon()) {
return fabs(a - b) < epsilon;
}
2022-04-16 07:50:32 +00:00
#endif // __CLOSEENOUGH_HPP__