looking inside the first link you procided, there is line 240:
var repulsiveForce = this.k * this.k / d;
which represent the repulsive potential (that's physics). The larger that number, the less likely is the geometric state. d is the distance between two nodes, and this.k is the spring stiffness. This potential becomes infinite for distance d = 0.
You want to translate this potential by a certain length (the size of your boxes), so replace d by d - length. That means, the repulsive force becomes infinite at the distance length. There still remains the problem, that the repulsive forces then decrease for distances, smaller then length, which must be covered by some conditional:
if (d + 0.0001 < length) repulsiveForce = bigbigNumber;
I added 0.0001 so that the repulsive force never becomes infinite, but only big, because computers don't handle infiniteness very well.