diff --git a/CHANGELOG.md b/CHANGELOG.md index a8db94c..5162b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [5-r.1-beta.3] - 2023-10-12 + +### Added + +* Add `clamp()` to CubismMath. + ## [5-r.1-beta.2] - 2023-09-28 @@ -320,6 +326,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Fix invalid expressions of `CubismCdiJson`. +[5-r.1-beta.3]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.2...5-r.1-beta.3 [5-r.1-beta.2]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.1...5-r.1-beta.2 [5-r.1-beta.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.7...5-r.1-beta.1 [4-r.7]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.6.2...4-r.7 diff --git a/src/Math/CubismMath.cpp b/src/Math/CubismMath.cpp index edcf138..1a59dde 100644 --- a/src/Math/CubismMath.cpp +++ b/src/Math/CubismMath.cpp @@ -12,6 +12,34 @@ namespace Live2D {namespace Cubism {namespace Framework { const csmFloat32 CubismMath::Pi = 3.1415926535897932384626433832795f; const csmFloat32 CubismMath::Epsilon = 0.00001f; +csmInt32 CubismMath::Clamp(csmInt32 val, csmInt32 min, csmInt32 max) +{ + if (val < min) + { + return min; + } + else if (max < val) + { + return max; + } + + return val; +} + +csmFloat32 CubismMath::ClampF(csmFloat32 val, csmFloat32 min, csmFloat32 max) +{ + if (val < min) + { + return min; + } + else if (max < val) + { + return max; + } + + return val; +} + csmFloat32 CubismMath::DegreesToRadian(csmFloat32 degrees) { return (degrees / 180.0f) * Pi; diff --git a/src/Math/CubismMath.hpp b/src/Math/CubismMath.hpp index 186c52b..8ab3dba 100644 --- a/src/Math/CubismMath.hpp +++ b/src/Math/CubismMath.hpp @@ -122,6 +122,26 @@ class CubismMath return (l > r) ? r : l; } + /** + * @brief 値を範囲内に納めて返す + * + * @param val -> 範囲内か確認する値 + * @param min -> 最小値 + * @param max -> 最大値 + * @return 範囲内に収まった値 + */ + static csmInt32 Clamp(csmInt32 val, csmInt32 min, csmInt32 max); + + /** + * @brief 値を範囲内に納めて返す + * + * @param val -> 範囲内か確認する値 + * @param min -> 最小値 + * @param max -> 最大値 + * @return 範囲内に収まった値 + */ + static csmFloat32 ClampF(csmFloat32 val, csmFloat32 min, csmFloat32 max); + /** * @brief 角度値をラジアン値に変換します。 *