瀏覽代碼

[raymath] Added macros for EPSILON on each function it's used in (#3330)

* Added macros for EPSILON
This is so the functions can be easily copied and used.

* used `#if !defined()` instead of `#ifndef`

---------

Co-authored-by: Brian-E <brian@intra.fo>
pull/3350/head
Brian E 1 年之前
committed by GitHub
父節點
當前提交
577a8de7c0
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: 4AEE18F83AFDEB23
共有 1 個檔案被更改,包括 20 行新增0 行删除
  1. +20
    -0
      src/raymath.h

+ 20
- 0
src/raymath.h 查看文件

@ -214,6 +214,10 @@ RMAPI float Wrap(float value, float min, float max)
// Check whether two given floats are almost equal // Check whether two given floats are almost equal
RMAPI int FloatEquals(float x, float y) RMAPI int FloatEquals(float x, float y)
{ {
#if !defined(EPSILON)
#define EPSILON 0.000001f
#endif
int result = (fabsf(x - y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y)))); int result = (fabsf(x - y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y))));
return result; return result;
@ -506,6 +510,10 @@ RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
// Check whether two given vectors are almost equal // Check whether two given vectors are almost equal
RMAPI int Vector2Equals(Vector2 p, Vector2 q) RMAPI int Vector2Equals(Vector2 p, Vector2 q)
{ {
#if !defined(EPSILON)
#define EPSILON 0.000001f
#endif
int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) && int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))); ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y)))));
@ -1090,6 +1098,10 @@ RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
// Check whether two given vectors are almost equal // Check whether two given vectors are almost equal
RMAPI int Vector3Equals(Vector3 p, Vector3 q) RMAPI int Vector3Equals(Vector3 p, Vector3 q)
{ {
#if !defined(EPSILON)
#define EPSILON 0.000001f
#endif
int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) && int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) && ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))); ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z)))));
@ -1846,6 +1858,10 @@ RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
{ {
Quaternion result = { 0 }; Quaternion result = { 0 };
#if !defined(EPSILON)
#define EPSILON 0.000001f
#endif
float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w; float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
if (cosHalfTheta < 0) if (cosHalfTheta < 0)
@ -2153,6 +2169,10 @@ RMAPI Quaternion QuaternionTransform(Quaternion q, Matrix mat)
// Check whether two given quaternions are almost equal // Check whether two given quaternions are almost equal
RMAPI int QuaternionEquals(Quaternion p, Quaternion q) RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
{ {
#if !defined(EPSILON)
#define EPSILON 0.000001f
#endif
int result = (((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) && int result = (((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) && ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) && ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&

Loading…
取消
儲存