diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-01-12 14:43:40 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-01-12 14:44:26 +0300 |
commit | e5766752d04794c2693dedad75baeb8c7d68f4cf (patch) | |
tree | 7f5354d1272612a32c28bfda4c03259970c402b7 /source/blender/blenkernel/intern/spline_base.cc | |
parent | b2ccd8546c7249a5ce279210d45ddbb5e90cd10d (diff) |
Revert "BLI: Refactor vector types & functions to use templates"
Reverted because the commit removes a lot of commits.
This reverts commit a2c1c368af48644fa8995ecbe7138cc0d7900c30.
Diffstat (limited to 'source/blender/blenkernel/intern/spline_base.cc')
-rw-r--r-- | source/blender/blenkernel/intern/spline_base.cc | 41 |
1 files changed, 14 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 3262d768b6c..857022345f3 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,15 +166,13 @@ static void accumulate_lengths(Span<float3> positions, const bool is_cyclic, MutableSpan<float> lengths) { - using namespace blender::math; - float length = 0.0f; for (const int i : IndexRange(positions.size() - 1)) { - length += distance(positions[i], positions[i + 1]); + length += float3::distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + distance(positions.last(), positions.first()); + lengths.last() = length + float3::distance(positions.last(), positions.first()); } } @@ -202,13 +200,11 @@ Span<float> Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - using namespace blender::math; - - const float3 dir_prev = normalize(middle - prev); - const float3 dir_next = normalize(next - middle); + const float3 dir_prev = (middle - prev).normalized(); + const float3 dir_next = (next - middle).normalized(); - const float3 result = normalize(dir_prev + dir_next); - if (UNLIKELY(is_zero(result))) { + const float3 result = (dir_prev + dir_next).normalized(); + if (UNLIKELY(result.is_zero())) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -218,8 +214,6 @@ static void calculate_tangents(Span<float3> positions, const bool is_cyclic, MutableSpan<float3> tangents) { - using namespace blender::math; - if (positions.size() == 1) { tangents.first() = float3(0.0f, 0.0f, 1.0f); return; @@ -238,8 +232,8 @@ static void calculate_tangents(Span<float3> positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = normalize(positions[1] - positions[0]); - tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); + tangents.first() = (positions[1] - positions[0]).normalized(); + tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); } } @@ -270,22 +264,18 @@ static float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, const float angle) { - using namespace blender::math; - BLI_ASSERT_UNIT_V3(direction); BLI_ASSERT_UNIT_V3(axis); - const float3 axis_scaled = axis * dot(direction, axis); + const float3 axis_scaled = axis * float3::dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = blender::math::cross(axis, diff); + const float3 cross = float3::cross(axis, diff); return axis_scaled + diff * std::cos(angle) + cross * std::sin(angle); } static void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> r_normals) { - using namespace blender::math; - BLI_assert(r_normals.size() == tangents.size()); /* Same as in `vec_to_quat`. */ @@ -296,7 +286,7 @@ static void calculate_normals_z_up(Span<float3> tangents, MutableSpan<float3> r_ r_normals[i] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); + r_normals[i] = float3(tangent.y, -tangent.x, 0.0f).normalized(); } } } @@ -308,14 +298,12 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - using namespace blender::math; - - if (is_zero(last_tangent) || is_zero(current_tangent)) { + if (last_tangent.is_zero() || current_tangent.is_zero()) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = normalize(cross(last_tangent, current_tangent)); + const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -325,7 +313,6 @@ static void calculate_normals_minimum(Span<float3> tangents, const bool cyclic, MutableSpan<float3> r_normals) { - using namespace blender::math; BLI_assert(r_normals.size() == tangents.size()); if (r_normals.is_empty()) { @@ -340,7 +327,7 @@ static void calculate_normals_minimum(Span<float3> tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); + r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); } /* Forward normal with minimum twist along the entire spline. */ |