// 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 #include namespace WwiseGTE { template class DCPQuery, Rectangle3> { public: struct Result { Real distance, sqrDistance; Real segmentParameter, rectangleParameter[2]; Vector3 closestPoint[2]; }; Result operator()(Segment3 const& segment, Rectangle3 const& rectangle) { Result result; Vector3 segCenter, segDirection; Real segExtent; segment.GetCenteredForm(segCenter, segDirection, segExtent); Line3 line(segCenter, segDirection); DCPQuery, Rectangle3> lrQuery; auto lrResult = lrQuery(line, rectangle); if (lrResult.lineParameter >= -segExtent) { if (lrResult.lineParameter <= segExtent) { result.distance = lrResult.distance; result.sqrDistance = lrResult.sqrDistance; result.segmentParameter = lrResult.lineParameter; result.rectangleParameter[0] = lrResult.rectangleParameter[0]; result.rectangleParameter[1] = lrResult.rectangleParameter[1]; result.closestPoint[0] = lrResult.closestPoint[0]; result.closestPoint[1] = lrResult.closestPoint[1]; } else { DCPQuery, Rectangle3> prQuery; Vector3 point = segCenter + segExtent * segDirection; auto prResult = prQuery(point, rectangle); result.sqrDistance = prResult.sqrDistance; result.distance = prResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = prResult.rectangleClosestPoint; } } else { DCPQuery, Rectangle3> prQuery; Vector3 point = segCenter - segExtent * segDirection; auto prResult = prQuery(point, rectangle); result.sqrDistance = prResult.sqrDistance; result.distance = prResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = prResult.rectangleClosestPoint; } return result; } }; }