Keep ForceLayout edges on the same body ids when the body set changes [patch] - #520
Merged
Merged
Conversation
SetNodes kept each edge's stored body indices and only dropped those that fell out of range, so removing or reordering bodies silently dropped valid edges or moved them onto bodies they never joined. Keep the endpoint ids each edge was submitted with and re-resolve them through the new id map, dropping an edge only when one of its ids is gone. Fixes #475 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AK9FUHZoZnfAL1aQuEtAR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018AK9FUHZoZnfAL1aQuEtAR
|
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #475
What was wrong
ForceLayout.SetNodesrebuilt the body array andidToIndexbut kept each edge's stored body indices. It dropped an edge only when an index fell out of range. Once the new body set differed in order or membership, an index pointed at a different body:[1,2,3]and edge2->3,SetNodes([2,3])put index 2 out of range.[1,2,3]and edge1->2,SetNodes([2,3])turned it into an edge between 2 and 3.This applies to the id-keyed
ForceLayoutAPI and to the C ABI (Layout_SetNodes/Layout_SetEdges), which goes through it.Change
SetEdgeskeeps the(SourceBodyId, TargetBodyId)each edge was submitted with, in an array parallel to the core's edge buffer.SetNodeslooks those ids up again in the newidToIndex. An edge is dropped (both ends set to -1) only when one of its ids is missing. As a side effect, an edge whose endpoint leaves and later comes back is linked again.internal GetEdgeIndices(int)lets the tests read what an edge resolves to. The test project already hasInternalsVisibleTo.LayoutCorerebuilds its per-body edge lists every step fromSourceIndex/TargetIndex, so updating those indices in place is enough.Tests
New tests in
ForceLayoutTests:SetNodes_RemovingAnUnconnectedBody_KeepsTheEdgeBetweenTheRestSetNodes_RemovingAnEndpoint_DropsItsEdgeRatherThanRetargetingItSetNodes_Reordering_KeepsEachEdgeOnTheSamePairOfIdsSetNodes_RestoringARemovedEndpoint_ReconnectsItsEdgeWith the old range check put back in
SetNodes, all four fail. With the fix in place, all 82 tests inForceDirectedLayout.Testspass on net10.0.🤖 Generated with Claude Code
https://claude.ai/code/session_018AK9FUHZoZnfAL1aQuEtAR
Generated by Claude Code