Skip to content

Commit

Permalink
Displacement#distance: Use a naive hypot impl
Browse files Browse the repository at this point in the history
`std::hypot` is much slower than a naive implementation.
It has the advantage of extra precision but we don't need that at all.
  • Loading branch information
glebm committed Nov 2, 2023
1 parent 17d5f05 commit 026907e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Source/engine/displacement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ struct DisplacementOf {

DVL_ALWAYS_INLINE float magnitude() const
{
return static_cast<float>(hypot(deltaX, deltaY));
// We do not use `std::hypot` here because it is slower and we do not need the extra precision.
return sqrtf(deltaX * deltaX + deltaY * deltaY);
}

/**
Expand Down

0 comments on commit 026907e

Please sign in to comment.