From fcfcddfdae168cd42491210528ff51f476b4dfb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 19 Jul 2020 21:46:56 +0200 Subject: fix distance() --- HexBoard.gd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/HexBoard.gd b/HexBoard.gd index 993776d..0bc6fa1 100644 --- a/HexBoard.gd +++ b/HexBoard.gd @@ -184,11 +184,13 @@ func distance(p0 : Vector2, p1 : Vector2, euclidean : bool = true) -> float: var fdy : float = dy * 0.86602 return sqrt((fdx * fdx) + (fdy * fdy)) else: - var dz : float = abs((p0.x - p0.y) - (p1.x - p1.y)) + dx = int(abs(dx)) + dy = int(abs(dy)) + var dz : float = abs(p1.x - p0.x - p1.y + p0.y) if dx > dy: - if dx > dz : return abs(dx) + if dx > dz: return float(dx) else: - if dy > dz: return abs(dy) + if dy > dz: return float(dy) return dz # http://zvold.blogspot.com/2010/01/bresenhams-line-drawing-algorithm-on_26.html -- cgit v1.1-2-g2b99