2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CLOSEENOUGH
|
|
|
|
#define _CLOSEENOUGH
|
2022-04-16 07:50:32 +00:00
|
|
|
|
2022-07-02 05:30:04 +00:00
|
|
|
#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"
|
2022-07-02 05:30:04 +00:00
|
|
|
|
2022-10-03 11:55:03 +00:00
|
|
|
#include "math.h"
|
|
|
|
|
2022-10-05 00:16:03 +00:00
|
|
|
struct Real32 {
|
2022-10-17 00:46:11 +00:00
|
|
|
static inline float Epsilon() { return 1.e-5f; }
|
2022-10-05 00:16:03 +00:00
|
|
|
};
|
|
|
|
struct Double {
|
2022-10-17 00:46:11 +00:00
|
|
|
static inline double Epsilon() { return 1.e-5; } // TODO check
|
2022-10-05 00:16:03 +00:00
|
|
|
};
|
2022-10-17 00:46:11 +00:00
|
|
|
static inline float vector3_epsilon() { return 1.e-4f; }
|
|
|
|
static inline float vector2_epsilon() { return 1.e-4f; }
|
2022-10-05 00:16:03 +00:00
|
|
|
|
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());
|
2022-10-05 00:16:03 +00:00
|
|
|
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()) {
|
2022-10-03 11:55:03 +00:00
|
|
|
return fabs(a - b) < epsilon;
|
|
|
|
}
|
2022-04-16 07:50:32 +00:00
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CLOSEENOUGH
|