Extract force-directed layout into ktsu.ForceDirectedLayout#176
Merged
Conversation
Move the force-directed physics simulation (repulsion, spring, gravity, directional bias, integration) out of NodeEditorEngine into a new standalone, renderer-agnostic library. The new library is generic over caller-defined body and edge types via BodyAccessor<TBody>/EdgeAccessor<TEdge> adapters, so it has no coupling to nodes, pins, ImNodes, or ImGui. NodeEditorEngine keeps its public API: PhysicsSettings, GravityCenter, WorldOrigin, UpdatePhysics, UpdatePhysicsSettings, LastPhysicsStepInfo, TotalSystemEnergy, IsStable, SetDraggedNodes, InitializeWorldOriginToCentroid. Internally it delegates to ForceDirectedLayout<Node, Link>, mapping pin ids to body ids in the edge accessor. PhysicsSettings moves to the ktsu.ForceDirectedLayout namespace; consumers that referenced it directly need to add `using ktsu.ForceDirectedLayout;`.
|
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.




Summary
Promotes the force-directed graph layout out of
ImGuiNodeEditorinto a new standalone, renderer-agnostic libraryktsu.ForceDirectedLayout. The new library has no dependency on ImGui, ImNodes, nodes, pins, or any rendering — it operates on arbitrary caller-defined body and edge types via accessor adapters.What moved
From
ImGuiNodeEditor/NodeEditorEngine.csandDomainModels.cs:PhysicsSettingsrecord — now inktsu.ForceDirectedLayoutnamespaceNew public API
The simulation snapshots body state into an internal mutable working buffer to avoid per-substep record allocations, runs N substeps, then commits results back through
WithPhysicsState. This is actually a small perf improvement over the previousnode with { ... }-per-substep code path.NodeEditorEngine
Public API is preserved.
NodeEditorEnginenow holds aForceDirectedLayout<Node, Link>and proxiesPhysicsSettings,GravityCenter,WorldOrigin,LastPhysicsStepInfo,TotalSystemEnergy,IsStable,UpdatePhysics,UpdatePhysicsSettings,SetDraggedNodes, andInitializeWorldOriginToCentroidto it. TheEdgeAccessorresolvesLink.OutputPinId/InputPinIdto node ids via a pin→node-id map rebuilt at the top of eachUpdatePhysicscall.One tiny API tightening:
GravityCenterwas previously{ get; set; }and is now read-only (no caller in the tree set it — it was always overwritten by the next physics step).Consumer impact
Consumers that referenced
PhysicsSettingsdirectly need to addusing ktsu.ForceDirectedLayout;. Updated in this PR:examples/ImGuiAppDemo/Demos/CleanImNodesDemo.csTest plan
dotnet buildsucceeds on the full solution in the project's CI environmentexamples/ImGuiAppDemo→ Clean ImNodes tab → enable physics and confirm nodes settle into a stable left-to-right layoutToggleNodePinned) and confirm it stays put while others moveIsStableflips to true once the system settlesGenerated by Claude Code