X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGBox.hxx;h=f63eef242568f5285fb740c7f8b28f43f6ddeb59;hb=3bcd0bafd5fba1eebadfd1cb8a7294d665cf1932;hp=8024a1318e3911767828bcebf164a983fe36d573;hpb=7e7ce2f38e87d6244e05730fa4382da088bb25f1;p=simgear.git diff --git a/simgear/math/SGBox.hxx b/simgear/math/SGBox.hxx index 8024a131..f63eef24 100644 --- a/simgear/math/SGBox.hxx +++ b/simgear/math/SGBox.hxx @@ -71,6 +71,14 @@ public: (pt[2] > center[2]) ? _min[2] : _max[2]); } + // return the closest point to pt still in the box + template + SGVec3 getClosestPoint(const SGVec3& pt) const + { + return SGVec3((pt[0] < _min[0]) ? _min[0] : ((_max[0] < pt[0]) ? _max[0] : T(pt[0])), + (pt[1] < _min[1]) ? _min[1] : ((_max[1] < pt[1]) ? _max[1] : T(pt[1])), + (pt[2] < _min[2]) ? _min[2] : ((_max[2] < pt[2]) ? _max[2] : T(pt[2]))); + } // Only works for floating point types SGVec3 getCenter() const @@ -89,7 +97,7 @@ public: return (_max[0] - _min[0])*(_max[1] - _min[1])*(_max[2] - _min[2]); } - const bool empty() const + bool empty() const { return !valid(); } bool valid() const