Add square magnitude 3 operator
This commit is contained in:
parent
2010504e84
commit
7f0d686a64
@ -101,6 +101,12 @@ vf4 magnitude3(vf4 v) noexcept
|
||||
return _mm_sqrt_ps(dot3(v, v));
|
||||
}
|
||||
|
||||
[[nodiscard]] TNVX_INLINE
|
||||
vf4 magnitude3_sq(vf4 v) noexcept
|
||||
{
|
||||
return dot3(v, v);
|
||||
}
|
||||
|
||||
[[nodiscard]] TNVX_INLINE
|
||||
vf4 norm3(vf4 v) noexcept
|
||||
{
|
||||
|
||||
35
src/tenvex/expressions/magnitude3_sq.h
Normal file
35
src/tenvex/expressions/magnitude3_sq.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "core.h"
|
||||
#include "expression.h"
|
||||
#include "traits.h"
|
||||
#include "concepts.h"
|
||||
|
||||
namespace tnvx
|
||||
{
|
||||
|
||||
template<vec_expr E>
|
||||
struct Magn3Sq : Expr<Magn3Sq<E>>
|
||||
{
|
||||
TNVX_INLINE
|
||||
explicit Magn3Sq(const E& e) noexcept;
|
||||
|
||||
[[nodiscard]] TNVX_INLINE
|
||||
vf4 eval() const noexcept;
|
||||
|
||||
[[nodiscard]] TNVX_INLINE
|
||||
operator float() const noexcept;
|
||||
|
||||
private:
|
||||
tnvx_ref_or_value_t<E> _e;
|
||||
};
|
||||
|
||||
template<vec_expr E> inline constexpr bool is_scalar_expr<Magn3Sq<E>> = true;
|
||||
|
||||
template<vec_expr E>
|
||||
[[nodiscard]] TNVX_INLINE
|
||||
Magn3Sq<E> magnitude3_sq(const E& e) noexcept;
|
||||
|
||||
}
|
||||
|
||||
#include "magnitude3_sq_impl.hpp"
|
||||
37
src/tenvex/expressions/magnitude3_sq_impl.hpp
Normal file
37
src/tenvex/expressions/magnitude3_sq_impl.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "magnitude3_sq.h"
|
||||
|
||||
namespace tnvx
|
||||
{
|
||||
|
||||
template<vec_expr E>
|
||||
TNVX_INLINE
|
||||
Magn3Sq<E>::Magn3Sq(const E& e) noexcept
|
||||
: _e(e)
|
||||
{
|
||||
}
|
||||
|
||||
template<vec_expr E>
|
||||
TNVX_INLINE
|
||||
vf4 Magn3Sq<E>::eval() const noexcept
|
||||
{
|
||||
return detail::magnitude3_sq(_e.eval());
|
||||
}
|
||||
|
||||
template<vec_expr E>
|
||||
TNVX_INLINE
|
||||
Magn3Sq<E>::operator float() const noexcept
|
||||
{
|
||||
return detail::to_float(eval());
|
||||
}
|
||||
|
||||
template<vec_expr E>
|
||||
TNVX_INLINE
|
||||
Magn3Sq<E> magnitude3_sq(const E& e) noexcept
|
||||
{
|
||||
return Magn3Sq<E>(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -9,6 +9,7 @@
|
||||
#include "expressions/dot3.h"
|
||||
#include "expressions/dot4.h"
|
||||
#include "expressions/magnitude3.h"
|
||||
#include "expressions/magnitude3_sq.h"
|
||||
#include "expressions/norm3.h"
|
||||
#include "expressions/cross3.h"
|
||||
#include "expressions/vec4.h"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user