File: relax.c

package info (click to toggle)
python-pyqtgraph 0.13.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,520 kB
  • sloc: python: 52,773; makefile: 115; ansic: 40; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,226 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <math.h>
#include <stdio.h>

void relax(
    double* pos, 
    long* links, 
    double* mrel1, 
    double* mrel2, 
    double* lengths, 
    char* push, 
    char* pull, 
    int nlinks, 
    int iters) 
    {
    int i, l, p1, p2;
    double x1, x2, y1, y2, dx, dy, dist, change;
//     printf("%d, %d\n", iters, nlinks);
    for( i=0; i<iters; i++ ) {
        for( l=0; l<nlinks; l++ ) {
            p1 = 2*links[l*2];
            p2 = 2*links[l*2 + 1];
            x1 = pos[p1];
            y1 = pos[p1 + 1];
            x2 = pos[p2];
            y2 = pos[p2 + 1];
            
            dx = x2 - x1;
            dy = y2 - y1;
            
//             dist = pow(dx*dx + dy*dy, 0.5);
            dist = sqrt(dx*dx + dy*dy);
            
            if( push[l]==0 && dist < lengths[l] )
                dist = lengths[l];
            if( pull[l]==0 && dist > lengths[l] )
                dist = lengths[l];
            
            change = (lengths[l]-dist) / dist;
            dx *= change;
            dy *= change;
        
            pos[p1]   -= mrel2[l] * dx;
            pos[p1+1] -= mrel2[l] * dy;
            pos[p2]   += mrel1[l] * dx;
            pos[p2+1] += mrel1[l] * dy;
        }
    }
}