Skip to content

Commit c01c2ce

Browse files
Rapen765pushfoo
andauthored
Fix math point types (#2430)
* Fixed rand_in_circle to ensure uniform distribution of points * fixed math point types * fixed rand_vec_magnitude documentation * Update arcade/math.py Co-authored-by: Paul <36696816+pushfoo@users.noreply.github.com> * Update arcade/math.py Co-authored-by: Paul <36696816+pushfoo@users.noreply.github.com> * Run formatting --------- Co-authored-by: Paul <36696816+pushfoo@users.noreply.github.com>
1 parent 4d65b60 commit c01c2ce

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

arcade/math.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,19 @@ def rand_in_circle(center: Point2, radius: float) -> Point2:
235235
# random radius
236236
r = radius * math.sqrt(random.random())
237237
# calculating coordinates
238-
return (r * math.cos(angle) + center[0], r * math.sin(angle) + center[1])
238+
return r * math.cos(angle) + center[0], r * math.sin(angle) + center[1]
239239

240240

241241
def rand_on_circle(center: Point2, radius: float) -> Point2:
242242
"""
243243
Generate a point on a circle.
244244
245-
.. note: by passing a random value in for float,
246-
you can achieve what rand_in_circle() does
247-
248245
Args:
249246
center (Point2): The center of the circle
250247
radius (float): The radius of the circle
251248
"""
252249
angle = 2 * math.pi * random.random()
253-
return (radius * math.cos(angle) + center[0], radius * math.sin(angle) + center[1])
250+
return radius * math.cos(angle) + center[0], radius * math.sin(angle) + center[1]
254251

255252

256253
def rand_on_line(pos1: Point2, pos2: Point2) -> Point:
@@ -284,9 +281,7 @@ def rand_angle_spread_deg(angle: float, half_angle_spread: float) -> float:
284281
return angle + s
285282

286283

287-
def rand_vec_spread_deg(
288-
angle: float, half_angle_spread: float, length: float
289-
) -> tuple[float, float]:
284+
def rand_vec_spread_deg(angle: float, half_angle_spread: float, length: float) -> Point2:
290285
"""
291286
Returns a random vector, within a spread of the given angle.
292287
@@ -304,12 +299,12 @@ def rand_vec_magnitude(
304299
angle: float,
305300
lo_magnitude: float,
306301
hi_magnitude: float,
307-
) -> tuple[float, float]:
302+
) -> Point2:
308303
"""
309-
Returns a random vector, within a spread of the given angle.
304+
Return a vector of randomized magnitude pointing in the given direction.
310305
311306
Args:
312-
angle (float): The angle to spread from
307+
angle (float): The vector angle in radians
313308
lo_magnitude (float): The lower magnitude
314309
hi_magnitude (float): The higher magnitude
315310
"""

0 commit comments

Comments
 (0)