reikhelm/.dev/2026-05-28-procgen-map-core/tasks/02-geometry.md
Parley Hatch 08e99e38a3 chore: scaffold reikhelm cargo workspace (core + viz crates)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-28 20:56:24 -06:00

36 lines
1.9 KiB
Markdown

# Task 2: Geometry
**Depends on:** Task 1
## Context Files
- `.dev/2026-05-28-procgen-map-core/spec/design.md` — §4.1 (geometry).
- `reikhelm-core/src/lib.rs` — append the module declaration here.
## Files
- Create: `reikhelm-core/src/geometry.rs``Point`, `Rect`, `Line`.
- Modify: `reikhelm-core/src/lib.rs` — append `pub mod geometry;`.
## What to Build
Integer grid-coordinate geometry types (spec §4.1). All types derive `Clone, Copy, Debug, PartialEq, Eq` and `serde::{Serialize, Deserialize}`. These are the foundation reused by the grid, regions, and every pass — keep them small and total (no panics on valid input).
## Interface Dependencies
- **Produces:**
- `Point { x: i32, y: i32 }``new`, `manhattan(&self, other: Point) -> i32`, and offset helpers for the four/eight neighbor directions.
- `Rect { x: i32, y: i32, w: i32, h: i32 }``new`, `center() -> Point`, `contains(Point) -> bool`, `intersects(&Rect) -> bool`, `inflate(by: i32) -> Rect`, `iter() -> impl Iterator<Item = Point>` (all contained cells).
- `Line { from: Point, to: Point }``cells() -> impl Iterator<Item = Point>` yielding the grid cells along the segment (a straight horizontal/vertical run is sufficient for v1 corridors; document the behavior).
## Tests
- `Rect::contains` is true for corners/interior and false just outside.
- `Rect::intersects` is symmetric; true for overlap, false for adjacent-but-disjoint rects.
- `Rect::iter` yields exactly `w * h` distinct points, all contained.
- `Rect::center` returns an interior point.
- `Point::manhattan` is correct and symmetric.
- `Line::cells` yields a contiguous run from `from` to `to` inclusive for a horizontal and a vertical line.
## Success Criteria
- [ ] All listed types and methods exist with the signatures above and derive serde.
- [ ] `pub mod geometry;` added to `lib.rs`.
- [ ] All tests pass: `cargo test -p reikhelm-core geometry`
## Commit
`"feat(core): geometry primitives (Point, Rect, Line)"`