Skip to content

Commit 4323e9e

Browse files
author
Aditya
committed
Rename parameter r to radius for clarity
Address review feedback from algorithms-keeper: use descriptive parameter name 'radius' instead of 'r' in is_circle_aabb_collision and is_point_in_circle functions.
1 parent 1052bc4 commit 4323e9e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

physics/collision_detection.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def is_circle_collision(
101101
def is_circle_aabb_collision(
102102
cx: float,
103103
cy: float,
104-
r: float,
104+
radius: float,
105105
rx: float,
106106
ry: float,
107107
rw: float,
@@ -110,7 +110,7 @@ def is_circle_aabb_collision(
110110
"""
111111
Check if a circle and an Axis-Aligned Bounding Box (AABB) are colliding.
112112
113-
The circle is defined by its center (cx, cy) and radius (r).
113+
The circle is defined by its center (cx, cy) and radius.
114114
The rectangle is defined by its top-left corner (rx, ry), width (rw),
115115
and height (rh).
116116
@@ -131,7 +131,7 @@ def is_circle_aabb_collision(
131131
...
132132
ValueError: Width and height must be non-negative
133133
"""
134-
if r < 0:
134+
if radius < 0:
135135
raise ValueError("Radius must be non-negative")
136136
if rw < 0 or rh < 0:
137137
raise ValueError("Width and height must be non-negative")
@@ -140,7 +140,7 @@ def is_circle_aabb_collision(
140140
closest_y = max(ry, min(cy, ry + rh))
141141

142142
distance_squared = (cx - closest_x) ** 2 + (cy - closest_y) ** 2
143-
return distance_squared < r**2
143+
return distance_squared < radius**2
144144

145145

146146
def is_point_in_rectangle(
@@ -184,13 +184,13 @@ def is_point_in_circle(
184184
py: float,
185185
cx: float,
186186
cy: float,
187-
r: float,
187+
radius: float,
188188
) -> bool:
189189
"""
190190
Check if a point is inside a circle.
191191
192192
The point is defined by (px, py).
193-
The circle is defined by its center (cx, cy) and radius (r).
193+
The circle is defined by its center (cx, cy) and radius.
194194
195195
>>> is_point_in_circle(3, 4, 0, 0, 10)
196196
True
@@ -205,11 +205,11 @@ def is_point_in_circle(
205205
...
206206
ValueError: Radius must be non-negative
207207
"""
208-
if r < 0:
208+
if radius < 0:
209209
raise ValueError("Radius must be non-negative")
210210

211211
distance_squared = (px - cx) ** 2 + (py - cy) ** 2
212-
return distance_squared < r**2
212+
return distance_squared < radius**2
213213

214214

215215
def detect_all_collisions(

0 commit comments

Comments
 (0)