SDL: Use the new SDL_clamp() macro where sensible

From fbc364908a4fd4644e96377ed488811f025cf36b Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Sat, 14 Aug 2021 22:29:05 +0800
Subject: [PATCH] Use the new SDL_clamp() macro where sensible

There were a few places throughout the SDL code where values were
clamped using SDL_min() and SDL_max(). Now that we have an SDL_clamp()
macro, use this instead.
---
 src/events/SDL_events.c                 |  2 +-
 src/joystick/iphoneos/SDL_mfijoystick.m |  6 +++---
 src/video/wayland/SDL_waylandevents.c   |  2 +-
 test/testvulkan.c                       | 12 ++++++------
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index d963337b12..771c0a605f 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -146,7 +146,7 @@ static int SDL_DoEventLogging = 0;
 static void SDLCALL
 SDL_EventLoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
 {
-    SDL_DoEventLogging = (hint && *hint) ? SDL_max(SDL_min(SDL_atoi(hint), 2), 0) : 0;
+    SDL_DoEventLogging = (hint && *hint) ? SDL_clamp(SDL_atoi(hint), 0, 2) : 0;
 }
 
 static void
diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index fafe63b703..5283199f44 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -783,9 +783,9 @@ static int is_macos11(void)
      */
 
     /* clamp the data */
-    accel.x = SDL_min(SDL_max(accel.x, -maxgforce), maxgforce);
-    accel.y = SDL_min(SDL_max(accel.y, -maxgforce), maxgforce);
-    accel.z = SDL_min(SDL_max(accel.z, -maxgforce), maxgforce);
+    accel.x = SDL_clamp(accel.x, -maxgforce, maxgforce);
+    accel.y = SDL_clamp(accel.y, -maxgforce, maxgforce);
+    accel.z = SDL_clamp(accel.z, -maxgforce, maxgforce);
 
     /* pass in data mapped to range of SInt16 */
     SDL_PrivateJoystickAxis(joystick, 0,  (accel.x / maxgforce) * maxsint16);
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 171a7a009e..c93dcc1267 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -925,7 +925,7 @@ keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
                             int32_t rate, int32_t delay)
 {
     struct SDL_WaylandInput *input = data;
-    input->keyboard_repeat.repeat_rate = SDL_max(0, SDL_min(rate, 1000));
+    input->keyboard_repeat.repeat_rate = SDL_clamp(rate, 0, 1000);
     input->keyboard_repeat.repeat_delay = delay;
     input->keyboard_repeat.is_initialized = SDL_TRUE;
 }
diff --git a/test/testvulkan.c b/test/testvulkan.c
index fe0cb79a2c..19465bca7a 100644
--- a/test/testvulkan.c
+++ b/test/testvulkan.c
@@ -722,13 +722,13 @@ static SDL_bool createSwapchain(void)
 
     // Clamp the size to the allowable image extent.
     // SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287)
-    vulkanContext.swapchainSize.width = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.width,
-                                                SDL_min(w,
-                                                        vulkanContext.surfaceCapabilities.maxImageExtent.width));
+    vulkanContext.swapchainSize.width = SDL_clamp(w,
+                                                  vulkanContext.surfaceCapabilities.minImageExtent.width,
+                                                  vulkanContext.surfaceCapabilities.maxImageExtent.width);
 
-    vulkanContext.swapchainSize.height = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.height,
-                                                SDL_min(h,
-                                                        vulkanContext.surfaceCapabilities.maxImageExtent.height));
+    vulkanContext.swapchainSize.height = SDL_clamp(h,
+                                                   vulkanContext.surfaceCapabilities.minImageExtent.height,
+                                                   vulkanContext.surfaceCapabilities.maxImageExtent.height);
 
     if(w == 0 || h == 0)
         return SDL_FALSE;