-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
64 lines (52 loc) · 1.36 KB
/
index.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
'use strict';
const VivaldiPosition = require('./lib/vivaldiposition');
const HeightCoordinates = require('./lib/heightcoodinates');
function create(data) {
if (data instanceof Float32Array && data.length == 4) {
return VivaldiPosition.fromFloatArray(data);
} else if (Array.isArray(data) && data.length == 4) {
return VivaldiPosition.fromFloatArray(new Float32Array(data));
} else if (isCoordinate(data)) {
return new VivaldiPosition(data);
} else {
return VivaldiPosition.create(data);
}
}
function update(rtt, p1, p2) {
if (!isPosition(p1) || !positionOrCoordinate(p2)) {
throw new TypeError('Argument 1 and argument 2 must be position or coordinate');
}
return p1.update(rtt, p2);
}
function distance(p1, p2) {
if (!isPosition(p1) || !positionOrCoordinate(p2)) {
throw new TypeError('Argument 1 and argument 2 must be position or coordinate');
}
return p1.estimateRTT(p2);
}
function equals(p1, p2) {
if (positionOrCoordinate(p1)) {
return p1.equals(p2);
}
return false;
}
/** @private */
function isPosition(p) {
return p instanceof VivaldiPosition;
}
/** @private */
function isCoordinate(c) {
return c instanceof HeightCoordinates;
}
/** @private */
function positionOrCoordinate(data) {
return isPosition(data) || isCoordinate(data);
}
module.exports = {
create,
update,
distance,
equals,
VivaldiPosition,
HeightCoordinates
}