diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-03 23:31:39 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-03 23:31:39 +0100 |
commit | e39fc6fa9096e034f0d9d325a70116fbf31403c4 (patch) | |
tree | ad4bfa17b2b4d143c186c8534761ab07564144cf | |
parent | 7bf80874ae2a940d052539626730d48fd8ed3f5c (diff) |
w
-rw-r--r-- | editor/tests/raycast-test.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp index 868d4a16..c1ede28e 100644 --- a/editor/tests/raycast-test.cpp +++ b/editor/tests/raycast-test.cpp @@ -353,8 +353,6 @@ struct raycast_test : base_test { constexpr double eps = 1e-6; constexpr double inv_eps = 1/eps; - constexpr double sqrt_2 = Math::sqrt(2.); - constexpr double inv_sqrt_2 = 1. / sqrt_2; constexpr int fuzz = 2; result.has_result = false; @@ -414,6 +412,7 @@ struct raycast_test : base_test auto pos = Vector2i{(int)std::copysign(pos_.x(), V.x()), (int)std::copysign(pos_.y(), V.y())}; auto size = Vector2ui(iTILE_SIZE2); size[long_axis] = Math::max(tile_size<unsigned>.x(), (unsigned)Math::ceil(long_len / nsteps)); + size[short_axis] = (unsigned)Math::ceil(short_len / nsteps)+2u; if (k == 0) { @@ -422,6 +421,12 @@ struct raycast_test : base_test pos[short_axis] += (int)(size[short_axis]/4) * (V[short_axis] < 0 ? -1 : 1); 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); + size[long_axis] -= size[long_axis]/2; + size[long_axis] += (unsigned)iTILE_SIZE2.x() / 2; + } pos -= Vector2i(fuzz); size += Vector2ui(fuzz)*2; @@ -451,9 +456,11 @@ struct raycast_test : base_test auto ret = ray_aabb_intersection(origin, dir_inv_norm, {{{r.m_min[0], r.m_min[1]},{r.m_max[0], r.m_max[1]}}}, signs); - if (!ret.result || ret.tmin > ray_len) + if (!ret.result) + return true; + if (ret.tmin > ray_len) [[unlikely]] return true; - if (ret.tmin < min_tmin) + if (ret.tmin < min_tmin) [[likely]] { min_tmin = ret.tmin; result.collision = object::normalize_coords(from, Vector2i(dir * (double)ret.tmin)); @@ -466,7 +473,7 @@ struct raycast_test : base_test for (unsigned i = 0; i < result.path.size(); i++) { auto [center, size] = result.path[i]; - if (center.chunk3() != last_ch) + if (center.chunk3() != last_ch) [[unlikely]] { last_ch = center.chunk3(); nbs = get_chunk_neighbors(w, center.chunk3()); |