VulkanEngine 0.1
Graphics engine using Vulkan
Loading...
Searching...
No Matches
Utilities.h
1// Copyright (c) 2024 Michael Carlie. All Rights Reserved.
2//
3// This software is released under the MIT License.
4// https://opensource.org/licenses/MIT
5
6#ifndef INCLUDE_VULKANENGINE_UTILITIES_H_
7#define INCLUDE_VULKANENGINE_UTILITIES_H_
8
9#include <VulkanEngine/Constants.h>
10
11#include <Eigen/Eigen>
12#include <tuple>
13
14namespace VulkanEngine {
15
17namespace Utilities {
18
20template <typename T>
21T toRadians(const T& val) {
22 return val * Constants::pi<T>() / static_cast<T>(180);
23}
24
29template <class T>
30inline void hashCombine(size_t* seed, const T& v) {
31 *seed ^= std::hash<T>()(v) + 0x9e3779b9 + (*seed << 6) + (*seed >> 2);
32}
33
36template <std::size_t i = 0, class C, class... Types>
37typename std::enable_if<i >= sizeof...(Types), C>::type tupleForEach(
38 const std::tuple<Types...>& t, // NOLINT(whitespace/indent_namespace)
39 const C& op) { // NOLINT(whitespace/indent_namespace)
40 return op;
41}
42
45template <size_t i = 0, class C, class... Types>
46 typename std::enable_if < // NOLINT(whitespace/indent_namespace)
47 i<sizeof...(Types), C>::type // NOLINT(whitespace/indent_namespace)
48 tupleForEach( // NOLINT(whitespace/indent_namespace)
49 const std::tuple<Types...>& t, // NOLINT(whitespace/indent_namespace)
50 const C& op) { // NOLINT(whitespace/indent_namespace)
51 op(std::get<i>(t));
52 return tupleForEach<i + 1, C, Types...>(t, op);
53}
54
55} // namespace Utilities
56
57} // namespace VulkanEngine
58
60template <typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows,
61 int _MaxCols>
62struct std::hash<
63 Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> {
64 typedef Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> T;
65 size_t operator()(T const& matrix) const {
66 size_t seed = 0;
67 for (int i = 0; i < matrix.size(); ++i) {
68 auto elem = *(matrix.data() + i);
69 VulkanEngine::Utilities::hashCombine<typename T::Scalar>(&seed, elem);
70 }
71 return seed;
72 }
73};
74
77template <class... TupleArgs>
78struct std::hash<std::tuple<TupleArgs...>> {
79 size_t operator()(const std::tuple<TupleArgs...>& tuple_value) const {
80 size_t seed = 0;
81 auto visitor = [&seed](const auto& element) {
83 };
84 VulkanEngine::Utilities::tupleForEach(tuple_value, visitor);
85 return seed;
86 }
87};
88
89#endif // INCLUDE_VULKANENGINE_UTILITIES_H_
T toRadians(const T &val)
Convert degrees to radian.
Definition: Utilities.h:21
void hashCombine(size_t *seed, const T &v)
Definition: Utilities.h:30
TODO development of this class is in progress.
Definition: Attribute.h:13