[Core] Fix `AABB.encloses` failing on shared upper bound

This differs from `Rect2(i)` and was fixed for those classes in the past
This commit is contained in:
A Thousand Ships 2024-01-12 17:58:42 +01:00
parent 26b1fd0d84
commit b4191bf8f6
No known key found for this signature in database
GPG Key ID: 2033189A662F8BD7
2 changed files with 12 additions and 3 deletions

View File

@ -200,11 +200,11 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
return ( return (
(src_min.x <= dst_min.x) && (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_min.y <= dst_min.y) &&
(src_max.y > dst_max.y) && (src_max.y >= dst_max.y) &&
(src_min.z <= dst_min.z) && (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 { Vector3 AABB::get_support(const Vector3 &p_normal) const {

View File

@ -228,11 +228,20 @@ TEST_CASE("[AABB] Merging") {
TEST_CASE("[AABB] Encloses") { TEST_CASE("[AABB] Encloses") {
const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); 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)); AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1));
CHECK_MESSAGE( CHECK_MESSAGE(
aabb_big.encloses(aabb_small), aabb_big.encloses(aabb_small),
"encloses() with fully contained AABB (touching the edge) should return the expected result."); "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)); aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1));
CHECK_MESSAGE( CHECK_MESSAGE(
!aabb_big.encloses(aabb_small), !aabb_big.encloses(aabb_small),