// If our point projected off the end of the segment, return the dSquared between
// the point and the end
if (proj >= segSquared) {
if (closest != null) closest.set(end);
dt.sub(pt, end);
return dt.lengthSquared();
}
// We projected somewhere along the segment, calculate the closest point
dt.scaleAdd(proj / segSquared, dir, start);
if (closest != null) closest.set(dt);