Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Last active March 3, 2021 20:21
Show Gist options
  • Save MartinThoma/e8e25e395311227b4a7eab02e65fc4e9 to your computer and use it in GitHub Desktop.
Save MartinThoma/e8e25e395311227b4a7eab02e65fc4e9 to your computer and use it in GitHub Desktop.
from typing import Optional
import attr
@attr.s
class Position:
longitude: float = attr.ib()
latitude: float = attr.ib()
address: Optional[str] = attr.ib(default=None)
@longitude.validator
def check_long(self, attribute, v):
if not (-180 <= v <= 180):
raise ValueError(f"Longitude was {v}, but must be in [-180, +180]")
@latitude.validator
def check_lat(self, attribute, v):
if not (-90 <= v <= 90):
raise ValueError(f"Latitude was {v}, but must be in [-90, +90]")
pos1 = Position(49.0127913, 8.4231381, "Parkstraße 17")
pos2 = Position(42.1238762, 9.1649964)
def get_distance(p1: Position, p2: Position) -> float:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment