add negate function to vector definitions

This commit is contained in:
2025-03-14 10:35:08 +01:00
parent e13dea813f
commit c6c6b8aade
3 changed files with 13 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);