From c6c6b8aade26a7e5092a80b728fa50752cee2f25 Mon Sep 17 00:00:00 2001 From: Quinn Date: Fri, 14 Mar 2025 10:35:08 +0100 Subject: [PATCH] add negate function to vector definitions --- src/util/vec/float2.h | 5 +++++ src/util/vec/float3.h | 4 ++++ src/util/vec/float4.h | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/src/util/vec/float2.h b/src/util/vec/float2.h index 1d44599..410e8fb 100644 --- a/src/util/vec/float2.h +++ b/src/util/vec/float2.h @@ -38,6 +38,11 @@ static inline float2 float2_div_s(float2 v, float n) { return (float2){v.x / n, v.y / n}; } +// negates the float2 (-v) +static inline float2 float2_neg(float2 v) { + return (float2){-v.x, -v.y}; +} + // gets the squared magnitude/length of float2 static inline float float2_mag2(float2 v) { return (v.x * v.x) + (v.y * v.y); diff --git a/src/util/vec/float3.h b/src/util/vec/float3.h index b9bf76e..79b2418 100644 --- a/src/util/vec/float3.h +++ b/src/util/vec/float3.h @@ -39,6 +39,10 @@ static inline float3 float3_div_s(float3 v, float n) { return (float3){v.x / n, v.y / n, v.z / n}; } +static inline float3 float3_neg(float3 v) { + return (float3){-v.x, -v.y, -v.z}; +} + // gets the squared magnitude/length of float3 static inline float float3_mag2(float3 v) { return (v.x * v.x) + (v.y * v.y) + (v.z * v.z); diff --git a/src/util/vec/float4.h b/src/util/vec/float4.h index 01f186c..002dbf7 100644 --- a/src/util/vec/float4.h +++ b/src/util/vec/float4.h @@ -40,6 +40,10 @@ static inline float4 float4_div_s(float4 v, float n) { return (float4){v.x / n, v.y / n, v.z / n, v.w / n}; } +static inline float4 float4_neg(float4 v) { + return (float4){-v.x, -v.y, -v.z, -v.w}; +} + // gets the squared magnitude/length of float4 static inline float float4_mag2(float4 v) { return (v.x * v.x) + (v.y * v.y) + (v.z * v.z) + (v.w * v.w);