From 6da9be5810bf82e9d0b3b2a8bce7606ef2e2bf93 Mon Sep 17 00:00:00 2001 From: fschildt Date: Tue, 20 Jan 2026 01:22:45 +0100 Subject: breakout: delete pong, add breakout --- src/common/math.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/common') diff --git a/src/common/math.hpp b/src/common/math.hpp index afbda1a..48a5869 100644 --- a/src/common/math.hpp +++ b/src/common/math.hpp @@ -2,6 +2,8 @@ #include #include +#include +#include struct V2ST { @@ -56,3 +58,25 @@ struct Color { float a; }; + +inline bool +Intersect_Rectangle_Circle(Rectangle rect, Circle circle) +{ + float xmin = std::min(rect.x0, rect.x1); + float xmax = std::max(rect.x0, rect.x1); + float ymin = std::min(rect.y0, rect.y1); + float ymax = std::max(rect.y0, rect.y1); + + float closest_x = std::max(xmin, std::min(circle.x, xmax)); + float closest_y = std::max(ymin, std::min(circle.y, ymax)); + + float dx = closest_x - circle.x; + float dy = closest_y - circle.y; + float d_sq = dx*dx + dy*dy; + + float r_sq = circle.r * circle.r; + + bool is_intersect = d_sq <= r_sq; + return is_intersect; +} + -- cgit v1.2.3