From da7bbe8fb80d6e0da5099da11842d9b12bf2fb51 Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Thu, 24 Mar 2022 09:03:21 -0700 Subject: Remove some unnecessary static_casts `float = float / static_cast(size_t)` should be equivalent to `float = float / size_t`, implicit conversion does the same thing. `float = float / double` is not quite equivalent to `float = float / static_cast(double)`. In the former case, the first operand is converted to a double and divided before the result is converted to float. PiperOrigin-RevId: 437007538 --- ink_stroke_modeler/internal/wobble_smoother.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ink_stroke_modeler/internal/wobble_smoother.cc b/ink_stroke_modeler/internal/wobble_smoother.cc index 4885519..96fe90d 100644 --- a/ink_stroke_modeler/internal/wobble_smoother.cc +++ b/ink_stroke_modeler/internal/wobble_smoother.cc @@ -45,10 +45,9 @@ Vec2 WobbleSmoother::Update(Vec2 position, Time time) { float speed = 0; if (delta_time == Duration(0)) { // We're going to assume that you're not actually moving infinitely fast. - speed = std::max(params_.speed_ceiling, - speed_sum_ / static_cast(samples_.size())); + speed = std::max(params_.speed_ceiling, speed_sum_ / samples_.size()); } else { - speed = distance / static_cast(delta_time.Value()); + speed = distance / delta_time.Value(); } samples_.push_back({.position = position, .speed = speed, .time = time}); @@ -60,8 +59,8 @@ Vec2 WobbleSmoother::Update(Vec2 position, Time time) { samples_.pop_front(); } - Vec2 avg_position = position_sum_ / static_cast(samples_.size()); - float avg_speed = speed_sum_ / static_cast(samples_.size()); + Vec2 avg_position = position_sum_ / samples_.size(); + float avg_speed = speed_sum_ / samples_.size(); return Interp( avg_position, position, Normalize(params_.speed_floor, params_.speed_ceiling, avg_speed)); -- cgit v1.2.3