feat(core): derive PartialEq/Eq on Grid<T> and Map

Lets downstream determinism tests compare maps with `assert_eq!` instead
of a serde-string workaround. Auto-gated on T (Grid<f32> gets only
PartialEq); Map has no float fields so Eq is sound.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Parley Hatch 2026-05-28 21:14:12 -06:00
parent 659ef00017
commit 8c4ef2ed4d
2 changed files with 10 additions and 7 deletions

View file

@ -23,8 +23,11 @@ use crate::geometry::{Point, Rect};
///
/// `Serialize`/`Deserialize` are available whenever `T` itself supports them,
/// so a `Grid<Tile>` can round-trip through serde while a `Grid<SomeNonSerde>`
/// simply does not gain those impls.
#[derive(Clone, Debug, Serialize, Deserialize)]
/// simply does not gain those impls. Likewise `PartialEq`/`Eq` are derived and
/// auto-gated on `T`: `Grid<Tile>` is fully `Eq` (so two maps can be compared
/// directly for determinism tests), while a `Grid<f32>` scratch buffer gains
/// only `PartialEq`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Grid<T> {
width: u32,
height: u32,

View file

@ -38,11 +38,11 @@ pub enum Tile {
/// data directly; the type intentionally holds nothing visual. The `seed` is
/// retained for reproducibility — the same seed reproduces this exact map.
///
/// `Map` does not derive `PartialEq`/`Eq` because its `tiles: Grid<Tile>` does
/// not (the [`crate::grid::Grid`] storage type is generic and only derives the
/// comparison traits where it chooses to). Equality of two maps is established
/// via their serde representation instead — see the round-trip test.
#[derive(Clone, Debug, Serialize, Deserialize)]
/// `Map` derives `PartialEq`/`Eq`: it has no float fields and `Grid<Tile>` is
/// `Eq`, so two maps generated from the same seed can be compared directly with
/// `==` — the cleanest expression of the determinism contract (spec §7). The
/// serde round-trip test additionally checks byte-stable JSON.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Map {
/// The base terrain layer: what tile occupies each cell.
pub tiles: Grid<Tile>,