From b7b0195841a22f5b8801c69fa8d61c8b0a07ab06 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 19 Nov 2022 17:47:47 +0100 Subject: entity: add the rest of erased accessors --- entity/erased-constraints.hpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'entity/erased-constraints.hpp') diff --git a/entity/erased-constraints.hpp b/entity/erased-constraints.hpp index f462472a..2d4b47ae 100644 --- a/entity/erased-constraints.hpp +++ b/entity/erased-constraints.hpp @@ -50,9 +50,27 @@ template constexpr std::pair range::convert() const } } -struct length final { +constexpr bool operator==(const range& a, const range& b) +{ + if (a.type != b.type) + return false; + + static constexpr float eps = 1e-6f; + + switch (a.type) + { + default: return false; + case range::type_none: return true; + case range::type_float: return std::fabs(a.min.f - b.min.f) < eps && std::fabs(a.max.f - b.max.f) < eps; + case range::type_uint: return a.min.u == b.min.u && a.max.u == b.max.u; + case range::type_int: return a.min.i == b.min.i && a.max.i == b.max.i; + } +} + +struct max_length final { std::size_t value = std::numeric_limits::max(); constexpr operator std::size_t() const { return value; } + //constexpr bool operator==(const max_length&) const noexcept = default; }; struct group final { @@ -60,6 +78,7 @@ struct group final { constexpr operator StringView() const { return group_name; } constexpr group() = default; constexpr group(StringView name) : group_name{name} {} + //constexpr bool operator==(const group&) const noexcept = default; }; } // namespace floormat::entities::erased_constraints -- cgit v1.2.3