/
Vec2.ts
78 lines (43 loc) · 847 Bytes
/
Vec2.ts
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
export class Vec2 {
public x : f32 = 0;
public y : f32 = 0;
public set( x : f32, y : f32 ) : Vec2 {
this.x = x;
this.y = y;
return this;
};
public add( v : Vec2 ) : Vec2 {
this.x += v.x;
this.y += v.y;
return this;
};
public sub( v : Vec2 ) : Vec2 {
this.x -= v.x;
this.y -= v.y;
return this;
};
public mul( v : Vec2 ) : Vec2 {
this.x *= v.x;
this.y *= v.y;
return this;
};
public div( v : Vec2 ) : Vec2 {
this.x /= v.x;
this.y /= v.y;
return this;
};
public dot( v : Vec2 ) : f32 {
return this.x * v.x + this.y * v.y;
};
public scale( scalar : f32 ) : Vec2 {
this.x *= scalar;
this.y *= scalar;
return this;
};
public mag() : f32 {
return Mathf.hypot( this.x, this.y );
};
public distanceSq() : f32 {
return this.x * this.x + this.y * this.y;
};
};