Skip to content

fix(clipping): post-merge Copilot review on #1435#1437

Merged
obiot merged 1 commit intomasterfrom
fix/clipping-followup-1435
May 8, 2026
Merged

fix(clipping): post-merge Copilot review on #1435#1437
obiot merged 1 commit intomasterfrom
fix/clipping-followup-1435

Conversation

@obiot
Copy link
Copy Markdown
Member

@obiot obiot commented May 8, 2026

Summary

Three small follow-ups to PR #1435 (which landed by squash-merge before these review comments were posted):

  • Bounds.addFrame now short-circuits the 4-corner walk when the matrix is identity. The renderer's clipRect/enableScissor unconditionally pass currentTransform and don't filter identity themselves, so they were running 4× Matrix3d.apply per scissor change in the common identity case. Existing matrix-passing callers (Renderable.updateBounds, the spine plugin) already gate on isIdentity() so they're unaffected.
  • Clipping example wrapper was positioned at its visual center (pos = (RIGHT_CENTER_X, RIGHT_CENTER_Y)) with a child clip offset by (-W/2, -H/2). Container's anchorPoint is always (0, 0), so its bounds (and viewport-cull rect) didn't match what was actually drawn — could disappear near canvas edges or on resize. Wrapper now sits at top-left and the per-frame pulse scales around the visual center via translate(cx, cy) → scale → translate(-cx, -cy) on currentTransform. Bounds and visual now agree.
  • bounds.spec.ts adds a sentinel test that spies on m.apply and asserts the identity short-circuit avoids the corner walk — guards against a future refactor that drops the isIdentity() check.

Test plan

  • pnpm vitest run — 2933 tests pass.
  • pnpm lint — 0 errors.
  • Visual: Clipping example renders identically to before; right-side pulse still breathes around its visual center.

🤖 Generated with Claude Code

Three small follow-ups that landed in Copilot review after the squash
merge of #1435:

- Bounds.addFrame: short-circuit the 4-corner walk when the matrix is
  identity. The renderer's clipRect/enableScissor unconditionally pass
  `currentTransform` and don't filter identity themselves, so they
  were running 4× `Matrix3d.apply` per scissor change for the common
  identity case. Existing matrix-passing callers (Renderable,
  Spine plugin) already gate on `isIdentity()` so they're unaffected.
- examples/Clipping: the right-side wrapper was positioned at its
  visual center (`pos = (RIGHT_CENTER_X, RIGHT_CENTER_Y)`) with a
  child clip offset by `(-W/2, -H/2)`. Container's anchorPoint is
  always `(0, 0)`, so its bounds (and viewport-cull rect) didn't
  match what was actually drawn — could disappear near edges or on
  resize. Wrapper now sits at top-left with `pos = (RIGHT_X, RIGHT_Y)`
  and the inner clip at `(0, 0)`; the per-frame pulse scales around
  the visual center via `translate(cx, cy) → scale → translate(-cx,
  -cy)` on `currentTransform`. Bounds and visual now agree.
- bounds.spec.ts: add a sentinel test that spies on `m.apply` and
  asserts the identity short-circuit avoids the corner walk. Guards
  against a future refactor that drops the `isIdentity()` check.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 8, 2026 00:47
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

Follow-up adjustments to the clipping work from #1435, focused on reducing overhead in the common “identity transform” scissor path, aligning the clipping gallery example’s bounds with what’s visually drawn, and adding a regression/sentinel test to prevent the optimization from being accidentally removed.

Changes:

  • Add an identity fast path to Bounds.addFrame() to avoid the 4-corner m.apply walk for no-op transforms.
  • Update WebGL scissor code comments to reflect that Bounds.addFrame() now provides the identity short-circuit used by clipRect / enableScissor.
  • Fix the clipping example’s right-side wrapper positioning so container bounds/culling match the rendered output, while keeping the pulse centered via translate→scale→translate-back on currentTransform.
  • Add a sentinel unit test that verifies the identity fast path avoids calling Matrix3d.apply.

Reviewed changes

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

File Description
packages/melonjs/src/physics/bounds.ts Adds an identity/no-transform early-return path in addFrame() to avoid unnecessary per-corner transform work.
packages/melonjs/src/video/webgl/webgl_renderer.js Updates documentation/comments to reflect that scissor AABB derivation benefits from Bounds.addFrame’s identity short-circuit.
packages/melonjs/tests/bounds.spec.ts Adds a regression/sentinel test that asserts addFrame doesn’t call apply for an identity matrix.
packages/examples/src/examples/clipping/ExampleClipping.tsx Adjusts example layout/transform composition so bounds and culling align with what is drawn while preserving the pulsing-center behavior.

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

@obiot obiot merged commit 3a4ec96 into master May 8, 2026
10 checks passed
@obiot obiot deleted the fix/clipping-followup-1435 branch May 8, 2026 02:08
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