馃悕馃悕馃悕
1
2function vec2_of(x, y) {
3 return { x, y };
4}
5
6function vec2_from_mouse(event, element) {
7 const rect = element.getBoundingClientRect();
8 return {
9 x: event.clientX - rect.left,
10 y: event.clientY - rect.top
11 };
12}
13
14function vec2_sub(a, b) {
15 return {
16 x: a.x - b.x,
17 y: a.y - b.y
18 };
19}
20
21function vec2_scalar_mult(v, s) {
22 return {
23 x: v.x * s,
24 y: v.y * s
25 };
26}
27
28window.$vector = {
29 v2: {
30 of: vec2_of,
31 fromMouse: vec2_from_mouse,
32 sub: vec2_sub,
33 scale: vec2_scalar_mult
34 }
35};
36