From b40a434d2ac03036aa37639f565ca75c775db2cc Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 6 May 2024 15:02:21 +0900 Subject: [PATCH 1/2] Fix UnitTest for checking combined AABB --- src/test.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/src/test.cpp b/src/test.cpp index 4986e1a..633d099 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -688,12 +688,70 @@ int main() { SC_SACD_AABB_Box b{-3.0F, -3.0F, -3.0F, 2.0F, 2.0F, 2.0F}; auto combined = SC_SACD_AABB_Combine(a, b); - CHECK_FLOAT(combined.x, (7.0F - 5.0F) / 2.0F); - CHECK_FLOAT(combined.y, (7.0F - 5.0F) / 2.0F); - CHECK_FLOAT(combined.z, (7.0F - 5.0F) / 2.0F); - CHECK_FLOAT(combined.width, 10.0F); - CHECK_FLOAT(combined.height, 10.0F); - CHECK_FLOAT(combined.depth, 10.0F); + + auto *box_min = a.x - a.width / 2.0F < b.x - b.width / 2.0F ? &a : &b; + auto *box_max = a.x + a.width / 2.0F > b.x + b.width / 2.0F ? &a : &b; + CHECK_FLOAT(combined.width, box_max->x + box_max->width / 2.0F - + (box_min->x - box_min->width / 2.0F)); + CHECK_FLOAT(combined.x, box_min->x - box_min->width / 2.0F + + (box_max->x + box_max->width / 2.0F - + (box_min->x - box_min->width / 2.0F)) / + 2.0F); + box_min = a.y - a.height / 2.0F < b.y - b.height / 2.0F ? &a : &b; + box_max = a.y + a.height / 2.0F > b.y + b.height / 2.0F ? &a : &b; + CHECK_FLOAT(combined.height, box_max->y + box_max->height / 2.0F - + (box_min->y - box_min->height / 2.0F)); + CHECK_FLOAT(combined.y, box_min->y - box_min->height / 2.0F + + (box_max->y + box_max->height / 2.0F - + (box_min->y - box_min->height / 2.0F)) / + 2.0F); + box_min = a.z - a.depth / 2.0F < b.z - b.depth / 2.0F ? &a : &b; + box_max = a.z + a.depth / 2.0F > b.z + b.depth / 2.0F ? &a : &b; + CHECK_FLOAT(combined.depth, box_max->z + box_max->depth / 2.0F - + (box_min->z - box_min->depth / 2.0F)); + CHECK_FLOAT(combined.z, box_min->z - box_min->depth / 2.0F + + (box_max->z + box_max->depth / 2.0F - + (box_min->z - box_min->depth / 2.0F)) / + 2.0F); + + a.x = -12.0F; + a.z = -1.0F; + a.width = 1.0F; + a.height = 5.0F; + a.depth = 0.5F; + + b.x = 1.0F; + b.y = 7.0F; + b.width = 3.0F; + b.height = 4.0F; + b.depth = 0.7F; + + combined = SC_SACD_AABB_Combine(a, b); + + box_min = a.x - a.width / 2.0F < b.x - b.width / 2.0F ? &a : &b; + box_max = a.x + a.width / 2.0F > b.x + b.width / 2.0F ? &a : &b; + CHECK_FLOAT(combined.width, box_max->x + box_max->width / 2.0F - + (box_min->x - box_min->width / 2.0F)); + CHECK_FLOAT(combined.x, box_min->x - box_min->width / 2.0F + + (box_max->x + box_max->width / 2.0F - + (box_min->x - box_min->width / 2.0F)) / + 2.0F); + box_min = a.y - a.height / 2.0F < b.y - b.height / 2.0F ? &a : &b; + box_max = a.y + a.height / 2.0F > b.y + b.height / 2.0F ? &a : &b; + CHECK_FLOAT(combined.height, box_max->y + box_max->height / 2.0F - + (box_min->y - box_min->height / 2.0F)); + CHECK_FLOAT(combined.y, box_min->y - box_min->height / 2.0F + + (box_max->y + box_max->height / 2.0F - + (box_min->y - box_min->height / 2.0F)) / + 2.0F); + box_min = a.z - a.depth / 2.0F < b.z - b.depth / 2.0F ? &a : &b; + box_max = a.z + a.depth / 2.0F > b.z + b.depth / 2.0F ? &a : &b; + CHECK_FLOAT(combined.depth, box_max->z + box_max->depth / 2.0F - + (box_min->z - box_min->depth / 2.0F)); + CHECK_FLOAT(combined.z, box_min->z - box_min->depth / 2.0F + + (box_max->z + box_max->depth / 2.0F - + (box_min->z - box_min->depth / 2.0F)) / + 2.0F); } std::cout << "Checks checked: " << checks_checked << '\n' From 6acbef0fa3bf48c5276a5656b3f3ae79b7900e90 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 6 May 2024 15:02:55 +0900 Subject: [PATCH 2/2] Version 2.2.1 (fix UnitTest) --- CMakeLists.txt | 2 +- Changelog.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9ae890..55a3c60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(SC_3D_CollisionDetectionHelpers_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/sc_ add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES}) -set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 2.2.0 SOVERSION 2) +set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 2.2.1 SOVERSION 2) target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20) if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/Changelog.md b/Changelog.md index 9abdf54..e660681 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## Version 2.2.1 + +Fix UnitTest for checking AABB. + ## Version 2.2.0 Refactoring of internally used function.