Return the (square) distance from point to AABB.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(aabb_object), | intent(in) | :: | self | AABB. |
||
| type(vector_R8P), | intent(in) | :: | point | Point reference. |
Distance from point to AABB.
pure function distance(self, point)
!< Return the (square) distance from point to AABB.
class(aabb_object), intent(in) :: self !< AABB.
type(vector_R8P), intent(in) :: point !< Point reference.
real(R8P) :: distance !< Distance from point to AABB.
real(R8P) :: dx, dy, dz !< Distance components.
dx = max(self%bmin%x - point%x, 0._R8P, point%x - self%bmax%x)
dy = max(self%bmin%y - point%y, 0._R8P, point%y - self%bmax%y)
dz = max(self%bmin%z - point%z, 0._R8P, point%z - self%bmax%z)
distance = dx * dx + dy * dy + dz * dz
endfunction distance