From d5e5fdeffae3f9f1ad6097ad980da1a035a23a10 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 1 Nov 2023 23:53:48 +0000 Subject: [PATCH] `Displacement#distance`: Use a naive hypot impl `std::hypot` is much slower than a naive implementation. It has the advantage of extra precision but we don't need that at all. --- Source/engine/displacement.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/engine/displacement.hpp b/Source/engine/displacement.hpp index f636bd6b0..5d2cca73f 100644 --- a/Source/engine/displacement.hpp +++ b/Source/engine/displacement.hpp @@ -120,7 +120,8 @@ struct DisplacementOf { float magnitude() const { - return static_cast(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); } /**