-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.js
More file actions
41 lines (33 loc) · 751 Bytes
/
math.js
File metadata and controls
41 lines (33 loc) · 751 Bytes
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
goog.provide('soko.math');
goog.require('soko.types');
goog.scope(function() {
/**
* @param {!soko.types.GridPoint} a
* @param {!soko.types.GridPoint} b
* @param {number=} opt_scale optional scaling of b
* @return {!soko.types.GridPoint}
*/
soko.math.vectorAdd = function(a, b, opt_scale) {
var scale = opt_scale || 1;
return [a[0] + b[0] * scale, a[1] + b[1] * scale];
};
/**
* @param {!soko.types.GridPoint} a
* @param {!soko.types.GridPoint} b
* @return {number}
*/
soko.math.vectorDistanceL1 = function(a, b) {
return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);
};
/**
* @param {number} x
*/
soko.math.factorial = function(x) {
var result = 1;
while (x > 1) {
result *= x;
--x;
}
return result;
};
});