Skip to content

feat: 018 — larger pig hitbox - #20

Merged
archae0pteryx merged 2 commits into
mainfrom
feat/018-pig-hitbox
May 3, 2026
Merged

feat: 018 — larger pig hitbox#20
archae0pteryx merged 2 commits into
mainfrom
feat/018-pig-hitbox

Conversation

@archae0pteryx

@archae0pteryx archae0pteryx commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds HITBOX_PADDING = 16 constant (exported)
  • Extracts buildHitRects(pigs, dpr) as pure function — rect size is PIG_SIZE + HITBOX_PADDING, centred on sprite with -(HITBOX_PADDING/2) offset
  • syncRects delegates to buildHitRects; no Rust changes needed

Test plan

  • 6 new unit tests covering padding size, x/y centering, dpr scaling, and multi-pig output
  • task check green
  • Clicking ~8px outside pig sprite still registers as pig click at runtime

Closes #16

Summary by CodeRabbit

  • Improvements

    • Expanded and centered interaction areas around on-screen pigs so they are easier and more reliable to click or tap across display scales and device pixel ratios.
  • Tests

    • Added automated tests validating hitbox padding, scaling, centering, and that one interaction rect is produced per pig to ensure consistent behavior.

Extract buildHitRects as pure function so rect logic is testable
without Tauri. Hitbox is 16px larger than sprite and centred,
so clicks within ~8px outside the pig still register.
@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a97354bd-ca9f-4928-a005-2dd7f901213d

📥 Commits

Reviewing files that changed from the base of the PR and between 6563b48 and e8ff469.

📒 Files selected for processing (1)
  • src/hooks/usePigMovement.ts

📝 Walkthrough

Walkthrough

Adds HITBOX_PADDING = 16, exports PigHitRect and buildHitRects(pigs, dpr) to produce centered, padded, DPR-scaled hit rectangles, and updates syncRects to use the helper. Adds tests verifying the constant, rect geometry, DPR scaling, and one-rect-per-pig behavior.

Changes

Hitbox Padding & Rect Building

Layer / File(s) Summary
Constants
src/hooks/usePigMovement.ts
Introduces export const HITBOX_PADDING = 16.
Types & Helper
src/hooks/usePigMovement.ts
Adds export interface PigHitRect { x: number; y: number; size: number } and export function buildHitRects(pigs: PigState[], dpr: number): PigHitRect[] that produces centered padded squares sized (PIG_SIZE + HITBOX_PADDING) * dpr.
Integration
src/hooks/usePigMovement.ts
syncRects now uses buildHitRects(pigs, dpr) for non-detailOpen rects; detailOpen full-viewport rect remains unchanged.
Tests / Verification
src/hooks/usePigMovement.test.ts
New Vitest suite asserts HITBOX_PADDING === 16, verifies buildHitRects sizing, centering offset of HITBOX_PADDING/2, DPR scaling, and that output length equals input pigs.
sequenceDiagram
  participant User
  participant React_UI as React (PigSprite)
  participant Hook as usePigMovement
  participant Rust as WASM/Rust PigHitTester

  User->>React_UI: click near pig
  React_UI->>Hook: (render / polling) request pig rects
  Hook->>Hook: buildHitRects(pigs, dpr) -> padded DPR-scaled rects
  Hook->>Rust: update_pig_rects(rects)
  Rust->>Rust: PigHitTester.is_hit checks rects against cursor
  Rust-->>React_UI: (hit result) toggle click-through / state
  React_UI-->>User: UI response (detail open / click)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Sixteen pixels soft and round,

The pig's new footprint found its ground.
Clicks that missed now find their mark,
Little pigs glow in the park. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: 018 — larger pig hitbox' clearly and concisely describes the main change: adding a larger hitbox to pig collision detection.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #16: HITBOX_PADDING constant exported, buildHitRects function computes correctly centered and padded hit rectangles, syncRects delegates to buildHitRects, and comprehensive unit tests verify the implementation.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #16 requirements: new exports (HITBOX_PADDING, PigHitRect, buildHitRects), hitbox computation logic, and corresponding test coverage. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/018-pig-hitbox

Review rate limit: 6/10 reviews remaining, refill in 19 minutes and 39 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/usePigMovement.ts`:
- Around line 127-130: The function buildHitRects currently returns an inline
object type; define and export a named type/interface (e.g., export type HitRect
= { x: number; y: number; size: number }) at the top of the module and change
the function signature to return HitRect[] (keeping PigState and dpr as-is),
then update any usages to reference HitRect so the module boundary uses a named
type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 10d35d8c-05a9-4a3f-8cb9-ac5dacd734d5

📥 Commits

Reviewing files that changed from the base of the PR and between 9d896cf and 6563b48.

📒 Files selected for processing (2)
  • src/hooks/usePigMovement.test.ts
  • src/hooks/usePigMovement.ts

Comment thread src/hooks/usePigMovement.ts Outdated
@archae0pteryx
archae0pteryx merged commit 16bbd39 into main May 3, 2026
1 of 2 checks passed
@archae0pteryx
archae0pteryx deleted the feat/018-pig-hitbox branch May 3, 2026 15:37
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.

018 — Larger pig hitbox

1 participant