While working on Johnny Got's the Runs, I needed to add a closest method for rect to circle in order to support collisions.
// closest(r,c)
// Returns closest point on rectangle to circle
template<typename T1, typename T2>
inline olc::v_2d<T1> closest(const rect<T1>& r, const circle<T2>& l)
{
// Johnnyg63
const auto pX = std::clamp(l.pos.x, r.pos.x, r.pos.x + r.size.x);
const auto pY = std::clamp(l.pos.y, r.pos.y, r.pos.y + r.size.y);
return { pX, pY };
}
While working on Johnny Got's the Runs, I needed to add a closest method for rect to circle in order to support collisions.