mdegans / weave

Branching story writing tool with generative AI
Other
1 stars 0 forks source link

force-directed layout may push node position off screen #9

Open mdegans opened 2 months ago

mdegans commented 2 months ago

Some nodes may become un-clickable during force-directed layout. This is likely due to inconsistencies about what the node position is (center, top-left, etc).

Likely there's a logic error I just realized where the position is clamped to the window but this isn't enough. The entire bounding rectangle should be clamped. Egui will still draw the nodes on-screen, but they cannot be interacted with.

When a node does not intersect the window bounds, the velocity is supposed to reverse, making it bounce off the sides. This usually works but clearly there are some issues because if there is a very high velocity the nodes can become "lost".

For example if nodes overlap exactly, which is easy to do since the initial positions overlap, velocity can quickly go to the max. It's clamped so it won't go to infinity but it's still high.

Within a single time step, if a node leaves the bounds with a very high velocity, it may be reversed, but because we apply a BOUNDARY_DAMPING, it may not have enough velocity to return within the next time step0. Because it doesn't intersect, the reversal and boundary damping is applied again, only this time the node is outside the bounds of the window. So very quickly the velocity goes to 0.0 and it never starts moving again because we have a cutoff and it may be too far from any attractors.

Perhaps the best way to fix this is to just ensure that the nodes cannot leave the window bounds. It also needs a lot more testing since this can break a story layout and we don't yet have an option to reset or randomize positions. This should probably be added since it's what Gephi does and it works well.