@wemap/geo 2.7.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,268 +0,0 @@
1
- import chai from 'chai';
2
- import chaiAlmost from 'chai-almost';
3
-
4
- import WGS84 from './WGS84';
5
- import Level from './Level';
6
- import Constants from '../Constants';
7
-
8
- const expect = chai.expect;
9
- chai.use(chaiAlmost());
10
-
11
- describe('WGS84', () => {
12
-
13
- it('creation', () => {
14
-
15
- expect(() => new WGS84()).throw(Error);
16
-
17
- expect(() => new WGS84(45)).throw(Error);
18
- expect(() => new WGS84(45, 5)).not.throw(Error);
19
- expect(() => new WGS84(-93, 5)).throw(Error);
20
- expect(() => new WGS84(45, 202)).throw(Error);
21
-
22
- expect(() => new WGS84(45, 5, true)).throw(Error);
23
- expect(() => new WGS84(45, 5, false)).throw(Error);
24
- expect(() => new WGS84(45, 5, null)).not.throw(Error);
25
- expect(() => new WGS84(45, 5, 0)).not.throw(Error);
26
- expect(() => new WGS84(45, 5, Number.POSITIVE_INFINITY)).throw(Error);
27
-
28
- expect(() => new WGS84(45, 5, null, null)).not.throw(Error);
29
- expect(() => new WGS84(45, 5, null, true)).throw(Error);
30
- expect(() => new WGS84(45, 5, null, new Level(1))).not.throw(Error);
31
- expect(() => new WGS84(45, 5, null, new Level(1, 2))).not.throw(Error);
32
- expect(() => new WGS84(45, 5, 0, new Level(1))).not.throw(Error);
33
-
34
- const level = new Level(2);
35
- const position = new WGS84(45, 5, 0, level);
36
- expect(position.lat).equals(45);
37
- expect(position.lng).equals(5);
38
- expect(position.alt).equals(0);
39
- expect(position.level).equals(level);
40
-
41
- });
42
-
43
- it('update', () => {
44
- const position = new WGS84(0, 0);
45
- position.lat = 45;
46
- position.lng = 5;
47
- position.alt = 0;
48
- position.level = new Level(2);
49
- expect(position.lat).equals(45);
50
- expect(position.lng).equals(5);
51
- expect(position.alt).equals(0);
52
- expect(Level.equalsTo(position.level, new Level(2))).true;
53
- expect(position._ecef).equals(null);
54
- expect(position.ecef).is.not.null;
55
- });
56
-
57
- it('clone', () => {
58
- const level = new Level(0);
59
- const position = new WGS84(45, 5, 0, level);
60
- const clonePosition = position.clone();
61
-
62
- expect(clonePosition.lat).equals(45);
63
- expect(clonePosition.lng).equals(5);
64
- expect(clonePosition.alt).equals(0);
65
- expect(Level.equalsTo(clonePosition.level, level)).true;
66
- expect(clonePosition.level).not.equals(level);
67
- });
68
-
69
- it('equalsTo', () => {
70
- let position;
71
-
72
- position = new WGS84(0, 0);
73
- expect(WGS84.equalsTo(position, new WGS84(0, 0))).true;
74
- expect(WGS84.equalsTo(position, new WGS84(0, 0, 0))).false;
75
- expect(WGS84.equalsTo(position, new WGS84(0, 0, null, new Level(0)))).false;
76
- expect(WGS84.equalsTo(position, new WGS84(0, 0, null, null))).true;
77
-
78
-
79
- position = new WGS84(45, 5, 0, new Level(0));
80
- expect(WGS84.equalsTo(position, new WGS84(45, 5, 0, new Level(0)))).true;
81
- expect(WGS84.equalsTo(position, new WGS84(45, 5, 1, new Level(0)))).false;
82
- expect(WGS84.equalsTo(position, new WGS84(45, 5, 0, new Level(1)))).false;
83
- expect(WGS84.equalsTo(position, {
84
- lat: 45,
85
- lng: 5
86
- })).false;
87
- expect(WGS84.equalsTo({
88
- lat: 45,
89
- lng: 5
90
- }, position)).false;
91
- expect(WGS84.equalsTo(position, null)).false;
92
- expect(WGS84.equalsTo(null, position)).false;
93
- expect(WGS84.equalsTo(null, null)).true;
94
-
95
- expect(position.equalsTo(new WGS84(45, 5, 0, new Level(0)))).true;
96
- expect(position.equalsTo(new WGS84(45, 5, 0, new Level(1)))).false;
97
- });
98
-
99
- it('toString', () => {
100
- expect(new WGS84(45, 5).toString()).equals('[45.0000000, 5.0000000]');
101
- expect(new WGS84(45, 5, 0).toString()).equals('[45.0000000, 5.0000000, 0.00]');
102
- expect(new WGS84(45, 5, 1).toString()).equals('[45.0000000, 5.0000000, 1.00]');
103
- expect(new WGS84(45, 5, null, new Level(0)).toString())
104
- .equals('[45.0000000, 5.0000000, [0]]');
105
- expect(new WGS84(45, 5, null, new Level(1)).toString())
106
- .equals('[45.0000000, 5.0000000, [1]]');
107
- expect(new WGS84(45, 5, 2, new Level(1)).toString())
108
- .equals('[45.0000000, 5.0000000, 2.00, [1]]');
109
- expect(new WGS84(45, 5, 2, new Level(1, 2)).toString())
110
- .equals('[45.0000000, 5.0000000, 2.00, [1;2]]');
111
- });
112
-
113
-
114
- it('move/destination', () => {
115
- let position;
116
-
117
- position = new WGS84(0, 0, 0, new Level(0)).move(100000, 0);
118
- expect(WGS84.equalsTo(position, new WGS84(0.8983152841195214, 0, 0, new Level(0)))).true;
119
-
120
- position = new WGS84(0, 0, 0, new Level(0)).move(100000, Math.PI / 2);
121
- expect(WGS84.equalsTo(position, new WGS84(0, 0.8983152841195212, 0, new Level(0)))).true;
122
-
123
- position = new WGS84(0, 0, 0).move(100000, 0, 10);
124
- expect(WGS84.equalsTo(position, new WGS84(0.8983152841195214, 0, 10))).true;
125
-
126
- expect(() => new WGS84(0, 0).move(100000, 0, 10)).throw(Error);
127
-
128
- const level = new Level(1);
129
- position = new WGS84(0, 0, null, level);
130
- const newPosition = position.destinationPoint(100000, 0);
131
- expect(newPosition).not.equals(position);
132
- expect(newPosition.level).not.equal(position.level);
133
- expect(WGS84.equalsTo(newPosition, new WGS84(0.8983152841195214, 0, null, level))).true;
134
- });
135
-
136
-
137
- it('ecef', () => {
138
- let position;
139
-
140
- position = new WGS84(45, 5, 10);
141
- expect(position.ecef).deep.equals(
142
- [4492868.9655526765, 393075.10119330435, 4510030.995104634]
143
- );
144
- expect(WGS84.equalsTo(WGS84.fromECEF(position.ecef), position)).true;
145
- expect(position.enuToEcefRotation).deep.equals(
146
- [0.6241639651811595, 0.2585371795226045, 0.2821438218554906, 0.6811554412633039]
147
- );
148
- expect(position.ecefToEnuRotation).deep.equals(
149
- [0.6241639651811595, -0.2585371795226045, -0.2821438218554906, -0.6811554412633039]
150
- );
151
-
152
- position = new WGS84(-15, 25, 1200);
153
- expect(position.ecef).deep.equals([5584638.098155466, 2604159.5131940604, -1651093.9107271794]);
154
- expect(WGS84.equalsTo(WGS84.fromECEF(position.ecef), position)).true;
155
- expect(position.enuToEcefRotation).deep.equals(
156
- [0.32708727738303844, 0.42626843901912514, 0.6691074207087071, 0.5134241817667833]
157
- );
158
- expect(position.ecefToEnuRotation).deep.equals(
159
- [0.32708727738303844, -0.42626843901912514, -0.6691074207087071, -0.5134241817667833]
160
- );
161
-
162
- });
163
-
164
-
165
- it('getSegmentProjection', () => {
166
- let p1, p2, projection;
167
-
168
- p1 = new WGS84(0, 0);
169
-
170
- projection = new WGS84(45, 5).getSegmentProjection(p1, p1);
171
- expect(projection).is.null;
172
-
173
- p2 = new WGS84(0, 30);
174
-
175
- projection = new WGS84(45, 5).getSegmentProjection(p1, p2);
176
- expect(WGS84.equalsTo(projection, new WGS84(0, 5))).true;
177
-
178
- projection = new WGS84(-10, 30).getSegmentProjection(p1, p2);
179
- expect(WGS84.equalsTo(projection, new WGS84(0, 30))).true;
180
-
181
- projection = new WGS84(10, 50).getSegmentProjection(p1, p2);
182
- expect(projection).is.null;
183
-
184
- p1 = new WGS84(0, 0);
185
- p2 = new WGS84(30, 10);
186
-
187
- projection = new WGS84(10, -30).getSegmentProjection(p1, p2);
188
- expect(WGS84.equalsTo(projection, new WGS84(1.5735557770204767, 0.473398796436419))).true;
189
-
190
- projection = new WGS84(0, 10).getSegmentProjection(p1, p2);
191
- expect(WGS84.equalsTo(projection, new WGS84(2.7840283663153627, 0.8380346611000419))).true;
192
-
193
- projection = new WGS84(45, 5).getSegmentProjection(p1, p2);
194
- expect(projection).is.null;
195
-
196
- p1 = new WGS84(0, 0, 10);
197
- p2 = new WGS84(0, 30, 15);
198
-
199
- projection = new WGS84(45, 5, 0).getSegmentProjection(p1, p2);
200
- expect(WGS84.equalsTo(projection, new WGS84(0, 5, 12.5))).true;
201
-
202
- });
203
-
204
- it('distance', () => {
205
-
206
- expect(WGS84.distanceBetween(new WGS84(0, 0), new WGS84(0, 5)))
207
- .closeTo(556597.4539663679, Constants.EPS_MM);
208
- expect(WGS84.distanceBetween(new WGS84(0, 0), new WGS84(10, 5)))
209
- .closeTo(1243322.1397654496, Constants.EPS_MM);
210
- expect(WGS84.distanceBetween(new WGS84(10, 10), new WGS84(10.003, 9.9995)))
211
- .closeTo(338.4269853899686, Constants.EPS_MM);
212
-
213
- });
214
-
215
- it('bearing', () => {
216
-
217
- expect(WGS84.bearingTo(new WGS84(0, 0), new WGS84(0, 5)))
218
- .closeTo(1.5707963267948966, 1e-5);
219
- expect(WGS84.bearingTo(new WGS84(0, 0), new WGS84(10, 5)))
220
- .closeTo(0.4590649881870773, 1e-5);
221
- expect(WGS84.bearingTo(new WGS84(10, 10), new WGS84(10.003, 9.9995)))
222
- .closeTo(-0.16268256717197785, 1e-5);
223
-
224
- });
225
-
226
- it('json', () => {
227
-
228
- expect(new WGS84(0, 0).toJson()).to.deep.equal({
229
- lat: 0,
230
- lng: 0
231
- });
232
-
233
- expect(new WGS84(5, -10, 2).toJson()).to.deep.equal({
234
- lat: 5,
235
- lng: -10,
236
- alt: 2
237
- });
238
-
239
- expect(new WGS84(5, -10, null, new Level(1, 2)).toJson()).to.deep.equal({
240
- lat: 5,
241
- lng: -10,
242
- level: '1;2'
243
- });
244
-
245
- expect(new WGS84(5, -10, 3, new Level(1, 2)).toJson()).to.deep.equal({
246
- lat: 5,
247
- lng: -10,
248
- alt: 3,
249
- level: '1;2'
250
- });
251
-
252
- let position;
253
-
254
- position = new WGS84(0, 0);
255
- expect(WGS84.equalsTo(WGS84.fromJson(position.toJson()), position)).true;
256
-
257
- position = new WGS84(5, -10, 2);
258
- expect(WGS84.equalsTo(WGS84.fromJson(position.toJson()), position)).true;
259
-
260
- position = new WGS84(5, -10, null, new Level(1, 2));
261
- expect(WGS84.equalsTo(WGS84.fromJson(position.toJson()), position)).true;
262
-
263
- position = new WGS84(5, -10, 3, new Level(1, 2));
264
- expect(WGS84.equalsTo(WGS84.fromJson(position.toJson()), position)).true;
265
-
266
- });
267
-
268
- });
@@ -1,247 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import chai from 'chai';
3
- import chaiAlmost from 'chai-almost';
4
-
5
- import WGS84UserPosition from './WGS84UserPosition';
6
- import Level from './Level';
7
- import WGS84 from './WGS84';
8
-
9
- const expect = chai.expect;
10
- chai.use(chaiAlmost());
11
-
12
- describe('WGS84UserPosition', () => {
13
-
14
- it('creation', () => {
15
-
16
- expect(() => new WGS84UserPosition()).throw(Error);
17
-
18
- expect(() => new WGS84UserPosition(45)).throw(Error);
19
- expect(() => new WGS84UserPosition(45, 5)).not.throw(Error);
20
- expect(() => new WGS84UserPosition(45, 5, null)).not.throw(Error);
21
- expect(() => new WGS84UserPosition(45, 5, null, null)).not.throw(Error);
22
-
23
- expect(() => new WGS84UserPosition(45, 5, null, null, null)).not.throw(Error);
24
- expect(() => new WGS84UserPosition(45, 5, null, null, 0)).not.throw(Error);
25
- expect(() => new WGS84UserPosition(45, 5, null, null, 10)).not.throw(Error);
26
- expect(() => new WGS84UserPosition(45, 5, null, null, -10)).not.throw(Error);
27
- expect(() => new WGS84UserPosition(45, 5, null, null, Number.POSITIVE_INFINITY)).throw(Error);
28
-
29
- expect(() => new WGS84UserPosition(45, 5, null, null, null, null)).not.throw(Error);
30
- expect(() => new WGS84UserPosition(45, 5, null, null, null, 0)).not.throw(Error);
31
- expect(() => new WGS84UserPosition(45, 5, null, null, null, 10)).not.throw(Error);
32
- expect(() => new WGS84UserPosition(45, 5, null, null, null, -10)).throw(Error);
33
- expect(() => new WGS84UserPosition(45, 5, null, null, null, Number.POSITIVE_INFINITY)).throw(Error);
34
-
35
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
36
- null, null)).not.throw(Error);
37
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
38
- null, 0)).not.throw(Error);
39
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
40
- null, 10)).not.throw(Error);
41
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
42
- null, -10)).not.throw(Error);
43
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
44
- null, Number.POSITIVE_INFINITY)).throw(Error);
45
-
46
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
47
- null, null, null)).not.throw(Error);
48
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
49
- null, null, 0)).throw(Error);
50
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
51
- null, null, 10)).throw(Error);
52
- expect(() => new WGS84UserPosition(45, 5, null, null, null,
53
- null, null, 'foo')).not.throw(Error);
54
-
55
- const position = new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo');
56
- expect(position.lat).equals(45);
57
- expect(position.lng).equals(5);
58
- expect(position.alt).equals(0);
59
- expect(Level.equalsTo(position.level, new Level(2))).true;
60
- expect(position.time).equals(123456);
61
- expect(position.accuracy).equals(10);
62
- expect(position.bearing).equals(Math.PI);
63
- expect(position.provider).equals('foo');
64
-
65
- });
66
-
67
- it('update', () => {
68
- const position = new WGS84UserPosition(0, 0);
69
- position.lat = 45;
70
- position.lng = 5;
71
- position.alt = 0;
72
- position.level = new Level(2);
73
- position.time = 123456;
74
- position.accuracy = 10;
75
- position.bearing = Math.PI;
76
- position.provider = 'foo';
77
- expect(position.lat).equals(45);
78
- expect(position.lng).equals(5);
79
- expect(position.alt).equals(0);
80
- expect(Level.equalsTo(position.level, new Level(2))).true;
81
- expect(position.time).equals(123456);
82
- expect(position.accuracy).equals(10);
83
- expect(position.bearing).equals(Math.PI);
84
- expect(position.provider).equals('foo');
85
-
86
- });
87
-
88
- it('fromWGS84', () => {
89
- const level = new Level(2);
90
- const wgs84 = new WGS84(45, 5, 0, level, 123456);
91
- const position = WGS84UserPosition.fromWGS84(wgs84);
92
- expect(position).instanceOf(WGS84UserPosition);
93
- expect(position.lat).equals(45);
94
- expect(position.lng).equals(5);
95
- expect(position.alt).equals(0);
96
- expect(Level.equalsTo(position.level, level)).true;
97
- expect(position.time).is.null;
98
- expect(position.accuracy).is.null;
99
- expect(position.bearing).is.null;
100
- expect(position.provider).is.null;
101
- });
102
-
103
-
104
- it('clone', () => {
105
- const level = new Level(2);
106
- const position = new WGS84UserPosition(45, 5, 0, level, 123456, 10, Math.PI, 'foo');
107
- const clonePosition = position.clone();
108
-
109
- expect(clonePosition.lat).equals(45);
110
- expect(clonePosition.lng).equals(5);
111
- expect(clonePosition.alt).equals(0);
112
- expect(Level.equalsTo(clonePosition.level, level)).true;
113
- expect(clonePosition.level).not.equals(level);
114
- expect(clonePosition.time).equals(123456);
115
- expect(clonePosition.accuracy).equals(10);
116
- expect(clonePosition.bearing).equals(Math.PI);
117
- expect(clonePosition.provider).equals('foo');
118
- });
119
-
120
-
121
- it('equalsTo', () => {
122
- let position, position2;
123
-
124
- expect(WGS84UserPosition.equalsTo(null, null)).true;
125
-
126
- position = new WGS84UserPosition(0, 0);
127
- expect(WGS84UserPosition.equalsTo(position, new WGS84UserPosition(0, 0))).true;
128
- expect(WGS84UserPosition.equalsTo(position, new WGS84(0, 0))).false;
129
-
130
- position = new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo');
131
- expect(WGS84UserPosition.equalsTo(position,
132
- new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo')
133
- )).true;
134
-
135
- position2 = position.clone();
136
- position2.lat = 0;
137
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
138
-
139
- position2 = position.clone();
140
- position2.lng = 0;
141
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
142
-
143
- position2 = position.clone();
144
- position2.alt = 10;
145
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
146
-
147
- position2 = position.clone();
148
- position2.level = null;
149
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
150
-
151
- position2 = position.clone();
152
- position2.time = 0;
153
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
154
-
155
- position2 = position.clone();
156
- position2.accuracy = 0;
157
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
158
-
159
- position2 = position.clone();
160
- position2.bearing = 0;
161
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
162
-
163
- position2 = position.clone();
164
- position2.provider = 'foobar';
165
- expect(WGS84UserPosition.equalsTo(position, position2)).false;
166
-
167
- expect(position.equalsTo(
168
- new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo')
169
- )).true;
170
- expect(position.equalsTo(
171
- new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 0, Math.PI, 'foo')
172
- )).false;
173
- });
174
-
175
- it('json', () => {
176
- let position;
177
-
178
- position = new WGS84UserPosition(5, -10);
179
- expect(position.toJson()).to.deep.equal({
180
- lat: 5,
181
- lng: -10
182
- });
183
-
184
- position = new WGS84UserPosition(5, -10);
185
- position.alt = 2;
186
- expect(position.toJson()).to.deep.equal({
187
- lat: 5,
188
- lng: -10,
189
- alt: 2
190
- });
191
-
192
- position = new WGS84UserPosition(5, -10);
193
- position.level = new Level(2);
194
- expect(position.toJson()).to.deep.equal({
195
- lat: 5,
196
- lng: -10,
197
- level: '2'
198
- });
199
-
200
- position = new WGS84UserPosition(5, -10);
201
- position.time = 10;
202
- expect(position.toJson()).to.deep.equal({
203
- lat: 5,
204
- lng: -10,
205
- time: 10
206
- });
207
-
208
- position = new WGS84UserPosition(5, -10);
209
- position.accuracy = 10;
210
- expect(position.toJson()).to.deep.equal({
211
- lat: 5,
212
- lng: -10,
213
- accuracy: 10
214
- });
215
-
216
- position = new WGS84UserPosition(5, -10);
217
- position.bearing = Math.PI;
218
- expect(position.toJson()).to.deep.equal({
219
- lat: 5,
220
- lng: -10,
221
- bearing: Math.PI
222
- });
223
-
224
- position = new WGS84UserPosition(5, -10);
225
- position.provider = 'foo';
226
- expect(position.toJson()).to.deep.equal({
227
- lat: 5,
228
- lng: -10,
229
- provider: 'foo'
230
- });
231
-
232
-
233
- position = new WGS84UserPosition(5, -10);
234
- expect(WGS84UserPosition.equalsTo(
235
- WGS84UserPosition.fromJson(position.toJson()),
236
- position)
237
- ).true;
238
-
239
- position = new WGS84UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo');
240
- expect(WGS84UserPosition.equalsTo(
241
- WGS84UserPosition.fromJson(position.toJson()),
242
- position)
243
- ).true;
244
-
245
- });
246
-
247
- });