From b4191bf8f64f984f469dc4fcef0c0f23cf6cf226 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:58:42 +0100 Subject: [PATCH] [Core] Fix `AABB.encloses` failing on shared upper bound This differs from `Rect2(i)` and was fixed for those classes in the past --- core/math/aabb.h | 6 +++--- tests/core/math/test_aabb.h | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/math/aabb.h b/core/math/aabb.h index 859810df372a..cea845bf7c2d 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -200,11 +200,11 @@ inline bool AABB::encloses(const AABB &p_aabb) const { return ( (src_min.x <= dst_min.x) && - (src_max.x > dst_max.x) && + (src_max.x >= dst_max.x) && (src_min.y <= dst_min.y) && - (src_max.y > dst_max.y) && + (src_max.y >= dst_max.y) && (src_min.z <= dst_min.z) && - (src_max.z > dst_max.z)); + (src_max.z >= dst_max.z)); } Vector3 AABB::get_support(const Vector3 &p_normal) const { diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h index d3560ff6b6cd..b9f84cca245a 100644 --- a/tests/core/math/test_aabb.h +++ b/tests/core/math/test_aabb.h @@ -228,11 +228,20 @@ TEST_CASE("[AABB] Merging") { TEST_CASE("[AABB] Encloses") { const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb_big.encloses(aabb_big), + "encloses() with itself should return the expected result."); + AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1)); CHECK_MESSAGE( aabb_big.encloses(aabb_small), "encloses() with fully contained AABB (touching the edge) should return the expected result."); + aabb_small = AABB(Vector3(1.5, 6, 2.5), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.encloses(aabb_small), + "encloses() with fully contained AABB (touching the edge) should return the expected result."); + aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1)); CHECK_MESSAGE( !aabb_big.encloses(aabb_small),