1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-30 22:29:56 +00:00

Switch to std::clamp.

This commit is contained in:
Thomas Harte 2021-11-26 18:10:29 -05:00
parent 8b38c567d2
commit f8e8f18be5
2 changed files with 6 additions and 4 deletions

View File

@ -8,6 +8,8 @@
#include "Mouse.hpp"
#include <algorithm>
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.

View File

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