2025-08-02 06:10:41 +02:00
|
|
|
import math
|
2025-08-02 09:05:30 +02:00
|
|
|
from dataclasses import dataclass
|
2025-08-02 06:10:41 +02:00
|
|
|
|
|
|
|
|
2025-08-02 09:05:30 +02:00
|
|
|
@dataclass
|
2025-08-02 06:10:41 +02:00
|
|
|
class Coordinates:
|
|
|
|
latitude: int
|
|
|
|
longitude: int
|
|
|
|
|
|
|
|
|
|
|
|
def distance_between_coords(lhs: Coordinates, rhs: Coordinates) -> float:
|
|
|
|
R = 6371000 # Earth radius in meters
|
|
|
|
|
|
|
|
def to_rad(deg):
|
|
|
|
return (deg * math.pi) / 180
|
|
|
|
|
|
|
|
d_lat = to_rad(rhs.latitude - lhs.latitude)
|
|
|
|
d_lon = to_rad(rhs.longitude - lhs.longitude)
|
|
|
|
|
|
|
|
a = (d_lat / 2) ** 2 + (to_rad(lhs.latitude) * to_rad(rhs.latitude)) * (d_lon / 2) ** 2
|
|
|
|
|
|
|
|
c = 2 * (a**0.5) / ((1 - a) ** 0.5)
|
|
|
|
|
|
|
|
return R * c # distance in meters
|
|
|
|
|
|
|
|
|
|
|
|
def is_within_range(my_coords: Coordinates, target_coords: Coordinates, max_range: float) -> bool:
|
|
|
|
distance = distance_between_coords(my_coords, target_coords)
|
|
|
|
return distance <= max_range
|