code style fixes

This commit is contained in:
BlackMATov
2021-02-13 12:40:48 +07:00
parent bcacd7b60e
commit bbaa269840
5 changed files with 166 additions and 216 deletions

View File

@@ -242,13 +242,13 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr mat<T, 4> translate(const vec<T, 3>& v) {
return translate(v.x, v.y, v.z);
[[nodiscard]] constexpr mat<T, 4> translate(const mat<T, 4>& m, T x, T y, T z) {
return m * translate(x, y, z);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 4> translate(const mat<T, 4>& m, T x, T y, T z) {
return m * translate(x, y, z);
[[nodiscard]] constexpr mat<T, 4> translate(const vec<T, 3>& v) {
return translate(v.x, v.y, v.z);
}
template < typename T >
@@ -288,6 +288,11 @@ namespace vmath_hpp
0, 0, 0, 1};
}
template < typename T >
[[nodiscard]] 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) {
/// REFERENCE:
@@ -326,11 +331,6 @@ namespace vmath_hpp
return m * rotate(angle, axis);
}
template < typename T >
[[nodiscard]] 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_x(T angle) {
/// REFERENCE:
@@ -403,13 +403,13 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr mat<T, 4> scale(const vec<T, 3>& v) {
return scale(v.x, v.y, v.z);
[[nodiscard]] constexpr mat<T, 4> scale(const mat<T, 4>& m, T x, T y, T z) {
return m * scale(x, y, z);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 4> scale(const mat<T, 4>& m, T x, T y, T z) {
return m * scale(x, y, z);
[[nodiscard]] constexpr mat<T, 4> scale(const vec<T, 3>& v) {
return scale(v.x, v.y, v.z);
}
template < typename T >
@@ -480,13 +480,13 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> translate(const vec<T, 2>& v) {
return translate(v.x, v.y);
[[nodiscard]] constexpr mat<T, 3> translate(const mat<T, 3>& m, T x, T y) {
return m * translate(x, y);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> translate(const mat<T, 3>& m, T x, T y) {
return m * translate(x, y);
[[nodiscard]] constexpr mat<T, 3> translate(const vec<T, 2>& v) {
return translate(v.x, v.y);
}
template < typename T >
@@ -528,13 +528,13 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale(const vec<T, 2>& v) {
return scale(v.x, v.y);
[[nodiscard]] constexpr mat<T, 3> scale(const mat<T, 3>& m, T x, T y) {
return m * scale(x, y);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> scale(const mat<T, 3>& m, T x, T y) {
return m * scale(x, y);
[[nodiscard]] constexpr mat<T, 3> scale(const vec<T, 2>& v) {
return scale(v.x, v.y);
}
template < typename T >
@@ -556,13 +556,13 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> shear(const vec<T, 2>& v) {
return shear(v.x, v.y);
[[nodiscard]] constexpr mat<T, 3> shear(const mat<T, 3>& m, T x, T y) {
return m * shear(x, y);
}
template < typename T >
[[nodiscard]] constexpr mat<T, 3> shear(const mat<T, 3>& m, T x, T y) {
return m * shear(x, y);
[[nodiscard]] constexpr mat<T, 3> shear(const vec<T, 2>& v) {
return shear(v.x, v.y);
}
template < typename T >
@@ -842,7 +842,7 @@ namespace vmath_hpp
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> project(const vec<T, Size>& v, const vec<T, Size>& normal) {
return dot(v, normal) / dot(normal, normal) * normal;
return dot(v, normal) * rcp(length2(normal)) * normal;
}
// perpendicular

View File

@@ -137,7 +137,7 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
constexpr smoothstep(T edge0, T edge1, T x) noexcept {
const T t = clamp((x - edge0) / (edge1 - edge0), T(0), T(1));
const T t = clamp((x - edge0) * rcp(edge1 - edge0), T(0), T(1));
return t * t * (T(3) - T(2) * t);
}
@@ -376,7 +376,7 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
normalize(T x) noexcept {
return x * rsqrt(dot(x, x));
return x * rsqrt(length2(x));
}
template < typename T >

View File

@@ -501,22 +501,16 @@ namespace vmath_hpp
namespace vmath_hpp
{
// any
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool any(const mat<T, Size>& xs) {
return fold_join([](bool acc, const vec<T, Size>& x){ return acc || any(x); }, false, xs);
}
// all
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool all(const mat<T, Size>& xs) {
return fold_join([](bool acc, const vec<T, Size>& x){ return acc && all(x); }, true, xs);
}
// approx
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> approx(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return approx(x, y); }, xs, ys);
@@ -527,43 +521,31 @@ namespace vmath_hpp
return map_join([epsilon](const vec<T, Size>& x, const vec<T, Size>& y){ return approx(x, y, epsilon); }, xs, ys);
}
// less
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return less(x, y); }, xs, ys);
}
// less_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> less_equal(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return less_equal(x, y); }, xs, ys);
}
// greater
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return greater(x, y); }, xs, ys);
}
// greater_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> greater_equal(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return greater_equal(x, y); }, xs, ys);
}
// equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return equal_to(x, y); }, xs, ys);
}
// not_equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr mat<bool, Size> not_equal_to(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return not_equal_to(x, y); }, xs, ys);

View File

@@ -241,7 +241,7 @@ namespace vmath_hpp
}
template < typename T >
[[nodiscard]] constexpr qua<T> normalize(const qua<T>& xs) {
[[nodiscard]] qua<T> normalize(const qua<T>& xs) {
return qua(normalize(vec{xs}));
}
}
@@ -252,8 +252,6 @@ namespace vmath_hpp
namespace vmath_hpp
{
// approx
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> approx(const qua<T>& xs, const qua<T>& ys) {
return approx(vec{xs}, vec{ys});
@@ -264,43 +262,31 @@ namespace vmath_hpp
return approx(vec{xs}, vec{ys}, epsilon);
}
// less
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> less(const qua<T>& xs, const qua<T>& ys) {
return less(vec{xs}, vec{ys});
}
// less_equal
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> less_equal(const qua<T>& xs, const qua<T>& ys) {
return less_equal(vec{xs}, vec{ys});
}
// greater
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> greater(const qua<T>& xs, const qua<T>& ys) {
return greater(vec{xs}, vec{ys});
}
// greater_equal
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> greater_equal(const qua<T>& xs, const qua<T>& ys) {
return greater_equal(vec{xs}, vec{ys});
}
// equal_to
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> equal_to(const qua<T>& xs, const qua<T>& ys) {
return equal_to(vec{xs}, vec{ys});
}
// not_equal_to
template < typename T >
[[nodiscard]] constexpr vec<bool, 4> not_equal_to(const qua<T>& xs, const qua<T>& ys) {
return not_equal_to(vec{xs}, vec{ys});
@@ -324,6 +310,6 @@ namespace vmath_hpp
template < typename T >
[[nodiscard]] constexpr qua<T> inverse(const qua<T>& q) {
return conjugate(q) * rcp(dot(q, q));
return conjugate(q) * rcp(length2(q));
}
}

View File

@@ -495,141 +495,6 @@ namespace vmath_hpp
}
}
//
// Angle and Trigonometric Functions
//
namespace vmath_hpp
{
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> radians(const vec<T, Size>& degrees) {
return map_join([](T x) { return radians(x); }, degrees);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> degrees(const vec<T, Size>& radians) {
return map_join([](T x) { return degrees(x); }, radians);
}
template < typename T, std::size_t Size >
[[nodiscard]] 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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
return map_join([](T x) { return atanh(x); }, xs);
}
template < typename T, std::size_t Size >
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) {
*ss = sin(xs);
*cs = cos(xs);
}
}
//
// Exponential Functions
//
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) {
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) {
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) {
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) {
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) {
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) {
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) {
return map_join([](T x) { return rsqrt(x); }, xs);
}
}
//
// Common Functions
//
@@ -849,6 +714,141 @@ namespace vmath_hpp
}
}
//
// Angle and Trigonometric Functions
//
namespace vmath_hpp
{
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> radians(const vec<T, Size>& degrees) {
return map_join([](T x) { return radians(x); }, degrees);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<T, Size> degrees(const vec<T, Size>& radians) {
return map_join([](T x) { return degrees(x); }, radians);
}
template < typename T, std::size_t Size >
[[nodiscard]] 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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
return map_join([](T x) { return atanh(x); }, xs);
}
template < typename T, std::size_t Size >
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) {
*ss = sin(xs);
*cs = cos(xs);
}
}
//
// Exponential Functions
//
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) {
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) {
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) {
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) {
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) {
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) {
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) {
return map_join([](T x) { return rsqrt(x); }, xs);
}
}
//
// Geometric Functions
//
@@ -897,7 +897,7 @@ namespace vmath_hpp
template < typename T, std::size_t Size >
[[nodiscard]] vec<T, Size> normalize(const vec<T, Size>& xs) {
return xs * rsqrt(dot(xs, xs));
return xs * rsqrt(length2(xs));
}
template < typename T, std::size_t Size >
@@ -924,22 +924,16 @@ namespace vmath_hpp
namespace vmath_hpp
{
// any
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool any(const vec<T, Size>& xs) {
return fold_join([](bool acc, T x){ return acc || any(x); }, false, xs);
}
// all
template < typename T, std::size_t Size >
[[nodiscard]] constexpr bool all(const vec<T, Size>& xs) {
return fold_join([](bool acc, T x){ return acc && all(x); }, true, xs);
}
// approx
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> approx(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return approx(x, y); }, xs, ys);
@@ -950,43 +944,31 @@ namespace vmath_hpp
return map_join([epsilon](T x, T y){ return approx(x, y, epsilon); }, xs, ys);
}
// less
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> less(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return less(x, y); }, xs, ys);
}
// less_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> less_equal(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return less_equal(x, y); }, xs, ys);
}
// greater
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> greater(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return greater(x, y); }, xs, ys);
}
// greater_equal
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> greater_equal(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return greater_equal(x, y); }, xs, ys);
}
// equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return equal_to(x, y); }, xs, ys);
}
// not_equal_to
template < typename T, std::size_t Size >
[[nodiscard]] constexpr vec<bool, Size> not_equal_to(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return not_equal_to(x, y); }, xs, ys);