You are given a circle centered at (cx, cy) with radius r, and a point (x, y). Determine whether the point lies inside the circle or on its boundary.
Return True if the point lies inside or on the circle, otherwise return False.
Function Signature
def is_point_in_circle(cx: int, cy: int, r: int, x: int, y: int) -> bool:
Rules
-
All five inputs are integers.
-
A point exactly on the circle counts as inside, so the function returns
True
for it.
-
When
r = 0
the circle is the single point
(cx, cy)
.
Constraints
-
-10^4 <= cx, cy, x, y <= 10^4
-
0 <= r <= 10^4
Examples
Input: cx = 0, cy = 0, r = 5, x = 3, y = 4
Output: True
The squared distance from (3, 4) to (0, 0) is 9 + 16 = 25, which equals r squared (25). The point sits exactly on the boundary, and the boundary counts as inside.
Input: cx = 1, cy = 1, r = 2, x = 5, y = 5
Output: False
The squared distance from (5, 5) to (1, 1) is 16 + 16 = 32, which is greater than r squared (4). The point is outside the circle.
Input: cx = 2, cy = -3, r = 0, x = 2, y = -3
Output: True
With radius 0 the circle is the single point (2, -3). The query point is that same point, so the squared distance is 0 and 0 <= 0 holds.