Dam, instead of going to sleep you guys made me do this:
Same interface as your function and should give the same results, while having obvious advantages. I love the fun of finding algorithms.
Code (glbasic) Select
FUNCTION DistanceBoxPoint#: cX# , cY# , cZ# , bXL# , bXR# , bYD# , bYU# , bZF# , bZB#
cX = IIF( cX<bXL, cX-bXL, IIF( cX>bXR, cX-bXR, 0 ) )
cY = IIF( cY<bYD, cY-bYD, IIF( cY>bYU, cY-bYU, 0 ) )
cZ = IIF( cZ<bZF, cZ-bZF, IIF( cZ>bZB, cZ-bZB, 0 ) )
RETURN cX * cX + cY * cY + cZ * cZ
ENDFUNCTION
Same interface as your function and should give the same results, while having obvious advantages. I love the fun of finding algorithms.