clampNodeVector method
Ensure no part of each drawn node is drawn outside the layout area.
Restricting the node position by Vector2.random()
on each side also
ensures that the position of any two nodes is never clamped to the
same point. Otherwise, groups of nodes may get 'stuck' at a corner
of the layout area, even after the area is expanded.
Implementation
@protected
void clampNodeVector(Vector2 nodePosition) {
nodePosition.clamp(
Vector2.all(nodeRadius) + Vector2.random(),
layoutDimensions - Vector2.all(nodeRadius) - Vector2.random(),
);
}