Skip to content

Fix translation seed for non-root layout - #23

Merged
nixonyh merged 1 commit into
mainfrom
fix/non-root-layout-translation-seed
Jun 4, 2026
Merged

Fix translation seed for non-root layout#23
nixonyh merged 1 commit into
mainfrom
fix/non-root-layout-translation-seed

Conversation

@nixonyh

@nixonyh nixonyh commented Jun 4, 2026

Copy link
Copy Markdown
Member

layout seeded propagate_translation with the node's own world_translation, so laying out a non-root node re-added its own translation each pass, making it drift by its offset on every layout. This was masked for root layout, where both world and translation are zero.

Seed from the parent's world translation instead (zero when the node has no parent). Also prefix the Id is invalid! panics with the originating function name.

`layout` seeded `propagate_translation` with the node's own world_translation, so laying out a non-root node re-added its own translation each pass, making it drift by its offset on every layout. This was masked for root layout, where both world and translation are zero.

Seed from the parent's world translation instead (zero when the node has no parent). Also prefix the `Id is invalid!` panics with the originating function name.
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Fixed layout translation computation for nested elements to correctly derive parent position data
    • Enhanced error diagnostics with clearer messages for invalid node references during layout operations

Walkthrough

The layout function now derives the initial parent_world translation from a node's parent's stored world translation instead of the node itself, with Vec2::ZERO as fallback. Panic messages across the layout pipeline functions (constrain, build, build_up, propagate_translation) are made more specific with function-prefixed text for improved error diagnostics.

Changes

Layout parent-world fix and error diagnostics

Layer / File(s) Summary
Parent-world computation and layout diagnostics
crates/rectree/src/lib.rs
The layout function now seeds parent_world from the parent node's world_translation instead of the current node's own value, defaulting to Vec2::ZERO when there is no parent. The root node lookup gains a function-specific error message (layout: Id is invalid!).
Consistent error diagnostics in layout pipeline
crates/rectree/src/lib.rs
The constrain, build, build_up, and propagate_translation functions each receive function-prefixed expect messages (e.g., constrain: Id is invalid!, build: Id is invalid!) for clearer error diagnostics during node lookups.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A parent's world guides the child so true,
From parent's hand, translation flows through,
When error strikes, the name rings clear—
Which function failed? Now it's plain to see here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix translation seed for non-root layout' clearly and specifically describes the main change: fixing how the translation seed is computed for non-root layout operations.
Description check ✅ Passed The description is well-related to the changeset, explaining both the bug being fixed (translation drift in non-root nodes) and the solution (seeding from parent's world translation instead of node's own).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.

🧹 Nitpick comments (1)
crates/rectree/src/lib.rs (1)

222-230: ⚡ Quick win

Correctly fixes the translation drift bug.

The refactored logic now seeds parent_world from the parent node's stored world_translation (or Vec2::ZERO when no parent exists), preventing non-root nodes from accumulating their own offset on each layout pass. The chain of and_then calls correctly handles the root case (no parent → zero) and non-root case (parent's absolute position).

Optional: clarify "translation" terminology in the comment

Line 223 says "own translation" but in context means "own world_translation" (the absolute position stored in world_translation). To avoid confusion with the translation field (which holds the local relative offset), consider:

-    // world translation. Seeding from `bubbled_id`'s own translation
+    // world translation. Seeding from `bubbled_id`'s own world_translation

This makes it unambiguous that the old behavior read the absolute position, not the local offset.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/rectree/src/lib.rs` around lines 222 - 230, The current code correctly
seeds parent_world from the parent's stored world_translation to prevent drift,
but the inline comment is ambiguous about "translation"; update the comment
around the let parent_world = ... block to explicitly say "world_translation
(absolute position)" rather than "translation" so it’s clear we seed from the
parent's world_translation (or Vec2::ZERO when no parent) and not the node's
local translation field; reference bubbled_id, nodes.get_node, parent_world,
world_translation, and Vec2::ZERO when editing the comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/rectree/src/lib.rs`:
- Around line 222-230: The current code correctly seeds parent_world from the
parent's stored world_translation to prevent drift, but the inline comment is
ambiguous about "translation"; update the comment around the let parent_world =
... block to explicitly say "world_translation (absolute position)" rather than
"translation" so it’s clear we seed from the parent's world_translation (or
Vec2::ZERO when no parent) and not the node's local translation field; reference
bubbled_id, nodes.get_node, parent_world, world_translation, and Vec2::ZERO when
editing the comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c14e2241-083d-4b1f-9835-62d5ce54ce5d

📥 Commits

Reviewing files that changed from the base of the PR and between 08ddf2a and 733d0da.

📒 Files selected for processing (1)
  • crates/rectree/src/lib.rs

@nixonyh
nixonyh merged commit e9ffbcb into main Jun 4, 2026
8 checks passed
@nixonyh
nixonyh deleted the fix/non-root-layout-translation-seed branch June 4, 2026 16:57
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