Add RangeSet

This commit is contained in:
Georg Hagen
2025-11-19 20:06:07 +01:00
parent 04ab87cf98
commit 13e62033a2

View File

@@ -0,0 +1,44 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Math/Range.hpp"
#include <vector>
namespace OpenVulkano
{
template<typename T>
class RangeSet
{
std::vector<Math::Range<T>> m_ranges;
public:
RangeSet() = default;
RangeSet(const std::vector<Math::Range<T>>& ranges) : m_ranges(ranges) {}
RangeSet(std::vector<Math::Range<T>>&& ranges) : m_ranges(std::move(ranges)) {}
[[nodiscard]] bool ContainsInclusive(const T& value) const
{
for(const auto& range : m_ranges)
{
if (range.InBounds(value)) return true;
}
return false;
}
[[nodiscard]] bool Contains(const T& value) const
{
for(const auto& range : m_ranges)
{
if (range.Inside(value)) return true;
}
return false;
}
};
}