mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 22:19:51 +07:00
mark constexpr all generic functions
This commit is contained in:
@@ -294,7 +294,7 @@ namespace vmath_hpp
|
||||
// rotate
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate(const qua<T>& q) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate(const qua<T>& q) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/
|
||||
|
||||
@@ -324,12 +324,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate(const mat<T, 4>& m, const qua<T>& q) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate(const mat<T, 4>& m, const qua<T>& q) {
|
||||
return m * rotate(q);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate(T angle, const vec<T, 3>& axis) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate(T angle, const vec<T, 3>& axis) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/
|
||||
|
||||
@@ -362,12 +362,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate(const mat<T, 4>& m, T angle, const vec<T, 3>& axis) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate(const mat<T, 4>& m, T angle, const vec<T, 3>& axis) {
|
||||
return m * rotate(angle, axis);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_x(T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_x(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
|
||||
|
||||
@@ -381,12 +381,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_x(const mat<T, 4>& m, T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_x(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate_x(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_y(T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_y(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
|
||||
|
||||
@@ -400,12 +400,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_y(const mat<T, 4>& m, T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_y(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate_y(angle);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_z(T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_z(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
|
||||
|
||||
@@ -419,7 +419,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> rotate_z(const mat<T, 4>& m, T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 4> rotate_z(const mat<T, 4>& m, T angle) {
|
||||
return m * rotate_z(angle);
|
||||
}
|
||||
|
||||
@@ -455,7 +455,7 @@ namespace vmath_hpp
|
||||
// look_at
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> look_at_lh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up) {
|
||||
[[nodiscard]] constexpr mat<T, 4> look_at_lh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up) {
|
||||
/// REFERENCE:
|
||||
/// https://www.euclideanspace.com/maths/algebra/vectors/lookat/
|
||||
|
||||
@@ -475,7 +475,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> look_at_rh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up) {
|
||||
[[nodiscard]] constexpr mat<T, 4> look_at_rh(const vec<T, 3>& eye, const vec<T, 3>& at, const vec<T, 3>& up) {
|
||||
/// REFERENCE:
|
||||
/// https://www.euclideanspace.com/maths/algebra/vectors/lookat/
|
||||
|
||||
@@ -532,7 +532,7 @@ namespace vmath_hpp
|
||||
// rotate
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 3> rotate(T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
|
||||
|
||||
@@ -545,7 +545,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 3> rotate(const mat<T, 3>& m, T angle) {
|
||||
[[nodiscard]] constexpr mat<T, 3> rotate(const mat<T, 3>& m, T angle) {
|
||||
return m * rotate(angle);
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ namespace vmath_hpp
|
||||
// orthographic
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> orthographic_lh(T width, T height, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> orthographic_lh(T width, T height, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixortholh
|
||||
|
||||
@@ -668,7 +668,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> orthographic_rh(T width, T height, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> orthographic_rh(T width, T height, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthorh
|
||||
|
||||
@@ -689,7 +689,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> orthographic_lh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> orthographic_lh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthooffcenterlh
|
||||
|
||||
@@ -705,7 +705,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> orthographic_rh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> orthographic_rh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixorthooffcenterrh
|
||||
|
||||
@@ -723,7 +723,7 @@ namespace vmath_hpp
|
||||
// perspective
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_lh(T width, T height, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_lh(T width, T height, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivelh
|
||||
|
||||
@@ -740,7 +740,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_rh(T width, T height, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_rh(T width, T height, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectiverh
|
||||
|
||||
@@ -757,7 +757,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_lh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_lh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectiveoffcenterlh
|
||||
|
||||
@@ -774,7 +774,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_rh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_rh(T left, T right, T bottom, T top, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectiveoffcenterrh
|
||||
|
||||
@@ -791,7 +791,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_fov_lh(T fovy, T aspect, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_fov_lh(T fovy, T aspect, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovlh
|
||||
|
||||
@@ -808,7 +808,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] mat<T, 4> perspective_fov_rh(T fovy, T aspect, T znear, T zfar) {
|
||||
[[nodiscard]] constexpr mat<T, 4> perspective_fov_rh(T fovy, T aspect, T znear, T zfar) {
|
||||
/// REFERENCE:
|
||||
/// https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxmatrixperspectivefovrh
|
||||
|
||||
@@ -833,7 +833,7 @@ namespace vmath_hpp
|
||||
// angle
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] T angle(const vec<T, Size>& x, const vec<T, Size>& y) {
|
||||
[[nodiscard]] constexpr T angle(const vec<T, Size>& x, const vec<T, Size>& y) {
|
||||
const T rs = rsqrt(length2(x) * length2(y));
|
||||
return acos(clamp(dot(x, y) * rs, -T{1}, T{1}));
|
||||
}
|
||||
@@ -841,7 +841,7 @@ namespace vmath_hpp
|
||||
// rotate
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 2> rotate(const vec<T, 2>& v, T angle) {
|
||||
[[nodiscard]] constexpr vec<T, 2> rotate(const vec<T, 2>& v, T angle) {
|
||||
const auto [s, c] = sincos(angle);
|
||||
return {
|
||||
v.x * c - v.y * s,
|
||||
@@ -849,27 +849,27 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 3> rotate_x(const vec<T, 3>& v, T angle) {
|
||||
[[nodiscard]] constexpr vec<T, 3> rotate_x(const vec<T, 3>& v, T angle) {
|
||||
return v * qrotate(angle, unit3_x<T>);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 3> rotate_y(const vec<T, 3>& v, T angle) {
|
||||
[[nodiscard]] constexpr vec<T, 3> rotate_y(const vec<T, 3>& v, T angle) {
|
||||
return v * qrotate(angle, unit3_y<T>);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 3> rotate_z(const vec<T, 3>& v, T angle) {
|
||||
[[nodiscard]] constexpr vec<T, 3> rotate_z(const vec<T, 3>& v, T angle) {
|
||||
return v * qrotate(angle, unit3_z<T>);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, const qua<T>& q) {
|
||||
[[nodiscard]] constexpr vec<T, 3> rotate(const vec<T, 3>& v, const qua<T>& q) {
|
||||
return v * q;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] vec<T, 3> rotate(const vec<T, 3>& v, T angle, const vec<T, 3>& axis) {
|
||||
[[nodiscard]] constexpr vec<T, 3> rotate(const vec<T, 3>& v, T angle, const vec<T, 3>& axis) {
|
||||
return v * qrotate(angle, axis);
|
||||
}
|
||||
|
||||
@@ -897,7 +897,7 @@ namespace vmath_hpp
|
||||
// qrotate
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(const mat<T, 3>& m) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(const mat<T, 3>& m) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
|
||||
|
||||
@@ -915,12 +915,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(const qua<T>& q, const mat<T, 3>& m) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(const qua<T>& q, const mat<T, 3>& m) {
|
||||
return q * qrotate(m);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(const vec<T, 3>& from, const vec<T, 3>& to) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(const vec<T, 3>& from, const vec<T, 3>& to) {
|
||||
/// REFERENCE:
|
||||
/// http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
|
||||
|
||||
@@ -937,12 +937,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(const qua<T>& q, const vec<T, 3>& from, const vec<T, 3>& to) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(const qua<T>& q, const vec<T, 3>& from, const vec<T, 3>& to) {
|
||||
return q * qrotate(from, to);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(T angle, const vec<T, 3>& axis) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(T angle, const vec<T, 3>& axis) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/
|
||||
|
||||
@@ -953,12 +953,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate(const qua<T>& q, T angle, const vec<T, 3>& axis) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate(const qua<T>& q, T angle, const vec<T, 3>& axis) {
|
||||
return q * qrotate(angle, axis);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_x(T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_x(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/
|
||||
|
||||
@@ -968,12 +968,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_x(const qua<T>& q, T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_x(const qua<T>& q, T angle) {
|
||||
return qrotate(q, angle, unit3_x<T>);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_y(T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_y(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/
|
||||
|
||||
@@ -983,12 +983,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_y(const qua<T>& q, T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_y(const qua<T>& q, T angle) {
|
||||
return qrotate(q, angle, unit3_y<T>);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_z(T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_z(T angle) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/
|
||||
|
||||
@@ -998,14 +998,14 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qrotate_z(const qua<T>& q, T angle) {
|
||||
[[nodiscard]] constexpr qua<T> qrotate_z(const qua<T>& q, T angle) {
|
||||
return qrotate(q, angle, unit3_z<T>);
|
||||
}
|
||||
|
||||
// look_at
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qlook_at_lh(const vec<T, 3>& dir, const vec<T, 3>& up) {
|
||||
[[nodiscard]] constexpr qua<T> qlook_at_lh(const vec<T, 3>& dir, const vec<T, 3>& up) {
|
||||
/// REFERENCE:
|
||||
/// https://www.euclideanspace.com/maths/algebra/vectors/lookat/
|
||||
|
||||
@@ -1020,7 +1020,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> qlook_at_rh(const vec<T, 3>& dir, const vec<T, 3>& up) {
|
||||
[[nodiscard]] constexpr qua<T> qlook_at_rh(const vec<T, 3>& dir, const vec<T, 3>& up) {
|
||||
/// REFERENCE:
|
||||
/// https://www.euclideanspace.com/maths/algebra/vectors/lookat/
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
normalize(T x) noexcept {
|
||||
constexpr normalize(T x) noexcept {
|
||||
return x * rlength(x);
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ namespace vmath_hpp
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr std::size_t size = Size;
|
||||
static inline constexpr std::size_t size = Size;
|
||||
public:
|
||||
using base_type::mat_base;
|
||||
using base_type::rows;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace vmath_hpp
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr std::size_t size = 4;
|
||||
static inline constexpr std::size_t size = 4;
|
||||
public:
|
||||
using base_type::qua_base;
|
||||
using base_type::operator[];
|
||||
|
||||
@@ -203,24 +203,24 @@ namespace vmath_hpp
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> lerp(const qua<T>& xs, const qua<T>& ys, T a) {
|
||||
[[nodiscard]] constexpr qua<T> lerp(const qua<T>& xs, const qua<T>& ys, T a) {
|
||||
return qua(lerp(vec{xs}, vec{ys}, a));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> lerp(const qua<T>& xs, const qua<T>& ys, T x_a, T y_a) {
|
||||
[[nodiscard]] constexpr qua<T> lerp(const qua<T>& xs, const qua<T>& ys, T x_a, T y_a) {
|
||||
return qua(lerp(vec{xs}, vec{ys}, x_a, y_a));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> nlerp(const qua<T>& unit_xs, const qua<T>& unit_ys, T a) {
|
||||
[[nodiscard]] constexpr qua<T> nlerp(const qua<T>& unit_xs, const qua<T>& unit_ys, T a) {
|
||||
const T xs_scale = T{1} - a;
|
||||
const T ys_scale = a * sign(dot(unit_xs, unit_ys));
|
||||
return normalize(lerp(unit_xs, unit_ys, xs_scale, ys_scale));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> slerp(const qua<T>& unit_xs, const qua<T>& unit_ys, T a) {
|
||||
[[nodiscard]] constexpr qua<T> slerp(const qua<T>& unit_xs, const qua<T>& unit_ys, T a) {
|
||||
/// REFERENCE:
|
||||
/// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
|
||||
|
||||
@@ -255,12 +255,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] T length(const qua<T>& xs) {
|
||||
[[nodiscard]] constexpr T length(const qua<T>& xs) {
|
||||
return length(vec{xs});
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] T rlength(const qua<T>& xs) {
|
||||
[[nodiscard]] constexpr T rlength(const qua<T>& xs) {
|
||||
return rlength(vec{xs});
|
||||
}
|
||||
|
||||
@@ -275,13 +275,13 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] T distance(const qua<T>& xs, const qua<T>& ys) {
|
||||
[[nodiscard]] constexpr T distance(const qua<T>& xs, const qua<T>& ys) {
|
||||
const qua zs = xs * conjugate(ys);
|
||||
return T{2} * atan2(length(zs.v), abs(zs.s));
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] qua<T> normalize(const qua<T>& xs) {
|
||||
[[nodiscard]] constexpr qua<T> normalize(const qua<T>& xs) {
|
||||
return qua(normalize(vec{xs}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace vmath_hpp
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr std::size_t size = Size;
|
||||
static inline constexpr std::size_t size = Size;
|
||||
public:
|
||||
using base_type::vec_base;
|
||||
using base_type::operator[];
|
||||
|
||||
@@ -471,61 +471,61 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> floor(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> floor(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return floor(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> trunc(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> trunc(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return trunc(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> round(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> round(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return round(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> ceil(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> ceil(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return ceil(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> fract(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> fract(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return fract(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> fmod(const vec<T, Size>& xs, T y) {
|
||||
[[nodiscard]] constexpr vec<T, Size> fmod(const vec<T, Size>& xs, T y) {
|
||||
return map_join([y](T x) { return fmod(x, y); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> fmod(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
[[nodiscard]] constexpr vec<T, Size> fmod(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y) { return fmod(x, y); }, xs, ys);
|
||||
}
|
||||
|
||||
namespace impl
|
||||
{
|
||||
template < typename T, std::size_t Size, std::size_t... Is >
|
||||
VMATH_HPP_FORCE_INLINE
|
||||
constexpr VMATH_HPP_FORCE_INLINE
|
||||
vec<T, Size> modf_impl(const vec<T, Size>& xs, vec<T, Size>* is, std::index_sequence<Is...>) {
|
||||
return { modf(xs[Is], &(*is)[Is])... };
|
||||
}
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
vec<T, Size> modf(const vec<T, Size>& xs, vec<T, Size>* is) {
|
||||
constexpr vec<T, Size> modf(const vec<T, Size>& xs, vec<T, Size>* is) {
|
||||
return impl::modf_impl(xs, is, std::make_index_sequence<Size>{});
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> copysign(const vec<T, Size>& xs, T s) {
|
||||
[[nodiscard]] constexpr vec<T, Size> copysign(const vec<T, Size>& xs, T s) {
|
||||
return map_join([s](T x) { return copysign(x, s); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> copysign(const vec<T, Size>& xs, const vec<T, Size>& ss) {
|
||||
[[nodiscard]] constexpr vec<T, Size> copysign(const vec<T, Size>& xs, const vec<T, Size>& ss) {
|
||||
return map_join([](T x, T s) { return copysign(x, s); }, xs, ss);
|
||||
}
|
||||
|
||||
@@ -634,7 +634,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> fma(const vec<T, Size>& as, const vec<T, Size>& bs, const vec<T, Size>& cs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> fma(const vec<T, Size>& as, const vec<T, Size>& bs, const vec<T, Size>& cs) {
|
||||
return map_join([](T a, T b, T c) { return fma(a, b, c); }, as, bs, cs);
|
||||
}
|
||||
}
|
||||
@@ -656,77 +656,77 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> sin(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> sin(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return sin(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> cos(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> cos(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return cos(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> tan(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> tan(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return tan(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> asin(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> asin(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return asin(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> acos(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> acos(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return acos(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> atan(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> atan(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return atan(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> atan2(const vec<T, Size>& ys, const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> atan2(const vec<T, Size>& ys, const vec<T, Size>& xs) {
|
||||
return map_join([](T y, T x) { return atan2(y, x); }, ys, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> sinh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> sinh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return sinh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> cosh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> cosh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return cosh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> tanh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> tanh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return tanh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> asinh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> asinh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return asinh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> acosh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> acosh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return acosh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> atanh(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> atanh(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return atanh(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] std::pair<vec<T, Size>, vec<T, Size>> sincos(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr std::pair<vec<T, Size>, vec<T, Size>> sincos(const vec<T, Size>& xs) {
|
||||
return { sin(xs), cos(xs) };
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
void sincos(const vec<T, Size>& xs, vec<T, Size>* ss, vec<T, Size>* cs) {
|
||||
constexpr void sincos(const vec<T, Size>& xs, vec<T, Size>* ss, vec<T, Size>* cs) {
|
||||
*ss = sin(xs);
|
||||
*cs = cos(xs);
|
||||
}
|
||||
@@ -739,37 +739,37 @@ namespace vmath_hpp
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> pow(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
[[nodiscard]] constexpr vec<T, Size> pow(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return map_join([](T x, T y) { return pow(x, y); }, xs, ys);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> exp(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> exp(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return exp(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> log(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> log(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return log(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> exp2(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> exp2(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return exp2(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> log2(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> log2(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return log2(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> sqrt(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> sqrt(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return sqrt(x); }, xs);
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> rsqrt(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> rsqrt(const vec<T, Size>& xs) {
|
||||
return map_join([](T x) { return rsqrt(x); }, xs);
|
||||
}
|
||||
}
|
||||
@@ -788,12 +788,12 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] T length(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr T length(const vec<T, Size>& xs) {
|
||||
return sqrt(dot(xs, xs));
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] T rlength(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr T rlength(const vec<T, Size>& xs) {
|
||||
return rsqrt(dot(xs, xs));
|
||||
}
|
||||
|
||||
@@ -808,7 +808,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] T distance(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
[[nodiscard]] constexpr T distance(const vec<T, Size>& xs, const vec<T, Size>& ys) {
|
||||
return length(ys - xs);
|
||||
}
|
||||
|
||||
@@ -831,7 +831,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> normalize(const vec<T, Size>& xs) {
|
||||
[[nodiscard]] constexpr vec<T, Size> normalize(const vec<T, Size>& xs) {
|
||||
return xs * rlength(xs);
|
||||
}
|
||||
|
||||
@@ -846,7 +846,7 @@ namespace vmath_hpp
|
||||
}
|
||||
|
||||
template < typename T, std::size_t Size >
|
||||
[[nodiscard]] vec<T, Size> refract(const vec<T, Size>& i, const vec<T, Size>& n, T eta) {
|
||||
[[nodiscard]] constexpr vec<T, Size> refract(const vec<T, Size>& i, const vec<T, Size>& n, T eta) {
|
||||
const T d = dot(n, i);
|
||||
const T k = T{1} - sqr(eta) * (T{1} - sqr(d));
|
||||
return k < T{0} ? vec<T, Size>{T{0}} : (eta * i - (eta * d + sqrt(k)) * n);
|
||||
|
||||
@@ -129,7 +129,7 @@ TEST_CASE("vmath/fun") {
|
||||
STATIC_CHECK(distance2(-5.f, -10.f) == uapprox(25.f));
|
||||
|
||||
STATIC_CHECK(dot(2.f, 5.f) == uapprox(10.f));
|
||||
CHECK(normalize(0.5f) == uapprox(1.f));
|
||||
STATIC_CHECK(normalize(0.5f) == uapprox(1.f));
|
||||
|
||||
STATIC_CHECK(faceforward(1.f, 2.f, 3.f) == uapprox(-1.f));
|
||||
STATIC_CHECK(reflect(1.f, 2.f) == uapprox(-7.f));
|
||||
|
||||
Reference in New Issue
Block a user