Improve Range class

This commit is contained in:
Georg Hagen
2025-11-18 20:05:06 +01:00
parent 77c731eb56
commit 04ab87cf98
2 changed files with 31 additions and 10 deletions

View File

@@ -115,16 +115,6 @@ namespace OpenVulkano::Math
{
return Math::Utils::all(Math::Utils::lessThanEqual(Range<T>::min, other.GetMax())) && Math::Utils::all(Math::Utils::greaterThanEqual(Range<T>::max, other.GetMin()));
}
[[nodiscard]] bool InBounds(const T& position) const
{
return Math::Utils::all(Math::Utils::lessThanEqual(Range<T>::min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, Range<T>::max));
}
[[nodiscard]] bool Inside(const T& position) const
{
return Math::Utils::all(Math::Utils::lessThan(Range<T>::min, position)) && Math::Utils::all(Math::Utils::lessThan(position, Range<T>::max));
}
[[nodiscard]] bool IsEmpty() const
{

View File

@@ -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<T>)
return position >= min & position <= max;
else
return Math::Utils::all(Math::Utils::lessThanEqual(Range<T>::min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, Range<T>::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<T>)
return position > min & position < max;
else
return Math::Utils::all(Math::Utils::lessThan(Range<T>::min, position)) && Math::Utils::all(Math::Utils::lessThan(position, Range<T>::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; }
};
}