16 template <
typename Real>
23 Real triangleParameter[3], rectangleParameter[2];
32 template <
typename Real>
39 result.sqrDistance = std::numeric_limits<Real>::max();
42 for (
int i0 = 2, i1 = 0; i1 < 3; i0 = i1++)
47 Real segExtent = ((Real)0.5)*
Normalize(segDirection);
51 auto srResult = srQuery(edge, rectangle);
52 if (srResult.sqrDistance < result.sqrDistance)
54 result.distance = srResult.distance;
55 result.sqrDistance = srResult.sqrDistance;
56 Real ratio = srResult.segmentParameter / segExtent;
57 result.triangleParameter[i0] = ((Real)0.5)*((Real)1 - ratio);
58 result.triangleParameter[i1] =
59 (Real)1 - result.triangleParameter[i0];
60 result.triangleParameter[3 - i0 - i1] = (Real)0;
61 result.rectangleParameter[0] = srResult.rectangleParameter[0];
62 result.rectangleParameter[1] = srResult.rectangleParameter[1];
63 result.closestPoint[0] = srResult.closestPoint[0];
64 result.closestPoint[1] = srResult.closestPoint[1];
69 for (
int i1 = 0; i1 < 2; ++i1)
71 for (
int i0 = -1; i0 <= 1; i0 += 2)
73 Real
s = i0 * rectangle.extent[1 - i1];
75 s * rectangle.axis[1 - i1];
77 rectangle.extent[i1]);
80 auto stResult = stQuery(edge, triangle);
81 if (stResult.sqrDistance < result.sqrDistance)
83 result.distance = stResult.distance;
84 result.sqrDistance = stResult.sqrDistance;
85 result.triangleParameter[0] = stResult.triangleParameter[0];
86 result.triangleParameter[1] = stResult.triangleParameter[1];
87 result.triangleParameter[2] = stResult.triangleParameter[2];
88 result.rectangleParameter[i1] =
s;
89 result.rectangleParameter[1 - i1] = stResult.segmentParameter;
90 result.closestPoint[0] = stResult.closestPoint[1];
91 result.closestPoint[1] = stResult.closestPoint[0];
GLsizei GLsizei GLfloat distance
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
Real Normalize(GVector< Real > &v, bool robust=false)