Skip to content

Fix Rect.setSize() not updating bounds (pointer event regression)#1373

Merged
obiot merged 2 commits intomasterfrom
fix/rect-setsize-bounds-regression
Apr 11, 2026
Merged

Fix Rect.setSize() not updating bounds (pointer event regression)#1373
obiot merged 2 commits intomasterfrom
fix/rect-setsize-bounds-regression

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented Apr 11, 2026

Summary

  • Rect.setSize() now calls updateBounds() after updating vertices
  • Fixes a regression from July 2024 (4d185c902) where replacing Rect.setShape() with pos.set() + setSize() during the TypeScript conversion left bounds stale
  • This broke pointer event broadphase lookups: the QuadTree query rect always reported bounds at (0,0) instead of the actual click position, causing objects at certain screen positions to not respond to clicks
  • Related to Inconsistent position vector type between me.Renderable and base shape objects #817 (inconsistent pos vector type between Renderable and base shapes)

Root Cause

The old Rect.setShape(x, y, w, h) updated position, vertices, and bounds in one call. The replacement split it into pos.set(x, y) + setSize(w, h), but setSize() never called updateBounds(), and Polygon.pos is a plain Vector2d with no change observer (unlike Renderable.pos which is an ObservableVector3d).

Test plan

  • Added bounds validation tests for Rect.setSize(), pos.set() + setSize(), and Rect.copy()
  • Added equivalent bounds tests for RoundRect
  • All 2381 tests pass
  • Manually verified: all moles respond to clicks in the whack-a-mole example

🤖 Generated with Claude Code

Rect.setSize() did not call updateBounds(), leaving bounds stale after
position or size changes. This broke pointer event broadphase lookups:
the QuadTree query rect always reported bounds at (0,0) instead of the
actual click position, causing moles at certain positions in the
whack-a-mole example to not respond to clicks.

Root cause: commit 4d185c9 (July 2024) replaced Rect.setShape(x,y,w,h)
with pos.set() + setSize() during the TypeScript conversion, but setSize()
never called updateBounds(). The old setShape() updated everything in one
call. See #817 for the underlying pos type mismatch.

Fix: add updateBounds() call in Rect.setSize().

Tests: add bounds validation tests for Rect.setSize(), pos.set()+setSize(),
Rect.copy(), and RoundRect equivalents.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obiot obiot added the Bug label Apr 11, 2026
Copilot AI review requested due to automatic review settings April 11, 2026 07:50
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

Fixes a pointer-event broadphase regression by ensuring Rect.setSize() refreshes the rectangle’s bounds after vertex updates, and adds regression tests to validate bounds updates across Rect and RoundRect.

Changes:

  • Call updateBounds() from Rect.setSize() after updating vertices.
  • Add unit tests covering bounds updates for Rect/RoundRect after setSize(), pos.set() + setSize(), and copy().
  • Document the fix in the melonJS changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/melonjs/src/geometries/rectangle.ts Updates Rect.setSize() to refresh bounds after size changes.
packages/melonjs/tests/rectangle.spec.ts Adds regression tests asserting bounds update correctly after setSize() / copy().
packages/melonjs/tests/roundrect.spec.ts Adds equivalent bounds regression tests for RoundRect.
packages/melonjs/CHANGELOG.md Adds a “Fixed” entry describing the regression and resolution.

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

@@ -38,6 +38,7 @@ export class Rect extends Polygon {
this.points[1].set(width, 0); // 1, 0
this.points[2].set(width, height); // 1, 1
this.points[3].set(0, height); // 0, 1
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

Rect.setSize() mutates points but does not call recalc(). That leaves edges, normals, and indices potentially stale for SAT/collision queries on rectangles that are resized via setSize() (unlike the width/height setters which do recalc() + updateBounds()). Consider calling this.recalc() before this.updateBounds() here to keep the polygon's derived data consistent after resizing.

Suggested change
this.points[3].set(0, height); // 0, 1
this.points[3].set(0, height); // 0, 1
this.recalc();

Copilot uses AI. Check for mistakes.
setSize() now calls recalc() before updateBounds(), matching the
behavior of the width/height setters. Without this, edges, normals,
and indices were stale after setSize(), which could cause incorrect
SAT/collision results on resized rectangles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obiot obiot merged commit 219e7e7 into master Apr 11, 2026
6 checks passed
@obiot obiot deleted the fix/rect-setsize-bounds-regression branch April 11, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants