From 6dcb0817a2cd1a507dbf5e3c42bf13623b5b5cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joshua=20Vanda=C3=ABle?= Date: Sun, 28 Jun 2026 08:33:40 +0200 Subject: MathUtil: C++20/23 modernisations I've also created DegreesToRadians/RadiansToDegrees utility functions since there was a lot of repeated code --- Source/Core/InputCommon/ControllerEmu/StickGate.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Source/Core/InputCommon/ControllerEmu/StickGate.cpp') diff --git a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp index 660ee939be..9898c452f4 100644 --- a/Source/Core/InputCommon/ControllerEmu/StickGate.cpp +++ b/Source/Core/InputCommon/ControllerEmu/StickGate.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -54,7 +55,7 @@ double GetNearestNotch(double angle, double virtual_notch_angle) constexpr auto rounding = MathUtil::TAU / sides; const auto closest_notch = std::round(angle / rounding) * rounding; const auto angle_diff = - std::fmod(angle - closest_notch + MathUtil::PI, MathUtil::TAU) - MathUtil::PI; + std::fmod(angle - closest_notch + std::numbers::pi, MathUtil::TAU) - std::numbers::pi; return std::abs(angle_diff) < virtual_notch_angle / 2 ? closest_notch : angle; } @@ -80,12 +81,12 @@ OctagonStickGate::OctagonStickGate(ControlState radius) : m_radius(radius) ControlState OctagonStickGate::GetRadiusAtAngle(double angle) const { constexpr int sides = 8; - constexpr double sum_int_angles = (sides - 2) * MathUtil::PI; + constexpr double sum_int_angles = (sides - 2) * std::numbers::pi; constexpr double half_int_angle = sum_int_angles / sides / 2; angle = std::fmod(angle, MathUtil::TAU / sides); // Solve ASA triangle using The Law of Sines: - return m_radius / std::sin(MathUtil::PI - angle - half_int_angle) * std::sin(half_int_angle); + return m_radius / std::sin(std::numbers::pi - angle - half_int_angle) * std::sin(half_int_angle); } std::optional OctagonStickGate::GetIdealCalibrationSampleCount() const @@ -306,7 +307,7 @@ ReshapableInput::ReshapeData ReshapableInput::Reshape(ControlState x, ControlSta // (which depends on the signs of x and y) does not matter here as dist is zero // TODO: make the AtAngle functions work with negative angles: - ControlState angle = std::atan2(y, x) + MathUtil::TAU; + ControlState angle = std::atan2(y, x) + MathUtil::TAU_v; const ControlState input_max_dist = GetInputRadiusAtAngle(angle); ControlState gate_max_dist = GetGateRadiusAtAngle(angle); -- cgit v1.2.3