aboutsummaryrefslogtreecommitdiff
path: root/src/common/math.hpp
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2026-01-20 01:22:45 +0100
committerfschildt <florian.schildt@protonmail.com>2026-01-20 01:59:19 +0100
commit6da9be5810bf82e9d0b3b2a8bce7606ef2e2bf93 (patch)
tree28bb67ad879f8bbb36476a537fe8b69195500146 /src/common/math.hpp
parentf463853872210415e06fb3f863325fdba303ab65 (diff)
breakout: delete pong, add breakout
Diffstat (limited to 'src/common/math.hpp')
-rw-r--r--src/common/math.hpp24
1 files changed, 24 insertions, 0 deletions
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 <cstddef>
#include <cstdint>
+#include <common/shapes.hpp>
+#include <algorithm>
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;
+}
+