summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorIdir Carlos Aliane <[email protected]>2024-01-22 19:48:18 +0100
committerGitHub <[email protected]>2024-01-22 19:48:18 +0100
commitc133fee286cfb3dad2fbfa40ab61f968850fd031 (patch)
tree28bb322877fc12b7139384efdb68b3f7219ec783 /src
parent27645e16ab5051b8cf7bb5b6506b16b20f0b1c19 (diff)
downloadraylib-c133fee286cfb3dad2fbfa40ab61f968850fd031.tar.gz
raylib-c133fee286cfb3dad2fbfa40ab61f968850fd031.zip
[raymath.h] Small code refactor (#3753)
* [raymath.h] Small refactor to avoid duplicated code * Fixing some blank spaces to match same syle convention
Diffstat (limited to 'src')
-rw-r--r--src/raymath.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/raymath.h b/src/raymath.h
index 444ba2e3..b46243f4 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -174,7 +174,7 @@ typedef struct float16 {
// Clamp float value
RMAPI float Clamp(float value, float min, float max)
{
- float result = (value < min)? min : value;
+ float result = (value < min) ? min : value;
if (result > max) result = max;
@@ -494,18 +494,18 @@ RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
{
length = sqrtf(length);
+ float scale = 1; // By default, 1 as the neutral element.
if (length < min)
{
- float scale = min/length;
- result.x = v.x*scale;
- result.y = v.y*scale;
+ scale = min/length;
}
else if (length > max)
{
- float scale = max/length;
- result.x = v.x*scale;
- result.y = v.y*scale;
+ scale = max/length;
}
+
+ result.x = v.x*scale;
+ result.y = v.y*scale;
}
return result;
@@ -834,7 +834,7 @@ RMAPI Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle)
// Vector3Normalize(axis);
float length = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
if (length == 0.0f) length = 1.0f;
- float ilength = 1.0f / length;
+ float ilength = 1.0f/length;
axis.x *= ilength;
axis.y *= ilength;
axis.z *= ilength;
@@ -1080,20 +1080,19 @@ RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
{
length = sqrtf(length);
+ float scale = 1; // By default, 1 as the neutral element.
if (length < min)
{
- float scale = min/length;
- result.x = v.x*scale;
- result.y = v.y*scale;
- result.z = v.z*scale;
+ scale = min/length;
}
else if (length > max)
{
- float scale = max/length;
- result.x = v.x*scale;
- result.y = v.y*scale;
- result.z = v.z*scale;
+ scale = max/length;
}
+
+ result.x = v.x*scale;
+ result.y = v.y*scale;
+ result.z = v.z*scale;
}
return result;
@@ -1962,7 +1961,7 @@ RMAPI Quaternion QuaternionFromMatrix(Matrix mat)
}
float biggestVal = sqrtf(fourBiggestSquaredMinus1 + 1.0f)*0.5f;
- float mult = 0.25f / biggestVal;
+ float mult = 0.25f/biggestVal;
switch (biggestIndex)
{