diff --git a/Library/include/playrho/d2/UnitVec.hpp b/Library/include/playrho/d2/UnitVec.hpp index c19fefb71c..102cdb9555 100644 --- a/Library/include/playrho/d2/UnitVec.hpp +++ b/Library/include/playrho/d2/UnitVec.hpp @@ -126,7 +126,18 @@ class UnitVec static PolarCoord Get(const T x, const T y, const UnitVec& fallback = GetDefaultFallback()) noexcept { - // Try the faster way first... + // Try the fastest way first... + enum { None = 0x0, Left = 0x1, Right = 0x2, Up = 0x4, Down = 0x8 }; + switch (((x > 0)? Right: (x < 0) ? Left: 0) | ((y > 0)? Up: (y < 0)? Down: 0)) { + case Right: return std::make_pair(GetRight(), x); + case Left: return std::make_pair(GetLeft(), -x); + case Up: return std::make_pair(GetTop(), y); + case Down: return std::make_pair(GetBottom(), -y); + case None: return std::make_pair(fallback, T{}); + default: break; + } + + // Try the faster way next... const auto magnitudeSquared = x * x + y * y; if (isnormal(magnitudeSquared)) {