]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/timmy/util.c
add games/mus midi converter (by qu7uux)
[plan9front.git] / sys / src / games / timmy / util.c
1 #include <u.h>
2 #include <libc.h>
3 #include <thread.h>
4 #include <draw.h>
5 #include <mouse.h>
6 #include <keyboard.h>
7 #include "dat.h"
8 #include "fns.h"
9
10 Vec
11 vecadd(Vec a, Vec b)
12 {
13         return (Vec){a.x + b.x, a.y + b.y};
14 }
15
16 Vec
17 vecsub(Vec a, Vec b)
18 {
19         return (Vec){a.x - b.x, a.y - b.y};
20 }
21
22 Vec
23 vecmul(Vec v, double s)
24 {
25         return (Vec){v.x * s, v.y * s};
26 }
27
28 Vec
29 vecnorm(Vec v)
30 {
31         double r;
32         
33         r = hypot(v.x, v.y);
34         if(r == 0) return (Vec){0, 0};
35         v.x /= r;
36         v.y /= r;
37         return v;
38 }
39
40 double
41 vecdist(Vec a, Vec b)
42 {
43         return hypot(a.x - b.x, a.y - b.y);
44 }
45
46 double
47 vecdot(Vec a, Vec b)
48 {
49         return a.x * b.x + a.y * b.y;
50 }
51
52 Vec
53 vecnormal(Vec n)
54 {
55         Vec m;
56         
57         m.x = -n.y;
58         m.y = n.x;
59         return vecnorm(m);
60 }