From 89eb05b4ed666d4d351eb77711cb92dc989e92c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Fri, 6 Jan 2023 20:21:25 +0100 Subject: [PATCH] Use `length` and `dot` functions to reduce duplicate code --- src/base/vmath.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/vmath.h b/src/base/vmath.h index 2b621c4b9..ca6fb1039 100644 --- a/src/base/vmath.h +++ b/src/base/vmath.h @@ -106,7 +106,7 @@ inline T dot(const vector2_base a, const vector2_base &b) inline float length(const vector2_base &a) { - return sqrtf(a.x * a.x + a.y * a.y); + return sqrtf(dot(a, a)); } inline float angle(const vector2_base &a) @@ -131,7 +131,7 @@ inline vector2_base normalize_pre_length(const vector2_base &v, T len) inline vector2_base normalize(const vector2_base &v) { - float divisor = sqrtf(v.x * v.x + v.y * v.y); + float divisor = length(v); if(divisor == 0.0f) return vector2_base(0.0f, 0.0f); float l = (float)(1.0f / divisor); @@ -271,12 +271,12 @@ inline vector3_base cross(const vector3_base &a, const vector3_base &b) // inline float length(const vector3_base &a) { - return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z); + return sqrtf(dot(a, a)); } inline vector3_base normalize(const vector3_base &v) { - float divisor = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); + float divisor = length(v); if(divisor == 0.0f) return vector3_base(0.0f, 0.0f, 0.0f); float l = (float)(1.0f / divisor);