Skip to content

Commit 1052bc4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 49f317a commit 1052bc4

File tree

1 file changed

+61
-19
lines changed

1 file changed

+61
-19
lines changed

physics/collision_detection.py

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@
2222

2323

2424
def is_aabb_collision(
25-
x1: float, y1: float, w1: float, h1: float,
26-
x2: float, y2: float, w2: float, h2: float,
25+
x1: float,
26+
y1: float,
27+
w1: float,
28+
h1: float,
29+
x2: float,
30+
y2: float,
31+
w2: float,
32+
h2: float,
2733
) -> bool:
2834
"""
2935
Check if two Axis-Aligned Bounding Boxes (AABBs) are colliding.
@@ -57,8 +63,12 @@ def is_aabb_collision(
5763

5864

5965
def is_circle_collision(
60-
cx1: float, cy1: float, r1: float,
61-
cx2: float, cy2: float, r2: float,
66+
cx1: float,
67+
cy1: float,
68+
r1: float,
69+
cx2: float,
70+
cy2: float,
71+
r2: float,
6272
) -> bool:
6373
"""
6474
Check if two circles are colliding.
@@ -85,12 +95,17 @@ def is_circle_collision(
8595

8696
distance_squared = (cx2 - cx1) ** 2 + (cy2 - cy1) ** 2
8797
radius_sum = r1 + r2
88-
return distance_squared < radius_sum ** 2
98+
return distance_squared < radius_sum**2
8999

90100

91101
def is_circle_aabb_collision(
92-
cx: float, cy: float, r: float,
93-
rx: float, ry: float, rw: float, rh: float,
102+
cx: float,
103+
cy: float,
104+
r: float,
105+
rx: float,
106+
ry: float,
107+
rw: float,
108+
rh: float,
94109
) -> bool:
95110
"""
96111
Check if a circle and an Axis-Aligned Bounding Box (AABB) are colliding.
@@ -129,8 +144,12 @@ def is_circle_aabb_collision(
129144

130145

131146
def is_point_in_rectangle(
132-
px: float, py: float,
133-
rx: float, ry: float, rw: float, rh: float,
147+
px: float,
148+
py: float,
149+
rx: float,
150+
ry: float,
151+
rw: float,
152+
rh: float,
134153
) -> bool:
135154
"""
136155
Check if a point is inside an Axis-Aligned Bounding Box (rectangle).
@@ -161,8 +180,11 @@ def is_point_in_rectangle(
161180

162181

163182
def is_point_in_circle(
164-
px: float, py: float,
165-
cx: float, cy: float, r: float,
183+
px: float,
184+
py: float,
185+
cx: float,
186+
cy: float,
187+
r: float,
166188
) -> bool:
167189
"""
168190
Check if a point is inside a circle.
@@ -248,26 +270,46 @@ def _check_collision(obj1: dict, obj2: dict) -> bool:
248270

249271
if type1 == "circle" and type2 == "circle":
250272
return is_circle_collision(
251-
obj1["cx"], obj1["cy"], obj1["r"],
252-
obj2["cx"], obj2["cy"], obj2["r"],
273+
obj1["cx"],
274+
obj1["cy"],
275+
obj1["r"],
276+
obj2["cx"],
277+
obj2["cy"],
278+
obj2["r"],
253279
)
254280

255281
if type1 == "rect" and type2 == "rect":
256282
return is_aabb_collision(
257-
obj1["x"], obj1["y"], obj1["w"], obj1["h"],
258-
obj2["x"], obj2["y"], obj2["w"], obj2["h"],
283+
obj1["x"],
284+
obj1["y"],
285+
obj1["w"],
286+
obj1["h"],
287+
obj2["x"],
288+
obj2["y"],
289+
obj2["w"],
290+
obj2["h"],
259291
)
260292

261293
if type1 == "circle" and type2 == "rect":
262294
return is_circle_aabb_collision(
263-
obj1["cx"], obj1["cy"], obj1["r"],
264-
obj2["x"], obj2["y"], obj2["w"], obj2["h"],
295+
obj1["cx"],
296+
obj1["cy"],
297+
obj1["r"],
298+
obj2["x"],
299+
obj2["y"],
300+
obj2["w"],
301+
obj2["h"],
265302
)
266303

267304
if type1 == "rect" and type2 == "circle":
268305
return is_circle_aabb_collision(
269-
obj2["cx"], obj2["cy"], obj2["r"],
270-
obj1["x"], obj1["y"], obj1["w"], obj1["h"],
306+
obj2["cx"],
307+
obj2["cy"],
308+
obj2["r"],
309+
obj1["x"],
310+
obj1["y"],
311+
obj1["w"],
312+
obj1["h"],
271313
)
272314

273315
msg = f"Unknown object types: {type1}, {type2}"

0 commit comments

Comments
 (0)