From 3b6480c5b0c968ad9f5a7cfb7ca494989be03629 Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Mon, 23 Feb 2015 16:25:14 +1000 Subject: [PATCH] Fix wrapDegrees family of functions wrapDegrees() (renamed to modulo360f) wrapDegrees_0_360 wrapDegrees_180 Minor errors were present in previous versions; see issue #2328 --- src/network/packethandlers/server.cpp | 4 +- src/test.cpp | 44 +++++++++++--- src/util/numeric.h | 83 +++++++++++++-------------- 3 files changed, 80 insertions(+), 51 deletions(-) diff --git a/src/network/packethandlers/server.cpp b/src/network/packethandlers/server.cpp index feb8d66be..137327e0b 100644 --- a/src/network/packethandlers/server.cpp +++ b/src/network/packethandlers/server.cpp @@ -543,8 +543,8 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt) v3f position((f32)ps.X / 100.0, (f32)ps.Y / 100.0, (f32)ps.Z / 100.0); v3f speed((f32)ss.X / 100.0, (f32)ss.Y / 100.0, (f32)ss.Z / 100.0); - pitch = wrapDegrees(pitch); - yaw = wrapDegrees(yaw); + pitch = modulo360f(pitch); + yaw = modulo360f(yaw); Player *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { diff --git a/src/test.cpp b/src/test.cpp index 3b7c75c6e..350cab127 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -147,15 +147,45 @@ struct TestBase struct TestUtilities: public TestBase { + inline float ref_WrapDegrees180(float f) + { + // This is a slower alternative to the wrapDegrees_180() function; + // used as a reference for testing + float value = fmodf(f + 180, 360); + if (value < 0) + value += 360; + return value - 180; + } + + inline float ref_WrapDegrees_0_360(float f) + { + // This is a slower alternative to the wrapDegrees_0_360() function; + // used as a reference for testing + float value = fmodf(f, 360); + if (value < 0) + value += 360; + return value < 0 ? value + 360 : value; + } + + void Run() { - /*infostream<<"wrapDegrees(100.0) = "<