-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
66 lines (56 loc) · 1.53 KB
/
util.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
/**
* Return a random double in the range [-scale, scale)
*/
let rand_value = function(scale) {
// Number between -1 and 1
let unit_rand = 2.0 * Math.random() - 1;
return scale * unit_rand;
}
/**
* Because JavaScript doesn't implement modulo properly for negative
* integers :P
*/
let mod = function(n, m) {
return ((n % m) + m) % m;
}
/**
* Using the definition
*
* a % b == a - floor(a / b) * b
*/
let fmod = function(val, n) {
return val - Math.floor(val / n) * n;
}
/**
* this is a common idiom for me
*/
let log = function(x) {
console.log(x.str);
}
let rand_array = function(n) {
return Array(n).fill(0).map(x => Math.random());
}
/**
* Pair two Clines
*/
function pair_circles(c1, c2, extra_xform) {
// First, map c1 to a unit circle at the origin
let P = Complex.from_vec(c1.center);
let to_center = MobiusTransform.pure_translation(P.neg);
let normalize_scale = MobiusTransform.pure_scale(1.0 / c1.radius);
//map inside to outside using 1/z
let inv = MobiusTransform.x180();
// If desired, map the unit circle -> unit circle in between
let extra = extra_xform || MobiusTransform.identity();
// Scale up to and move to second circle
let scale = MobiusTransform.pure_scale(c2.radius);
let Q = Complex.from_vec(c2.center);
let recenter = MobiusTransform.pure_translation(Q);
// Combine the 5 steps into one matrix:
return to_center
.then(normalize_scale)
.then(inv)
.then(extra)
.then(scale)
.then(recenter);
}