summaryrefslogtreecommitdiffstats
path: root/include/mm/mmvec.hpp
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2019-07-10 10:24:37 +0200
committerancarola <raffaele.ancarola@epfl.ch>2019-07-10 10:24:37 +0200
commiteb5cdb04efc9984d0937b65620606f8043dd1831 (patch)
tree46b750f4f2228e532e2041d873b37caf2940d15c /include/mm/mmvec.hpp
parentSmall correction on basic multiplication (diff)
downloadlibmm-eb5cdb04efc9984d0937b65620606f8043dd1831.tar.gz
libmm-eb5cdb04efc9984d0937b65620606f8043dd1831.zip
Implicit convertion to basic_vec to vec2 or vec3
Diffstat (limited to 'include/mm/mmvec.hpp')
-rw-r--r--include/mm/mmvec.hpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/include/mm/mmvec.hpp b/include/mm/mmvec.hpp
index 1939388..da9040d 100644
--- a/include/mm/mmvec.hpp
+++ b/include/mm/mmvec.hpp
@@ -44,6 +44,27 @@ struct mm::basic_vec : public std::array<T, d> {
using type = T;
static constexpr std::size_t dimensions = d;
+ // convertions
+ static inline constexpr bool is_vec2() {
+ return d == 2;
+ }
+
+ static inline constexpr bool is_vec3() {
+ return d == 3;
+ }
+
+ operator mm::vec2<T>()
+ {
+ static_assert(is_vec2(), "Invalid cast to two dimensional vector");
+ return static_cast<mm::vec2<T>>(*this);
+ }
+
+ operator mm::vec3<T>()
+ {
+ static_assert(is_vec3(), "Invalid cast to three dimensional vector");
+ return static_cast<mm::vec3<T>>(*this);
+ }
+
// TODO: template away these
static constexpr T null_element = static_cast<T>(0);
static constexpr T unit_element = static_cast<T>(1);