template hex builder fix

This commit is contained in:
dingo
2026-04-05 14:30:00 -04:00
parent 58c5778bfb
commit 323de3982d
@@ -284,7 +284,8 @@ else
const double HexR = 16.0;
const double HexPad = 12.0;
// hexN = radius + 1 (for HexGrid coordinate math)
int hexN = _template.HexSides > 0 ? _template.HexSides : (_pendingHexRadius + 1);
int hexN = _template.HexSides > 0 ? _template.HexSides : (_pendingHexRadius + 1);
int hexPoly = _template.HexPolygonSides > 0 ? _template.HexPolygonSides : _pendingHexPolySides;
int hexDim = 2 * hexN - 1;
double svgW = HexR * Math.Sqrt(3) * (hexDim - 1) + 2 * HexR + 2 * HexPad;
double svgH = HexR * 1.5 * (hexDim - 1) + 2 * HexR + 2 * HexPad;
@@ -303,7 +304,7 @@ else
var hr = row; var hc = col;
double cx = HexCellX(hc, hr, hexN, HexR, HexPad);
double cy = HexCellY(hr, hexN, HexR, HexPad);
<polygon points="@HexPolygonPoints(cx, cy, HexR - 1.0)"
<polygon points="@HexPolygonPoints(cx, cy, HexR - 1.0, hexPoly)"
fill="@GetCellColor(hc, hr)"
stroke="rgba(0,0,0,0.25)" stroke-width="1"
title="@GetCellTooltip(hc, hr)"
@@ -709,12 +710,14 @@ else
return pad + R * 1.5 * (N - 1) + R * 1.5 * r;
}
private static string HexPolygonPoints(double cx, double cy, double R)
private static string HexPolygonPoints(double cx, double cy, double R, int sides = 6)
{
var sb = new System.Text.StringBuilder();
for (int i = 0; i < 6; i++)
for (int i = 0; i < sides; i++)
{
double angle = Math.PI / 180.0 * (60.0 * i - 30.0); // pointy-top
// Start at top (-90°) and go clockwise; for 6 sides this matches the
// original pointy-top hexagon orientation used by the hex grid layout.
double angle = -Math.PI / 2.0 + 2.0 * Math.PI * i / sides;
if (i > 0) sb.Append(' ');
sb.Append(FormattableString.Invariant(
$"{cx + R * Math.Cos(angle):F1},{cy + R * Math.Sin(angle):F1}"));