// GJK is more robust with polygon-vs-point than polygon-vs-circle.
// So we convert polygon-vs-circle to polygon-vs-point.
public static float DistancePC(out Vec2 x1, out Vec2 x2,
PolygonShape polygon, XForm xf1, CircleShape circle, XForm xf2)
{
Point point = new Point();
point.p = Common.Math.Mul(xf2, circle.GetLocalPosition());
float distance = DistanceGeneric <PolygonShape, Point>(out x1, out x2, polygon, xf1, point, XForm.Identity);
float r = circle.GetRadius() - Settings.ToiSlop;
if (distance > r)
{
distance -= r;
Vec2 d = x2 - x1;
d.Normalize();
x2 -= r * d;
}
else
{
distance = 0.0f;
x2 = x1;
}
return(distance);
}