Skip to content

Commit 6d9b9a2

Browse files
HandyS11claude
andcommitted
fix(2a): derive grid row count from Height, not Width (final review)
GridReference computed the row count from Width and never read Height/ OceanMargin — correct only because Rust maps are square. Derive each axis from its own dimension so the grid math is correct by construction. Behavior-preserving for square maps; GridReference tests unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent dc347ba commit 6d9b9a2

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/RustPlusBot.Features.Events/Formatting/GridReference.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public static string From(float x, float y, MapDimensions? dims)
2323
$"({Math.Round(x)}, {Math.Round(y)})");
2424
}
2525

26-
var mapSize = dims.Width;
27-
var columns = (int)Math.Ceiling(mapSize / GridDiameter);
28-
var col = (int)Math.Floor(Math.Clamp(x, 0f, mapSize - 1) / GridDiameter);
26+
// Columns run along X (Width); rows along Y (Height). Rust maps are square in practice, but
27+
// derive each axis from its own dimension so the math is correct by construction, not by accident.
28+
var col = (int)Math.Floor(Math.Clamp(x, 0f, dims.Width - 1) / GridDiameter);
29+
var rowCount = (int)Math.Ceiling(dims.Height / GridDiameter);
2930
// Rows are numbered from the TOP; world Y increases upward, so invert.
30-
var rowFromBottom = (int)Math.Floor(Math.Clamp(y, 0f, mapSize - 1) / GridDiameter);
31-
var row = Math.Max(0, columns - rowFromBottom - 1);
31+
var rowFromBottom = (int)Math.Floor(Math.Clamp(y, 0f, dims.Height - 1) / GridDiameter);
32+
var row = Math.Max(0, rowCount - rowFromBottom - 1);
3233

3334
return string.Create(CultureInfo.InvariantCulture, $"{ColumnLetters(col)}{row}");
3435
}

0 commit comments

Comments
 (0)