diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-01-11 15:49:57 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-01-11 15:49:57 +0300 |
commit | 6bfa578d0c5ce6b64a68e19537df18a39c1af469 (patch) | |
tree | c69196ed5e8736e05c285bf1e9cb41e592795e0b /source | |
parent | d43ca533e37303377a9c062793d3889d2255d23c (diff) |
Move `is_zero` and `is_any_zero` to `blender::math` namespace.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/spline_base.cc | 4 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vec_types.hh | 26 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.hh | 22 | ||||
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_transform.cc | 2 |
4 files changed, 27 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 6cca88becda..f8563d34b01 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -209,7 +209,7 @@ static float3 direction_bisect(const float3 &prev, const float3 &middle, const f const float3 dir_next = normalize(next - middle); const float3 result = normalize(dir_prev + dir_next); - if (UNLIKELY(result.is_zero())) { + if (UNLIKELY(is_zero(result))) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -311,7 +311,7 @@ static float3 calculate_next_normal(const float3 &last_normal, { using namespace blender::math; - if (last_tangent.is_zero() || current_tangent.is_zero()) { + if (is_zero(last_tangent) || is_zero(current_tangent)) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); diff --git a/source/blender/blenlib/BLI_math_vec_types.hh b/source/blender/blenlib/BLI_math_vec_types.hh index 48d6df314e9..8da7ce28830 100644 --- a/source/blender/blenlib/BLI_math_vec_types.hh +++ b/source/blender/blenlib/BLI_math_vec_types.hh @@ -335,7 +335,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> friend vec_base operator/(const vec_base &a, const vec_base &b) { - BLI_assert(!b.is_any_zero()); + BLI_assert(!math::is_any_zero(b)); BLI_VEC_OP_IMPL(ret, i, ret[i] = a[i] / b[i]); } @@ -347,7 +347,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> friend vec_base operator/(T a, const vec_base &b) { - BLI_assert(!b.is_any_zero()); + BLI_assert(!math::is_any_zero(b)); BLI_VEC_OP_IMPL(ret, i, ret[i] = a / b[i]); } @@ -359,7 +359,7 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> vec_base &operator/=(const vec_base &b) { - BLI_assert(!b.is_any_zero()); + BLI_assert(!math::is_any_zero(b)); BLI_VEC_OP_IMPL_SELF(i, (*this)[i] /= b[i]); } @@ -525,26 +525,6 @@ template<typename T, int Size> struct vec_base : public vec_struct_base<T, Size> return !(a == b); } - bool is_zero() const - { - for (int i = 0; i < Size; i++) { - if ((*this)[i] != T(0)) { - return false; - } - } - return true; - } - - bool is_any_zero() const - { - for (int i = 0; i < Size; i++) { - if ((*this)[i] == T(0)) { - return true; - } - } - return false; - } - /** Misc. */ uint64_t hash() const diff --git a/source/blender/blenlib/BLI_math_vector.hh b/source/blender/blenlib/BLI_math_vector.hh index 3da70dfdf27..049027bf94c 100644 --- a/source/blender/blenlib/BLI_math_vector.hh +++ b/source/blender/blenlib/BLI_math_vector.hh @@ -60,6 +60,26 @@ namespace blender::math { #define BLI_ENABLE_IF_INT_VEC(T) BLI_ENABLE_IF((std::is_integral<typename T::base_type>::value)) +template<typename T> inline bool is_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] != bT(0)) { + return false; + } + } + return true; +} + +template<typename T> inline bool is_any_zero(const T &a) +{ + for (int i = 0; i < T::type_length; i++) { + if (a[i] == bT(0)) { + return true; + } + } + return false; +} + template<typename T> inline T abs(const T &a) { T result; @@ -255,7 +275,7 @@ inline T refract(const T &incident, const T &normal, const bT eta) template<typename T, BLI_ENABLE_IF_FLT_VEC(T)> inline T project(const T &p, const T &v_proj) { - if (UNLIKELY(v_proj.is_zero())) { + if (UNLIKELY(is_zero(v_proj))) { return T(0.0f); } return v_proj * (dot(p, v_proj) / dot(v_proj, v_proj)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_transform.cc b/source/blender/nodes/geometry/nodes/node_geo_transform.cc index a56fddb54a2..6187a2eacf9 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_transform.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_transform.cc @@ -49,7 +49,7 @@ static bool use_translate(const float3 rotation, const float3 scale) static void translate_mesh(Mesh &mesh, const float3 translation) { - if (!translation.is_zero()) { + if (!math::is_zero(translation)) { BKE_mesh_translate(&mesh, translation, false); } } |