From e9db004a7a17911c33c01c6190e62af4567c2f36 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 12 May 2022 08:46:45 -0700 Subject: [PATCH] Add Point.euclidean_distance_to() Does what it says on the tin. --- roguebasin/geometry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roguebasin/geometry.py b/roguebasin/geometry.py index e76ef36..872777d 100644 --- a/roguebasin/geometry.py +++ b/roguebasin/geometry.py @@ -2,6 +2,7 @@ '''A bunch of geometric primitives''' +import math from dataclasses import dataclass from typing import Any, Iterator, Optional, overload @@ -35,6 +36,10 @@ class Point: return None + def euclidean_distance_to(self, other: 'Point') -> float: + '''Compute the Euclidean distance to another Point''' + return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2) + @overload def __add__(self, other: 'Vector') -> 'Point': ...