summaryrefslogtreecommitdiff
path: root/include/llmr/util/vec.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/llmr/util/vec.hpp')
-rw-r--r--include/llmr/util/vec.hpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/llmr/util/vec.hpp b/include/llmr/util/vec.hpp
index 445160f15d..0191e3868d 100644
--- a/include/llmr/util/vec.hpp
+++ b/include/llmr/util/vec.hpp
@@ -4,6 +4,7 @@
#include <limits>
#include <type_traits>
#include <cmath>
+#include <cstdint>
namespace llmr {
@@ -15,10 +16,17 @@ struct vec2 {
T x, y;
inline vec2() {}
+
+ template<typename U = T, typename std::enable_if<std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
inline vec2(null) : x(std::numeric_limits<T>::quiet_NaN()), y(std::numeric_limits<T>::quiet_NaN()) {}
+ template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline vec2(null) : x(std::numeric_limits<T>::min()), y(std::numeric_limits<T>::min()) {}
+
inline vec2(const vec2& o) : x(o.x), y(o.y) {}
+
inline vec2(T x, T y) : x(x), y(y) {}
+
inline bool operator==(const vec2& rhs) const {
return x == rhs.x && y == rhs.y;
}
@@ -27,6 +35,11 @@ struct vec2 {
inline operator bool() const {
return !isnan(x) && !isnan(y);
}
+
+ template<typename U = T, typename std::enable_if<!std::numeric_limits<U>::has_quiet_NaN, int>::type = 0>
+ inline operator bool() const {
+ return x != std::numeric_limits<T>::min() && y != std::numeric_limits<T>::min();
+ }
};
template <typename T = double>
@@ -59,6 +72,8 @@ struct box {
vec2<double> center;
};
+typedef vec2<int16_t> Coordinate;
+
}
#endif