-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.c
More file actions
35 lines (29 loc) · 832 Bytes
/
link.c
File metadata and controls
35 lines (29 loc) · 832 Bytes
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
#include <stdlib.h>
#include "link.h"
#include "layout.h"
#include "math.h"
#define INTERPOLATION 10
void tesselate_links(Network *n)
{
for(size_t i=0; i<((n->l*2) - 1); i+=2) {
tesselate_link(n, n->links[i], n->links[i+1]);
}
}
void tesselate_link(Network *n, uint32_t x, uint32_t y)
{
Point2 a = n->nodes[x],
b = n->nodes[y];
/* calculate the distance and slope of the line and create one tesselation
* point for each unit of distance along the path */
uint32_t d = ceil(distance(a,b)/INTERPOLATION),
t_start = n->t,
t_end = n->t + d;
Point2 dp = unit(direction(a,b));
n->tlinks = realloc(n->tlinks, t_end*sizeof(Point2));
for(uint32_t i=0; i<d; i++) {
a.x += dp.x*INTERPOLATION;
a.y += dp.y*INTERPOLATION;
n->tlinks[t_start+i] = a;
}
n->t = t_end;
}