Skip to content

Commit 780eb0a

Browse files
bluetoothbotclaude
andauthored
perf(distance): use ** operator and drop * 1.0 idiom (#269)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 967cc9f commit 780eb0a

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from typing import cast
2-
31
MAX_THEORETICAL_DISTANCE = 400.0
42

53

64
def calculate_distance_meters(power: int, rssi: int) -> float | None:
75
"""Calculate the distance in meters between the scanner and the device."""
86
if rssi == 0 or power == 0:
97
return None
10-
if (ratio := rssi * 1.0 / power) < 1.0:
11-
distance = pow(ratio, 10)
8+
if (ratio := rssi / power) < 1.0:
9+
distance = ratio**10
1210
else:
13-
distance = cast(float, 0.89976 * pow(ratio, 7.7095) + 0.111)
11+
distance = 0.89976 * ratio**7.7095 + 0.111
1412
return min(distance, MAX_THEORETICAL_DISTANCE)

0 commit comments

Comments
 (0)