From f8e8f18be544687089a244cdcbd4a82db5ae3a9c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 26 Nov 2021 18:10:29 -0500 Subject: [PATCH] Switch to `std::clamp`. --- Machines/Apple/ADB/Mouse.cpp | 6 ++++-- Machines/Atari/ST/IntelligentKeyboard.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Machines/Apple/ADB/Mouse.cpp b/Machines/Apple/ADB/Mouse.cpp index 2bd2e7ae6..ba0a5310f 100644 --- a/Machines/Apple/ADB/Mouse.cpp +++ b/Machines/Apple/ADB/Mouse.cpp @@ -8,6 +8,8 @@ #include "Mouse.hpp" +#include + using namespace Apple::ADB; Mouse::Mouse(Bus &bus) : ReactiveDevice(bus, 3) {} @@ -20,8 +22,8 @@ void Mouse::perform_command(const Command &command) { const int buttons = button_flags_; // Clamp deltas. - delta_x = std::max(std::min(delta_x, int16_t(127)), int16_t(-128)); - delta_y = std::max(std::min(delta_y, int16_t(127)), int16_t(-128)); + delta_x = std::clamp(delta_x, int16_t(-128), int16_t(127)); + delta_y = std::clamp(delta_y, int16_t(-128), int16_t(127)); // Figure out what that would look like, and don't respond if there's // no change to report. diff --git a/Machines/Atari/ST/IntelligentKeyboard.cpp b/Machines/Atari/ST/IntelligentKeyboard.cpp index 4fab68478..fdec08d7f 100644 --- a/Machines/Atari/ST/IntelligentKeyboard.cpp +++ b/Machines/Atari/ST/IntelligentKeyboard.cpp @@ -68,8 +68,8 @@ void IntelligentKeyboard::run_for(HalfCycles duration) { mouse_position_[1] += mouse_y_multiplier_ * scaled_movement[1]; // Clamp to range. - mouse_position_[0] = std::min(std::max(mouse_position_[0], 0), mouse_range_[0]); - mouse_position_[1] = std::min(std::max(mouse_position_[1], 0), mouse_range_[1]); + mouse_position_[0] = std::clamp(mouse_position_[0], 0, mouse_range_[0]); + mouse_position_[1] = std::clamp(mouse_position_[1], 0, mouse_range_[1]); mouse_movement_[0] -= scaled_movement[0] * mouse_scale_[0]; mouse_movement_[1] -= scaled_movement[1] * mouse_scale_[1];