1.9 KiB
1.9 KiB
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— appendpub 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::containsis true for corners/interior and false just outside.Rect::intersectsis symmetric; true for overlap, false for adjacent-but-disjoint rects.Rect::iteryields exactlyw * hdistinct points, all contained.Rect::centerreturns an interior point.Point::manhattanis correct and symmetric.Line::cellsyields a contiguous run fromfromtotoinclusive 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 tolib.rs.- All tests pass:
cargo test -p reikhelm-core geometry
Commit
"feat(core): geometry primitives (Point, Rect, Line)"