From 78221efae3c038e2c21cb553891d9de8c37cf809 Mon Sep 17 00:00:00 2001 From: Elisey Puzko Date: Sun, 25 Feb 2018 14:49:36 +0300 Subject: min/max functions --- src/GameState.cpp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/GameState.cpp') diff --git a/src/GameState.cpp b/src/GameState.cpp index 192a0c5..6c2ad42 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -594,28 +594,14 @@ BlockFacing detectHitFace(VectorF raycastHit, Vector selectedBlock) { static const auto vecRight = VectorF(1, 0, 0); static const auto vecForward = VectorF(0, 0, -1); - double up = vec.cosBetween(vecUp); - double down = -up; - double right = vec.cosBetween(vecRight); - double left = -right; - double forward = vec.cosBetween(vecForward); - double backward = -forward; - - // TODO: create a min/max function for the variable number of arguments - // NOTE: function names are surrounded by parentheses to avoid conflict of - // `std::min` and a `min` macro from `windows.h`. If there will be more uses - // of `std::min`, a macro `NOMINMAX` should be defined because these hacks can - // have the real impact on the performance. - double min_cos = (std::min)( - (std::min)( - (std::min)( - (std::min)( - (std::min)(up, down), - right), - left), - forward), - backward); - + const double up = vec.cosBetween(vecUp); + const double down = -up; + const double right = vec.cosBetween(vecRight); + const double left = -right; + const double forward = vec.cosBetween(vecForward); + const double backward = -forward; + + const double min_cos = _min(up, down, right, left, forward, backward); if (min_cos == down) return BlockFacing::Bottom; else if (min_cos == up) -- cgit v1.2.3