Skip to content

Commit

Permalink
Enable vector conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko committed Jul 13, 2023
1 parent a4a452c commit 4892489
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Orbitersdk/include/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,36 @@ template<typename V, if_vector4(V)> constexpr auto exp(const V& v) { return V{st
*/
template<typename V, if_vector(V)> constexpr auto lerp(const V& a, const V& b, dtype<V> t) { return a + t * (b - a); }

/**
* @brief type conversions
*/
template<typename U, typename V, if_vector2(U), if_vector2(V)>
constexpr auto morph_to(const V& v) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y)}; }

template<typename U, typename V, if_vector3(U), if_vector3(V)>
constexpr auto morph_to(const V& v) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y), static_cast<dtype<U>>(v.z)}; }

template<typename U, typename V, if_vector4(U), if_vector4(V)>
constexpr auto morph_to(const V& v) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y), static_cast<dtype<U>>(v.z), static_cast<dtype<U>>(v.w)}; }

/**
* @brief reduction
*/
template<typename U, typename V, if_vector2(U), if_vector3(V)>
constexpr auto morph_to(const V& v) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y)}; }

template<typename U, typename V, if_vector3(U), if_vector4(V)>
constexpr auto morph_to(const V& v) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y), static_cast<dtype<U>>(v.z)}; }

/**
* @brief expansion
*/
template<typename U, typename V, if_vector3(U), if_vector2(V)>
constexpr auto morph_to(const V& v, dtype<U> z = 0) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y), z}; }

template<typename U, typename V, if_vector4(U), if_vector3(V)>
constexpr auto morph_to(const V& v, dtype<U> w = 0) { return U{static_cast<dtype<U>>(v.x), static_cast<dtype<U>>(v.y), static_cast<dtype<U>>(v.z), w}; }

/**
* @brief vector norm/length (squared and not)
*/
Expand Down

0 comments on commit 4892489

Please sign in to comment.