Add RangeSet
This commit is contained in:
44
openVulkanoCpp/Data/Containers/RangeSet.hpp
Normal file
44
openVulkanoCpp/Data/Containers/RangeSet.hpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user