-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.js
102 lines (67 loc) · 1.82 KB
/
vector.js
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
94
95
96
97
98
99
100
101
102
// Generated by CoffeeScript 1.10.0
(function() {
var Vector, deodorant, vec;
deodorant = new Deodorant('debug');
deodorant.addAlias('Vector', '{x: Number, y: Number}');
Vector = (function() {
Vector.prototype.constructor_ = ['Number', 'Number', 'Void'];
function Vector(x, y) {
this.x = x;
this.y = y;
}
Vector.prototype.add_ = ['Vector', 'Void'];
Vector.prototype.add = function(vec) {
this.x += vec.x;
this.y += vec.y;
return this;
};
Vector.prototype.sub_ = ['Vector', 'Void'];
Vector.prototype.sub = function(vec) {
this.x -= vec.x;
this.y -= vec.y;
return this;
};
Vector.prototype.mul_ = ['Vector', 'Void'];
Vector.prototype.mul = function(vec) {
this.x *= vec.x;
this.y *= vec.y;
return this;
};
Vector.prototype.div_ = ['Vector', 'Void'];
Vector.prototype.div = function(vec) {
this.x /= vec.x;
this.y /= vec.y;
return this;
};
Vector.prototype.magnitude_ = ['Number'];
Vector.prototype.magnitude = function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
};
Vector.prototype.normalize_ = ['Void'];
Vector.prototype.normalize = function() {
return this.div({
x: this.magnitude(),
y: this.magnitude()
});
};
Vector.prototype.print_ = ['Void'];
Vector.prototype.print = function() {
return console.log(this.x, this.y);
};
return Vector;
})();
Vector = deodorant.checkClass(Vector);
vec = new Vector(5, 2);
vec.add(new Vector(3, 3));
vec.print();
vec.sub(new Vector(2, 2));
vec.print();
vec.mul(new Vector(4, 4));
vec.print();
vec.div(new Vector(2, 2));
vec.print();
console.log(vec.magnitude());
vec.normalize();
vec.print();
debugger;
}).call(this);