MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / intersection

Method intersection

core/math/aabb.cpp:87–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87AABB AABB::intersection(const AABB &p_aabb) const {
88#ifdef MATH_CHECKS
89 if (unlikely(size.x < 0 || size.y < 0 || size.z < 0 || p_aabb.size.x < 0 || p_aabb.size.y < 0 || p_aabb.size.z < 0)) {
90 ERR_PRINT("AABB size is negative, this is not supported. Use AABB.abs() to get an AABB with a positive size.");
91 }
92#endif
93 Vector3 src_min = position;
94 Vector3 src_max = position + size;
95 Vector3 dst_min = p_aabb.position;
96 Vector3 dst_max = p_aabb.position + p_aabb.size;
97
98 Vector3 min, max;
99
100 if (src_min.x > dst_max.x || src_max.x < dst_min.x) {
101 return AABB();
102 } else {
103 min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
104 max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
105 }
106
107 if (src_min.y > dst_max.y || src_max.y < dst_min.y) {
108 return AABB();
109 } else {
110 min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
111 max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
112 }
113
114 if (src_min.z > dst_max.z || src_max.z < dst_min.z) {
115 return AABB();
116 } else {
117 min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
118 max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
119 }
120
121 return AABB(min, max - min);
122}
123
124// Note that this routine returns the BACKTRACKED (i.e. behind the ray origin)
125// intersection point + normal if INSIDE the AABB.

Callers 15

set_bit_rectMethod · 0.45
grow_maskMethod · 0.45
get_rect_regionMethod · 0.45
_notificationMethod · 0.45
_get_mouse_overMethod · 0.45
fill_rectMethod · 0.45
fill_solid_regionMethod · 0.45

Calls 1

AABBClass · 0.70

Tested by

no test coverage detected