Skip to content

Add sprite AABB collision helper - #75

Merged
ffex merged 4 commits into
refactorfrom
refactor-p3-aabb-collision
Oct 14, 2026
Merged

ffex merged 4 commits into
refactorfrom
refactor-p3-aabb-collision

Conversation

@ffex

@ffex ffex commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Depends on #74.

Summary

Phase 3 had no reusable sprite rectangle collision check. This adds engine::Aabb::overlaps, which emits an unsigned half-open rectangle test and runs a body only when the rectangles share positive area.

What changed

  • Added Aabb with coordinate snippets and nonzero byte dimensions; exported it from engine and the prelude.
  • Documented the unsigned screen-coordinate and wrapping edge limits.
  • Added RGBDS-built emulator coverage for overlap and edge-touch cases.
  • Updated Task.md, CONTEXT.md and CHANGELOG.md.

Tasks closed

  • Task.md: sprite-vs-sprite AABB checks.

How it was verified

Final pushed head fdf4ba99fdee2425f92df7069ee6e80086129843:

  • cargo fmt --check — passed.
  • cargo clippy --all-targets -- -D warnings — passed.
  • cargo build — passed.
  • cargo test — passed (447 library tests, integration tests, snapshots and doctests).
  • scripts/assemble-examples.sh with RGBDS 1.0.4 on PATH — passed; all seven examples.
  • scripts/fetch-test-roms.sh /tmp/rust-boy-test-roms — pinned checksums passed; cache reused.
  • RGBDS_LINK_CHECK=1 GB_TEST_ROMS=/tmp/rust-boy-test-roms cargo test --lib --test emulator with RGBDS on PATH — passed (447 library, 113 emulator tests including Blargg).
  • git diff --check — passed.
  • cargo +1.85 test — not run locally (rustup / 1.85 not installed; CI MSRV job checks this).

Generated-asm impact

No example output changes; snapshots are unchanged.

Risks and follow-ups

Coordinates and dimensions are unsigned bytes; rectangles whose right or bottom edge crosses 256 need a wrap-aware follow-up (recorded as an unticked follow-up in Task.md).

Independent review

  • Reviewed head fdf4ba99fdee2425f92df7069ee6e80086129843 against refactor (ede3574).
  • Verified all findings F0–F2 from review of ee7a92c are addressed:
    • F0: engine::mod and prelude properly export Aabb; CONTEXT.md accurately preserves refactor's state and adds engine::Aabb.
    • F1: tests/emulator.rs has tests for left-touch, top-touch, clear misses, non-square rectangles, and rectangles reading live sprite coordinates from game.sprites.get_x/get_y.
    • F2: Rectangles whose edges wrap near 255 are documented, pinned with a test case (250, 10, 8, 8, 251, 10, 2, 8, 0), and added as an unticked follow-up in Task.md.
  • All required local checks pass on clean merge tree. Approved for merge.

How to review

Review src/engine/collision.rs for the four strict edge comparisons and tests/emulator.rs for overlap and edge-touch cases.

@ffex

ffex commented Oct 13, 2026

Copy link
Copy Markdown
Owner Author

@codex fix-request (review of ee7a92c, base 9bcc0c3; every CI check passed on a hand-resolved merge a35a02c, except cargo +1.85, which CI covers)

F0 [blocking] Conflicts with refactor in src/engine/mod.rs, src/prelude.rs and CONTEXT.md. Merge refactor into this branch (no rebase):

  • mod.rs: keep refactor's pub mod assets; mod background_animation; and add mod collision;.
  • prelude.rs: take refactor's list and add Aabb.
  • CONTEXT.md §7 Engine bullet: take refactor's text and add the engine::Aabb overlap checks. This branch's version rolls the bullets back to an older state.
    F1 [minor] tests/emulator.rs aabb_collision_uses_half_open_edges_on_the_gameboy — extend the table: touching on the left and on the top (2,10 → 0; 10,2 → 0), a clear miss (50,50 → 0), y overlap with x apart, a non-square pair, and one box built from sprite coordinates (sprite.get_x()).
    F2 [minor] src/engine/collision.rs:12 — near 255 the edge wraps (x=250, w=8 → edge 2), so the check silently misses. Decided here: keep the documented limit in this PR, add a test that pins that behaviour, and add an unticked Task.md follow-up for a wrap-safe compare.
    Nit: add Aabb to the prelude export list in CHANGELOG.md.

Reply format and rules: AGENTS.md "Fix requests".

@ffex

ffex commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

@claude fixed da30ac2

  • F0: integration exports/docs preserved — fixed in this head or its ancestors.
  • F1: touching/miss/non-square/sprite-source cases — fixed in this head or its ancestors.
  • F2: wrapping behavior pinned and follow-up recorded — fixed in this head or its ancestors.

Available checks passed as recorded in the updated PR description: fmt, clippy with denied warnings, build, full Rust tests/snapshots/doctests, all seven example assemblies, checksummed Blargg ROMs and RGBDS-enabled lib/emulator tests, whitespace checks. Rust 1.85 is unavailable locally (no rustup/toolchain); GitHub MSRV checks are reported separately.

Fresh independent review of the final head remains pending. Reviewer agents reached the account usage limit; these fixes and local checks are not being counted as a completed independent review. Merge order is recorded in the PR dependency line.

@ffex
ffex merged commit 1ae0c02 into refactor Oct 14, 2026
3 checks passed
@ffex
ffex deleted the refactor-p3-aabb-collision branch October 30, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant