diff options
author | Samuel Freilich <sfreilich@google.com> | 2022-03-24 09:03:21 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-03-24 09:03:53 -0700 |
commit | da7bbe8fb80d6e0da5099da11842d9b12bf2fb51 (patch) | |
tree | 2010b4c6497bdf3598210e6e8f2ecca7e375fbec | |
parent | f36296c84270b78765458ba59a5616fbce350da6 (diff) | |
download | ink-stroke-modeler-da7bbe8fb80d6e0da5099da11842d9b12bf2fb51.tar.gz |
Remove some unnecessary static_casts
`float = float / static_cast<float>(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<float>(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
-rw-r--r-- | ink_stroke_modeler/internal/wobble_smoother.cc | 9 |
1 files 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<float>(samples_.size())); + speed = std::max(params_.speed_ceiling, speed_sum_ / samples_.size()); } else { - speed = distance / static_cast<float>(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<float>(samples_.size()); - float avg_speed = speed_sum_ / static_cast<float>(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)); |