diff options
Diffstat (limited to 'source/blender/blenkernel/intern/spline_base.cc')
-rw-r--r-- | source/blender/blenkernel/intern/spline_base.cc | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 857022345f3..3262d768b6c 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -166,13 +166,15 @@ 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 += float3::distance(positions[i], positions[i + 1]); + length += distance(positions[i], positions[i + 1]); lengths[i] = length; } if (is_cyclic) { - lengths.last() = length + float3::distance(positions.last(), positions.first()); + lengths.last() = length + distance(positions.last(), positions.first()); } } @@ -200,11 +202,13 @@ Span<float> Spline::evaluated_lengths() const static float3 direction_bisect(const float3 &prev, const float3 &middle, const float3 &next) { - const float3 dir_prev = (middle - prev).normalized(); - const float3 dir_next = (next - middle).normalized(); + using namespace blender::math; + + const float3 dir_prev = normalize(middle - prev); + const float3 dir_next = normalize(next - middle); - const float3 result = (dir_prev + dir_next).normalized(); - if (UNLIKELY(result.is_zero())) { + const float3 result = normalize(dir_prev + dir_next); + if (UNLIKELY(is_zero(result))) { return float3(0.0f, 0.0f, 1.0f); } return result; @@ -214,6 +218,8 @@ 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; @@ -232,8 +238,8 @@ static void calculate_tangents(Span<float3> positions, tangents.last() = direction_bisect(second_to_last, last, first); } else { - tangents.first() = (positions[1] - positions[0]).normalized(); - tangents.last() = (positions.last() - positions[positions.size() - 2]).normalized(); + tangents.first() = normalize(positions[1] - positions[0]); + tangents.last() = normalize(positions.last() - positions[positions.size() - 2]); } } @@ -264,18 +270,22 @@ 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 * float3::dot(direction, axis); + const float3 axis_scaled = axis * dot(direction, axis); const float3 diff = direction - axis_scaled; - const float3 cross = float3::cross(axis, diff); + const float3 cross = blender::math::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`. */ @@ -286,7 +296,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] = float3(tangent.y, -tangent.x, 0.0f).normalized(); + r_normals[i] = normalize(float3(tangent.y, -tangent.x, 0.0f)); } } } @@ -298,12 +308,14 @@ static float3 calculate_next_normal(const float3 &last_normal, const float3 &last_tangent, const float3 ¤t_tangent) { - if (last_tangent.is_zero() || current_tangent.is_zero()) { + using namespace blender::math; + + if (is_zero(last_tangent) || is_zero(current_tangent)) { return last_normal; } const float angle = angle_normalized_v3v3(last_tangent, current_tangent); if (angle != 0.0) { - const float3 axis = float3::cross(last_tangent, current_tangent).normalized(); + const float3 axis = normalize(cross(last_tangent, current_tangent)); return rotate_direction_around_axis(last_normal, axis, angle); } return last_normal; @@ -313,6 +325,7 @@ 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()) { @@ -327,7 +340,7 @@ static void calculate_normals_minimum(Span<float3> tangents, r_normals[0] = {1.0f, 0.0f, 0.0f}; } else { - r_normals[0] = float3(first_tangent.y, -first_tangent.x, 0.0f).normalized(); + r_normals[0] = normalize(float3(first_tangent.y, -first_tangent.x, 0.0f)); } /* Forward normal with minimum twist along the entire spline. */ |