From 0f7c4605575aa36d0d3eaa8b2eb4a0e1edb4921c Mon Sep 17 00:00:00 2001 From: Idir Aliane Crespo Date: Mon, 22 Jan 2024 18:36:52 +0100 Subject: [PATCH] [raymath.h] Small refactor to avoid duplicated code --- src/raymath.h | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index 444ba2e34..8661eb8cd 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -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; @@ -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;