From b4d5ef6180566b45f567c332aee3d18e1f4b006e Mon Sep 17 00:00:00 2001 From: sashi Date: Sun, 10 Nov 2024 14:51:58 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Math::ClampAngle=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Siv3D/include/Siv3D/Math.hpp | 22 ++++++++++++++++++++++ Siv3D/include/Siv3D/detail/Math.ipp | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/Siv3D/include/Siv3D/Math.hpp b/Siv3D/include/Siv3D/Math.hpp index 5c065c87d..bc6ab52c4 100644 --- a/Siv3D/include/Siv3D/Math.hpp +++ b/Siv3D/include/Siv3D/Math.hpp @@ -1321,6 +1321,28 @@ namespace s3d [[nodiscard]] inline constexpr Vec4 Smoothstep(Vec4 v) noexcept; + ////////////////////////////////////////////////// + // + // ClampAngle + // + ////////////////////////////////////////////////// + + /// @brief 最小値と最大値の範囲にクランプした角度を返します。 + /// @param angle クランプする角度 + /// @param min 範囲の最小値 + /// @param max 範囲の最大値 + /// @return クランプした角度 + /// @remark angle が範囲外である場合、角度を円環的に解釈して min または max のうちより近い方の値に調整します。 + [[nodiscard]] + inline float ClampAngle(float angle, float min, float max) noexcept; + + [[nodiscard]] + inline double ClampAngle(double angle, double min, double max) noexcept; + + SIV3D_CONCEPT_ARITHMETIC + [[nodiscard]] + inline double ClampAngle(Arithmetic angle, Arithmetic min, Arithmetic max) noexcept; + ////////////////////////////////////////////////// // // NormalizeAngle diff --git a/Siv3D/include/Siv3D/detail/Math.ipp b/Siv3D/include/Siv3D/detail/Math.ipp index 7aaf15eac..3e4f7a1f4 100644 --- a/Siv3D/include/Siv3D/detail/Math.ipp +++ b/Siv3D/include/Siv3D/detail/Math.ipp @@ -1354,6 +1354,34 @@ namespace s3d SIV3D_MATH_FUNCTION_CONSTEXPR_X(Smoothstep) + ////////////////////////////////////////////////// + // + // ClampAngle + // + ////////////////////////////////////////////////// + + inline float ClampAngle(const float angle, const float min, float max) noexcept + { + const auto start = (min + max) * 0.5f - TwoPiF; + const auto floor = Floor((angle - start) / TwoPiF) * TwoPiF; + return Clamp(angle, min + floor, max + floor); + } + + inline double ClampAngle(const double angle, const double min, double max) noexcept + { + const auto start = (min + max) * 0.5 - TwoPi; + const auto floor = Floor((angle - start) / TwoPi) * TwoPi; + return Clamp(angle, min + floor, max + floor); + } + + SIV3D_CONCEPT_ARITHMETIC_ + inline double ClampAngle(Arithmetic angle, Arithmetic min, Arithmetic max) noexcept + { + const auto start = (min + max) * 0.5 - TwoPi; + const auto floor = Floor((angle - start) / TwoPi) * TwoPi; + return Clamp(angle, min + floor, max + floor); + } + ////////////////////////////////////////////////// // // NormalizeAngle From 23bc0b498f1fc8db4e5fe28b5a3cafd859637e47 Mon Sep 17 00:00:00 2001 From: sashi Date: Sun, 10 Nov 2024 17:02:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Siv3D/include/Siv3D/Math.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Siv3D/include/Siv3D/Math.hpp b/Siv3D/include/Siv3D/Math.hpp index bc6ab52c4..7b31ef6d3 100644 --- a/Siv3D/include/Siv3D/Math.hpp +++ b/Siv3D/include/Siv3D/Math.hpp @@ -1327,12 +1327,12 @@ namespace s3d // ////////////////////////////////////////////////// - /// @brief 最小値と最大値の範囲にクランプした角度を返します。 + /// @brief 最小角と最大角の範囲にクランプした角度を返します。 /// @param angle クランプする角度 - /// @param min 範囲の最小値 - /// @param max 範囲の最大値 + /// @param min 範囲の最小角 + /// @param max 範囲の最大角 /// @return クランプした角度 - /// @remark angle が範囲外である場合、角度を円環的に解釈して min または max のうちより近い方の値に調整します。 + /// @remark 角度を円環的に解釈して min または max のうちより近い方の角度に angle を調整します。 [[nodiscard]] inline float ClampAngle(float angle, float min, float max) noexcept; From 71f5819061b3738ecb6493a9eb5d7b8417a4c12e Mon Sep 17 00:00:00 2001 From: sashi Date: Sun, 10 Nov 2024 22:29:07 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Pi=20=E3=81=A8=E3=81=99=E3=82=8B=E3=81=B9?= =?UTF-8?q?=E3=81=8D=E9=83=A8=E5=88=86=E3=81=8C=20TwoPi=20=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Siv3D/include/Siv3D/detail/Math.ipp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Siv3D/include/Siv3D/detail/Math.ipp b/Siv3D/include/Siv3D/detail/Math.ipp index 3e4f7a1f4..d2bf2b0da 100644 --- a/Siv3D/include/Siv3D/detail/Math.ipp +++ b/Siv3D/include/Siv3D/detail/Math.ipp @@ -1362,14 +1362,14 @@ namespace s3d inline float ClampAngle(const float angle, const float min, float max) noexcept { - const auto start = (min + max) * 0.5f - TwoPiF; + const auto start = (min + max) * 0.5f - PiF; const auto floor = Floor((angle - start) / TwoPiF) * TwoPiF; return Clamp(angle, min + floor, max + floor); } inline double ClampAngle(const double angle, const double min, double max) noexcept { - const auto start = (min + max) * 0.5 - TwoPi; + const auto start = (min + max) * 0.5 - Pi; const auto floor = Floor((angle - start) / TwoPi) * TwoPi; return Clamp(angle, min + floor, max + floor); } @@ -1377,7 +1377,7 @@ namespace s3d SIV3D_CONCEPT_ARITHMETIC_ inline double ClampAngle(Arithmetic angle, Arithmetic min, Arithmetic max) noexcept { - const auto start = (min + max) * 0.5 - TwoPi; + const auto start = (min + max) * 0.5 - Pi; const auto floor = Floor((angle - start) / TwoPi) * TwoPi; return Clamp(angle, min + floor, max + floor); } From 613078385dd58f8c2e0c19889553604e83277f90 Mon Sep 17 00:00:00 2001 From: Ryo Suzuki Date: Sun, 17 Nov 2024 22:09:11 +0900 Subject: [PATCH 4/4] Update Math.hpp --- Siv3D/include/Siv3D/Math.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Siv3D/include/Siv3D/Math.hpp b/Siv3D/include/Siv3D/Math.hpp index 7b31ef6d3..bfd02845e 100644 --- a/Siv3D/include/Siv3D/Math.hpp +++ b/Siv3D/include/Siv3D/Math.hpp @@ -1328,11 +1328,11 @@ namespace s3d ////////////////////////////////////////////////// /// @brief 最小角と最大角の範囲にクランプした角度を返します。 - /// @param angle クランプする角度 - /// @param min 範囲の最小角 - /// @param max 範囲の最大角 - /// @return クランプした角度 - /// @remark 角度を円環的に解釈して min または max のうちより近い方の角度に angle を調整します。 + /// @param angle クランプする角度(ラジアン) + /// @param min 範囲の最小角(ラジアン) + /// @param max 範囲の最大角(ラジアン) + /// @return クランプした角度(ラジアン) + /// @remark angle が min の方向と max の方向の間を指さない場合、より近いほうの角度を返します。 [[nodiscard]] inline float ClampAngle(float angle, float min, float max) noexcept;