## Circular references problem

As of http://dooglus.rincevent.net/synfig/logs/2008/%23synfig-2008-03-06.log the circular references problem appeared.

In my (Zelgadis) opinion we have 3 problems:

1. Detecting loops
2. Creating loops (handling detected loop while creating)
3. Dealing with loops (handling modifications of linked-to-bline vertices engaged inloops)

### Detecting loops

00:22 < dooglus> it turns out that every node in the network has a 'time last modified' field, so checking that will allow us to detect loops

### Creating loops

While creating loop we have a Circular references problem.

We want to link C2 to Bline A.

But if we do it, C2 will change it's position (it must lay on the Bline A). As result, the shape of Bline C will change and B2 (which linked to Bline C) will move. It will change the shape of Bline B -> A2 will move -> shape of Bline A changed -> C2 not on Bline A. Сontradiction.

We could move C2 to place it on Bline A again but then it'll end up not laying on Bline A again.

So, if we detected loop, we must do linking in special way.

1. As the user invokes "Link to Bline" command for C2, we detected loop C2->B2->A2->C2.
2. We must solve system of equations to determine position of C2 when: a) it belongs to Bline A; b) the shape of Bline A determined by position of C2;
1. How such system of equations will look like? See Linking to Blines - Equations.
3. We placing C2 to determined position. So it definitely on Bline A. Blines A, B, C are updated according to new position of C2.
4. We linking C2 to Bline A. Position of C2 not changed while linking, so all blines not recalculated and Bline A keeps its shape and recursion not taking place.

Another possible solution (ah-hoc):

1. As the user invokes "Link to Bline" command for C2, we detected loop C2->B2->A2->C2.
2. We adding a new vertex A3 on Bline A where C2 must be connected. Then we moving (moving, not linking) C2 to the position Bline A where user had clicked. The blines C,B,A will change so C2 probably won't be on A.
3. Just link C2 -> A3

### Dealing with loops

To be written... if needed to.