Skip to content

Add closest point on rectangle to circle to olc #252

Description

@Johnnyg63

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 };
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions