aboutsummaryrefslogtreecommitdiff
path: root/src/un_splines.c
blob: c6d2844417b58e3f4b8fb42126f2eb0155acc556 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
void un_m_bezierr(real *v, real a, real q0, real q1, real b, real t) {
    real i0, i1, i2, p0, p1;

    i0 = un_m_lerpr(a,  q0, t);
    i1 = un_m_lerpr(q0, q1, t);
    i2 = un_m_lerpr(q1, b,  t);

    p0 = un_m_lerpr(i0, i1, t);
    p1 = un_m_lerpr(i1, i2, t);

    *v = un_m_lerpr(p0, p1, t);
}

void un_m_bezierf(f32 *v, f32 a, f32 q0, f32 q1, f32 b, f32 t) {
    f32 i0, i1, i2, p0, p1;

    i0 = un_m_lerpf(a,  q0, t);
    i1 = un_m_lerpf(q0, q1, t);
    i2 = un_m_lerpf(q1, b,  t);

    p0 = un_m_lerpf(i0, i1, t);
    p1 = un_m_lerpf(i1, i2, t);

    *v = un_m_lerpf(p0, p1, t);
}

void un_m_bezierd(f64 *v, f64 a, f64 q0, f64 q1, f64 b, f64 t) {
    f64 i0, i1, i2, p0, p1;

    i0 = un_m_lerpd(a,  q0, t);
    i1 = un_m_lerpd(q0, q1, t);
    i2 = un_m_lerpd(q1, b,  t);

    p0 = un_m_lerpd(i0, i1, t);
    p1 = un_m_lerpd(i1, i2, t);

    *v = un_m_lerpd(p0, p1, t);
}

void un_m_bezier2r(real *v, real *a, real *q0, real *q1, real *b, real t) {
    un_m_bezierr(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierr(v + 1, a[1], q0[1], q1[1], b[1], t);
}

void un_m_bezier3r(real *v, real *a, real *q0, real *q1, real *b, real t) {
    un_m_bezierr(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierr(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierr(v + 2, a[2], q0[2], q1[2], b[2], t);
}

void un_m_bezier4r(real *v, real *a, real *q0, real *q1, real *b, real t) {
    un_m_bezierr(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierr(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierr(v + 2, a[2], q0[2], q1[2], b[2], t);
    un_m_bezierr(v + 3, a[3], q0[3], q1[3], b[3], t);
}

void un_m_bezier2f(f32 *v, f32 *a, f32 *q0, f32 *q1, f32 *b, f32 t) {
    un_m_bezierf(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierf(v + 1, a[1], q0[1], q1[1], b[1], t);
}

void un_m_bezier3f(f32 *v, f32 *a, f32 *q0, f32 *q1, f32 *b, f32 t) {
    un_m_bezierf(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierf(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierf(v + 2, a[2], q0[2], q1[2], b[2], t);
}

void un_m_bezier4f(f32 *v, f32 *a, f32 *q0, f32 *q1, f32 *b, f32 t) {
    un_m_bezierf(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierf(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierf(v + 2, a[2], q0[2], q1[2], b[2], t);
    un_m_bezierf(v + 3, a[3], q0[3], q1[3], b[3], t);
}


void un_m_bezier2d(f64 *v, f64 *a, f64 *q0, f64 *q1, f64 *b, f64 t) {
    un_m_bezierd(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierd(v + 1, a[1], q0[1], q1[1], b[1], t);
}

void un_m_bezier3d(f64 *v, f64 *a, f64 *q0, f64 *q1, f64 *b, f64 t) {
    un_m_bezierd(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierd(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierd(v + 2, a[2], q0[2], q1[2], b[2], t);
}

void un_m_bezier4d(f64 *v, f64 *a, f64 *q0, f64 *q1, f64 *b, f64 t) {
    un_m_bezierd(v + 0, a[0], q0[0], q1[0], b[0], t);
    un_m_bezierd(v + 1, a[1], q0[1], q1[1], b[1], t);
    un_m_bezierd(v + 2, a[2], q0[2], q1[2], b[2], t);
    un_m_bezierd(v + 3, a[3], q0[3], q1[3], b[3], t);
}