| 5 | #include <tmd/TriangleMeshDistance.h> |
| 6 | |
| 7 | double point_AABB_signed(const tmd::Vec3d& point, const tmd::Vec3d& bottom, const tmd::Vec3d& top) |
| 8 | { |
| 9 | const tmd::Vec3d dx = { std::max(bottom[0] - point[0], point[0] - top[0]), |
| 10 | std::max(bottom[1] - point[1], point[1] - top[1]), |
| 11 | std::max(bottom[2] - point[2], point[2] - top[2]) }; |
| 12 | |
| 13 | const double max_dx = std::max(dx[0], std::max(dx[1], dx[2])); |
| 14 | if (max_dx < 0.0) { // Inside |
| 15 | return max_dx; |
| 16 | } |
| 17 | else { // Outside |
| 18 | double dist_sq = 0.0; |
| 19 | for (int i = 0; i < 3; i++) { |
| 20 | if (dx[i] > 0.0) { |
| 21 | dist_sq += dx[i] * dx[i]; |
| 22 | } |
| 23 | |
| 24 | } |
| 25 | return std::sqrt(dist_sq); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | |
| 30 | TEST_CASE("TriangleMeshDistance", "") |