From 04ab87cf980bf531a82480d7de101682e38e4924 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Tue, 18 Nov 2025 20:05:06 +0100 Subject: [PATCH] Improve Range class --- openVulkanoCpp/Math/AABB.hpp | 10 ---------- openVulkanoCpp/Math/Range.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/openVulkanoCpp/Math/AABB.hpp b/openVulkanoCpp/Math/AABB.hpp index aea74f1..a673878 100644 --- a/openVulkanoCpp/Math/AABB.hpp +++ b/openVulkanoCpp/Math/AABB.hpp @@ -115,16 +115,6 @@ namespace OpenVulkano::Math { return Math::Utils::all(Math::Utils::lessThanEqual(Range::min, other.GetMax())) && Math::Utils::all(Math::Utils::greaterThanEqual(Range::max, other.GetMin())); } - - [[nodiscard]] bool InBounds(const T& position) const - { - return Math::Utils::all(Math::Utils::lessThanEqual(Range::min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, Range::max)); - } - - [[nodiscard]] bool Inside(const T& position) const - { - return Math::Utils::all(Math::Utils::lessThan(Range::min, position)) && Math::Utils::all(Math::Utils::lessThan(position, Range::max)); - } [[nodiscard]] bool IsEmpty() const { diff --git a/openVulkanoCpp/Math/Range.hpp b/openVulkanoCpp/Math/Range.hpp index 9f25a42..bf6a56a 100644 --- a/openVulkanoCpp/Math/Range.hpp +++ b/openVulkanoCpp/Math/Range.hpp @@ -35,5 +35,36 @@ namespace OpenVulkano::Math [[nodiscard]] T GetSize() const { return max - min; } [[nodiscard]] T Clamp(const T& value) const { return Math::Utils::clamp(value, min, max); } + + /** + * Checks weather positions is inside the bounds or equal to the bounds. + * @param position Position to be checked + * @return True if inside or on bounds, fals if no. + */ + [[nodiscard]] bool InBounds(const T& position) const + { + if constexpr (std::is_arithmetic_v) + return position >= min & position <= max; + else + return Math::Utils::all(Math::Utils::lessThanEqual(Range::min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, Range::max)); + } + + /** + * Checks weather positions is inside the bounds. + * @param position Position to be checked + * @return True if inside bounds, fals if no. + */ + [[nodiscard]] bool Inside(const T& position) const + { + if constexpr (std::is_arithmetic_v) + return position > min & position < max; + else + return Math::Utils::all(Math::Utils::lessThan(Range::min, position)) && Math::Utils::all(Math::Utils::lessThan(position, Range::max)); + } + + [[nodiscard]] bool operator <(const T& rhs) const { return max < rhs; } + [[nodiscard]] bool operator<=(const T& rhs) const { return max <= rhs; } + [[nodiscard]] bool operator >(const T& rhs) const { return min > rhs; } + [[nodiscard]] bool operator>=(const T& rhs) const { return min >= rhs; } }; }