summaryrefslogtreecommitdiffstats
path: root/HexBoard.gd
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-19 21:46:56 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-19 21:46:56 +0200
commitfcfcddfdae168cd42491210528ff51f476b4dfb8 (patch)
tree11e03784671aed17df577526a74af02b2311e626 /HexBoard.gd
parent2320bc526783ac3fb86e52dde07e8bb736a76286 (diff)
downloadgodot-hexgrid-fcfcddfdae168cd42491210528ff51f476b4dfb8.zip
godot-hexgrid-fcfcddfdae168cd42491210528ff51f476b4dfb8.tar.gz
fix distance()
Diffstat (limited to 'HexBoard.gd')
-rw-r--r--HexBoard.gd8
1 files 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