bvh_integrity.inc 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. void _integrity_check_all() {
  2. #ifdef BVH_INTEGRITY_CHECKS
  3. for (int n = 0; n < NUM_TREES; n++) {
  4. uint32_t root = _root_node_id[n];
  5. if (root != BVHCommon::INVALID) {
  6. _integrity_check_down(root);
  7. }
  8. }
  9. #endif
  10. }
  11. void _integrity_check_up(uint32_t p_node_id) {
  12. TNode &node = _nodes[p_node_id];
  13. BVHABB_CLASS abb = node.aabb;
  14. node_update_aabb(node);
  15. BVHABB_CLASS abb2 = node.aabb;
  16. abb2.expand(-_node_expansion);
  17. CRASH_COND(!abb.is_other_within(abb2));
  18. }
  19. void _integrity_check_down(uint32_t p_node_id) {
  20. const TNode &node = _nodes[p_node_id];
  21. if (node.is_leaf()) {
  22. _integrity_check_up(p_node_id);
  23. } else {
  24. CRASH_COND(node.num_children != 2);
  25. for (int n = 0; n < node.num_children; n++) {
  26. uint32_t child_id = node.children[n];
  27. // check the children parent pointers are correct
  28. TNode &child = _nodes[child_id];
  29. CRASH_COND(child.parent_id != p_node_id);
  30. _integrity_check_down(child_id);
  31. }
  32. }
  33. }