From 223790941cda4e192faec14b00b81c1cf1a1e442 Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 10 Mar 2025 13:01:38 +0100 Subject: [PATCH] small optimisation to normalisation function --- src/util/vec/float2.h | 4 ++-- src/util/vec/float3.h | 4 ++-- src/util/vec/float4.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/vec/float2.h b/src/util/vec/float2.h index f9cd318..58822fb 100644 --- a/src/util/vec/float2.h +++ b/src/util/vec/float2.h @@ -45,8 +45,8 @@ static inline float float2_mag(float2 v) { // normalizes the float2 static inline float2 float2_norm(float2 v) { - float len = float2_mag(v); - return float2_div(v, len); + float s = 1.0F / float2_mag(v); // get the scaling factor + return float2_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing) } // gets the dot product of two float2s diff --git a/src/util/vec/float3.h b/src/util/vec/float3.h index 2758339..9f9a00f 100644 --- a/src/util/vec/float3.h +++ b/src/util/vec/float3.h @@ -46,8 +46,8 @@ static inline float float3_mag(float3 v) { // normalizes the float3 static inline float3 float3_norm(float3 v) { - float len = float3_mag(v); - return float3_div(v, len); + float s = 1.0F / float3_mag(v); // get the scaling factor + return float3_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing) } // gets the dot product of two float3s diff --git a/src/util/vec/float4.h b/src/util/vec/float4.h index d89435b..92a7794 100644 --- a/src/util/vec/float4.h +++ b/src/util/vec/float4.h @@ -47,8 +47,8 @@ static inline float float4_mag(float4 v) { // normalizes the float4 static inline float4 float4_norm(float4 v) { - float len = float4_mag(v); - return float4_div(v, len); + float s = 1.0F / float4_mag(v); // get the scaling factor + return float4_scale(v, s); // scale the vector by the scaling factor (slightly more efficient than dividing) } // gets the dot product of two float4s