-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
60 lines (41 loc) · 1.15 KB
/
helpers.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
/* Birdcage Builder
*
* Helper Functions
*
* Doug Brantner
* 3 May 2023
* NYU Langone Health
* cai2r.net
*
*/
/*** Unit Conversions ***/
/* The constants can be used directly, or called in functions */
// Multiplicative Constants (multiply to acheive desired result)
var CM2M = 1e-2; // centimeters to meters
var MHZ2HZ = 1e6; // megahertz to hertz
function cm2meters(m) {
// Convert centimeters to meters
return CM2M * m;
}
function mhz2hz(mhz) {
// Convert MHz to Hertz
return MHZ2HZ * mhz;
}
/*** Math Functions ***/
function mod(n, d) {
/* Modulo operator
*
* Compute expected n % d (% in the modulo sense here, not the javascript sense)
*
* Implementation Details:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Remainder
*
* The % operator is NOT the same in Javascript as in other languages;
* the above reference gives this implementation for the expected behavior.
*/
// TODO UNIT TESTS - compare with actual Java output to confirm expected behavior!!!
//debug('mod: ' + n + ', ' + d);
//debug('typeof n: ' + typeof(n));
//debug('typeof d: ' + typeof(d));
return ((n % d) + d) % d;
}