Skip to content

Fix RoundRect radius clamping and containsRectangle API#1327

Merged
obiot merged 1 commit intomasterfrom
fix/roundrect-copilot-feedback
Mar 28, 2026
Merged

Fix RoundRect radius clamping and containsRectangle API#1327
obiot merged 1 commit intomasterfrom
fix/roundrect-copilot-feedback

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented Mar 28, 2026

Summary

Addresses Copilot review feedback from PR #1326:

  • Width/height setters: now re-clamp radius when dimensions shrink (prevents invalid vertices when size < 2*radius)
  • Negative radius: clamp to 0 in setter (was stored as-is, breaking vertex generation)
  • containsRectangle: accepts any object with left/right/top/bottom (not just RoundRect), preserving Rect compatibility

Test plan

  • All 1829 tests pass (6 new)
  • Width setter clamping, height setter clamping, negative radius constructor, negative radius setter, Rect argument, structural type argument

🤖 Generated with Claude Code

- Width/height setters now re-clamp radius (prevents invalid vertices
  when dimensions shrink below 2*radius)
- Radius setter clamps negative values to 0
- containsRectangle accepts any object with left/right/top/bottom
  (not just RoundRect, preserving Rect compatibility)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 28, 2026 01:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes RoundRect radius handling to prevent invalid vertex generation when dimensions shrink, and widens the containsRectangle API to accept Rect and other rectangle-like objects.

Changes:

  • Re-clamp radius (via the radius setter) when width/height are updated to smaller values.
  • Clamp negative radius values to 0 in the radius setter.
  • Update containsRectangle to accept any object with left/right/top/bottom, and add tests covering these behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/melonjs/src/geometries/roundrect.ts Re-clamps radius on dimension changes, clamps negative radius, and broadens containsRectangle parameter type.
packages/melonjs/tests/roundrect.spec.ts Adds tests for setter-based re-clamping, negative radius clamping, and containsRectangle structural typing (including Rect).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@obiot obiot merged commit ef44d01 into master Mar 28, 2026
10 checks passed
@obiot obiot deleted the fix/roundrect-copilot-feedback branch April 11, 2026 12:48
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.

2 participants