blob: 82d285fe20c2324d26b2904238cfdc33b42b4118 (
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
|
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <mouse.h>
#include <keyboard.h>
#include "dat.h"
#include "fns.h"
Vec
vecadd(Vec a, Vec b)
{
return (Vec){a.x + b.x, a.y + b.y};
}
Vec
vecsub(Vec a, Vec b)
{
return (Vec){a.x - b.x, a.y - b.y};
}
Vec
vecmul(Vec v, double s)
{
return (Vec){v.x * s, v.y * s};
}
Vec
vecnorm(Vec v)
{
double r;
r = hypot(v.x, v.y);
if(r == 0) return (Vec){0, 0};
v.x /= r;
v.y /= r;
return v;
}
double
vecdist(Vec a, Vec b)
{
return hypot(a.x - b.x, a.y - b.y);
}
double
vecdot(Vec a, Vec b)
{
return a.x * b.x + a.y * b.y;
}
Vec
vecnormal(Vec n)
{
Vec m;
m.x = -n.y;
m.y = n.x;
return vecnorm(m);
}
|