From 5424a1d5434e3ddd911a504719918c2df027e2fd Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 17 Apr 2022 20:08:57 -0700 Subject: Changeset: 8 Initial work on sprites and texture system --- source/Utils.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source/Utils.hpp') diff --git a/source/Utils.hpp b/source/Utils.hpp index 03fdfed..6239667 100644 --- a/source/Utils.hpp +++ b/source/Utils.hpp @@ -1,7 +1,10 @@ #pragma once +#include #include +#include #include +#include namespace Utils { @@ -18,4 +21,33 @@ constexpr float Abs(float v) noexcept { return v < 0.0f ? -v : v; } +bool InRangeInclusive(int n, int lower, int upper); +bool LineContains(glm::ivec2 p1, glm::ivec2 p2, glm::ivec2 candidate); +bool IsColinear(glm::ivec2 p1, glm::ivec2 p2); + } // namespace Utils + +struct StringHash { + using is_transparent = void; + + std::size_t operator()(const std::string& key) const { return robin_hood::hash_bytes(key.c_str(), key.size()); } + std::size_t operator()(std::string_view key) const { return robin_hood::hash_bytes(key.data(), key.size()); } + std::size_t operator()(const char* key) const { return robin_hood::hash_bytes(key, std::strlen(key)); } +}; + +struct StringEqual { + using is_transparent = int; + + bool operator()(std::string_view lhs, const std::string& rhs) const { + const std::string_view view = rhs; + return lhs == view; + } + + bool operator()(const char* lhs, const std::string& rhs) const { + return std::strcmp(lhs, rhs.c_str()) == 0; + } + + bool operator()(const std::string& lhs, const std::string& rhs) const { + return lhs == rhs; + } +}; -- cgit v1.2.3-70-g09d2