// David Eberly, Geometric Tools, Redmond WA 98052 // Copyright (c) 1998-2020 // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt // Version: 4.0.2019.08.13 #pragma once #include #include namespace WwiseGTE { template class DCPQuery, Line> { public: struct Result { Real distance, sqrDistance; Real lineParameter; // t in (-infinity,+infinity) Vector lineClosest; // origin + t * direction }; Result operator()(Vector const& point, Line const& line) { Result result; Vector diff = point - line.origin; result.lineParameter = Dot(line.direction, diff); result.lineClosest = line.origin + result.lineParameter * line.direction; diff = point - result.lineClosest; result.sqrDistance = Dot(diff, diff); result.distance = std::sqrt(result.sqrDistance); return result; } }; // Template aliases for convenience. template using DCPPointLine = DCPQuery, Line>; template using DCPPoint2Line2 = DCPPointLine<2, Real>; template using DCPPoint3Line3 = DCPPointLine<3, Real>; }