summaryrefslogtreecommitdiffstats
path: root/include/mm/mmvec.hpp
diff options
context:
space:
mode:
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);