From 9e22140fb1aed53f70a9a8aebebe2925071f690b Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 3 Feb 2024 23:37:29 +0100 Subject: w --- editor/tests/raycast-test.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'editor/tests/raycast-test.cpp') diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp index f074cb98..8bfab6c2 100644 --- a/editor/tests/raycast-test.cpp +++ b/editor/tests/raycast-test.cpp @@ -26,6 +26,11 @@ template constexpr inline auto chunk_size = Math::Vector2{TILE_MA using RTree = std::decay_t().rtree())>; using Rect = typename RTree::Rect; +template constexpr inline T sign_(auto&& x) { + constexpr auto zero = std::decay_t{0}; + return T(x > zero) - T(x < zero); +} + constexpr Vector2d pt_to_vec(point from, point pt) { auto V = Vector2d{}; @@ -416,14 +421,16 @@ struct raycast_test : base_test if (k == 0) { - pos[long_axis] += (int)(size[long_axis]/4) * (V[long_axis] < 0 ? -1 : 1); + auto sign_long = sign_(V[long_axis]), sign_short = sign_(V[short_axis]); + pos[long_axis] += (int)(size[long_axis]/4) * sign_long; size[long_axis] -= size[long_axis]/2; - pos[short_axis] += (int)(size[short_axis]/4) * (V[short_axis] < 0 ? -1 : 1); + pos[short_axis] += (int)(size[short_axis]/4) * sign_short; size[short_axis] -= size[short_axis]/2; } else if (k == nsteps) { - pos[long_axis] -= (int)(size[long_axis]/4) * (V[long_axis] < 0 ? -1 : 1); + auto sign_long = sign_(V[long_axis]); + pos[long_axis] -= (int)(size[long_axis]/4) * sign_long; size[long_axis] -= size[long_axis]/2; size[long_axis] += (unsigned)iTILE_SIZE2.x() / 2; } -- cgit v1.2.3