fix(vector3): change returns 0 to NAN for better comprehension

This commit is contained in:
2025-03-16 12:14:08 +01:00
committed by Loïc GUEZO
parent 87e2ec312c
commit 1dbbf5da3e

View File

@@ -35,14 +35,14 @@ Vec3* vec3Scale(Vec3* v, float scalar)
float vec3Dot(Vec3* a, Vec3* b) float vec3Dot(Vec3* a, Vec3* b)
{ {
if (!a || !b) return 0; if (!a || !b) return NAN;
return a->x * b->x + a->y * b->y + a->z * b->z; return a->x * b->x + a->y * b->y + a->z * b->z;
} }
float vec3Len(Vec3* v) float vec3Len(Vec3* v)
{ {
if (!v) return 0; if (!v) return NAN;
return sqrtf(vec3Dot(v, v)); return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
} }
Vec3* vec3Norm(Vec3* v) Vec3* vec3Norm(Vec3* v)
@@ -52,8 +52,7 @@ Vec3* vec3Norm(Vec3* v)
float length = vec3Len(v); float length = vec3Len(v);
if (length == 0.f) return vec3(0, 0, 0); if (length == 0.f) return vec3(0, 0, 0);
float invLength = 1.f / length; return vec3Scale(v, 1.f / length);
return vec3Scale(v, invLength);
} }
Vec3* vec3Lerp(Vec3* a, Vec3* b, float t) Vec3* vec3Lerp(Vec3* a, Vec3* b, float t)