From ec856947b9b82ff7c4678a37b8246f9907cac284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 8 Jul 2020 13:26:53 +0200 Subject: HexBoard : shorten contact point computation --- .../ch/asynk/gdx/boardgame/boards/HexBoard.java | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java index f22b824..35bfac5 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java @@ -453,23 +453,20 @@ public class HexBoard implements Board v.set(t.cx, t.cy + side); } else if (o == Orientation.E) { float x = t.cx - dw; - float y = from.cy + m * (x - from.cx); - v.set(x, y); + v.set(x, from.cy + m * (x - from.cx)); } else if (o == Orientation.W) { float x = t.cx + dw; - float y = from.cy + m * (x - from.cx); - v.set(x, y); + v.set(x, from.cy + m * (x - from.cx)); } else { if (line) { - float k = 0; float p = ((o == Orientation.SE || o == Orientation.NW) ? slope : -slope); + float k = t.cy - (p * t.cx); if (o == Orientation.SE || o == Orientation.SW) - k = (t.cy + side) - (p * t.cx); + k += side; else - k = (t.cy - side) - (p * t.cx); + k -= side; float x = (k - c) / (m - p); - float y = m * x + c; - v.set(x, y); + v.set(x, m * x + c); } else { float x = t.cx + ((o == Orientation.NE || o == Orientation.SE) ? -dw : dw); float y = t.cy + ((o == Orientation.SE || o == Orientation.SW) ? dh : -dh); @@ -483,12 +480,10 @@ public class HexBoard implements Board v.set(t.cx + side, t.cy); } else if (o == Orientation.N) { float y = t.cy - dw; - float x = from.cx + (y - from.cy) / m; - v.set(x, y); + v.set(from.cx + (y - from.cy) / m, y); } else if (o == Orientation.S) { float y = t.cy + dw; - float x = from.cx + (y - from.cy) / m; - v.set(x, y); + v.set(from.cx + (y - from.cy) / m, y); } else { if (line) { float k = 0; @@ -498,8 +493,7 @@ public class HexBoard implements Board else k = t.cy - (p * (t.cx - side)); float x = (k - c) / (m - p); - float y = m * x + c; - v.set(x, y); + v.set(x, m * x + c); } else { float x = t.cx + ((o == Orientation.NW || o == Orientation.SW) ? dh: -dh); float y = t.cy + ((o == Orientation.SE || o == Orientation.SW) ? dw : -dw); -- cgit v1.1-2-g2b99