From eb5cdb04efc9984d0937b65620606f8043dd1831 Mon Sep 17 00:00:00 2001 From: ancarola Date: Wed, 10 Jul 2019 10:24:37 +0200 Subject: Implicit convertion to basic_vec to vec2 or vec3 --- include/mm/mmvec.hpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/mm/mmvec.hpp') 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 { 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() + { + static_assert(is_vec2(), "Invalid cast to two dimensional vector"); + return static_cast>(*this); + } + + operator mm::vec3() + { + static_assert(is_vec3(), "Invalid cast to three dimensional vector"); + return static_cast>(*this); + } + // TODO: template away these static constexpr T null_element = static_cast(0); static constexpr T unit_element = static_cast(1); -- cgit v1.2.1