diff options
Diffstat (limited to 'core/src/Utils')
-rw-r--r-- | core/src/Utils/Color.hpp | 9 | ||||
-rw-r--r-- | core/src/Utils/Math.hpp | 11 | ||||
-rw-r--r-- | core/src/Utils/Time.cpp | 4 | ||||
-rw-r--r-- | core/src/Utils/Time.hpp | 4 |
4 files changed, 22 insertions, 6 deletions
diff --git a/core/src/Utils/Color.hpp b/core/src/Utils/Color.hpp index 8e159ea..46435c3 100644 --- a/core/src/Utils/Color.hpp +++ b/core/src/Utils/Color.hpp @@ -1,5 +1,6 @@ #pragma once +#include "Utils/Math.hpp" #include "Utils/Vector.hpp" #include "Utils/fwd.hpp" @@ -167,7 +168,7 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept auto p = fg < fb ? Vec4f{ fb, fg, -1, 2.0f / 3.0f } : Vec4f{ fg, fb, 0, -1.0f / 3.0f }; auto q = fr < p.x ? Vec4f{ p.x, p.y, p.w, fr } : Vec4f{ fr, p.y, p.z, p.x }; float c = q.x - std::min(q.w, q.y); - float h = std::abs((q.w - q.y) / (6 * c + std::numeric_limits<float>::epsilon()) + q.z); + float h = MathUtils::Abs((q.w - q.y) / (6 * c + std::numeric_limits<float>::epsilon()) + q.z); Vec3f hcv{ h, c, q.x }; float s = hcv.y / (hcv.z + std::numeric_limits<float>::epsilon()); @@ -176,9 +177,9 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept constexpr RgbaColor HsvColor::ToRgba() const noexcept { - float r = std::abs(h * 6 - 3) - 1; - float g = 2 - std::abs(h * 6 - 2); - float b = 2 - std::abs(h * 6 - 4); + float r = MathUtils::Abs(h * 6 - 3) - 1; + float g = 2 - MathUtils::Abs(h * 6 - 2); + float b = 2 - MathUtils::Abs(h * 6 - 4); auto rgb = Vec3f{ std::clamp(r, 0.0f, 1.0f), diff --git a/core/src/Utils/Math.hpp b/core/src/Utils/Math.hpp new file mode 100644 index 0000000..2d0c0cd --- /dev/null +++ b/core/src/Utils/Math.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace MathUtils { + +template <class T> +constexpr T Abs(T t) +{ + return t < 0 ? -t : t; +} + +} // namespace Math diff --git a/core/src/Utils/Time.cpp b/core/src/Utils/Time.cpp index bbdc313..9086e31 100644 --- a/core/src/Utils/Time.cpp +++ b/core/src/Utils/Time.cpp @@ -2,7 +2,7 @@ #include <ctime> -std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp) +std::string TimeUtils::StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp) { auto t = std::chrono::system_clock::to_time_t(tp); @@ -15,7 +15,7 @@ std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock return std::string(data); } -std::string StringifyTimeStamp(int64_t timeStamp) +std::string TimeUtils::StringifyTimeStamp(int64_t timeStamp) { if (timeStamp == 0) { return ""; diff --git a/core/src/Utils/Time.hpp b/core/src/Utils/Time.hpp index 13e12a1..fbbd3b2 100644 --- a/core/src/Utils/Time.hpp +++ b/core/src/Utils/Time.hpp @@ -3,5 +3,9 @@ #include <chrono> #include <string> +namespace TimeUtils { + std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp); std::string StringifyTimeStamp(int64_t timeStamp); + +} // namespace TimeUtils |