forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEllipsoidSpec.js
435 lines (379 loc) · 20.2 KB
/
EllipsoidSpec.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/*global defineSuite*/
defineSuite([
'Core/Ellipsoid',
'Core/Cartesian3',
'Core/Cartographic',
'Core/Math'
], function(
Ellipsoid,
Cartesian3,
Cartographic,
CesiumMath) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
var radii = new Cartesian3(1.0, 2.0, 3.0);
var radiiSquared = Cartesian3.multiplyComponents(radii, radii);
var radiiToTheFourth = Cartesian3.multiplyComponents(radiiSquared, radiiSquared);
var oneOverRadii = new Cartesian3(1 / radii.x, 1 / radii.y, 1 / radii.z);
var oneOverRadiiSquared = new Cartesian3(1 / radiiSquared.x, 1 / radiiSquared.y, 1 / radiiSquared.z);
var minimumRadius = 1.0;
var maximumRadius = 3.0;
//All values computes using STK Components
var spaceCartesian = new Cartesian3(4582719.8827300891, -4582719.8827300882, 1725510.4250797231);
var spaceCartesianGeodeticSurfaceNormal = new Cartesian3(0.6829975339864266, -0.68299753398642649, 0.25889908678270795);
var spaceCartographic = new Cartographic(CesiumMath.toRadians(-45.0), CesiumMath.toRadians(15.0), 330000.0);
var spaceCartographicGeodeticSurfaceNormal = new Cartesian3(0.68301270189221941, -0.6830127018922193, 0.25881904510252074);
var surfaceCartesian = new Cartesian3(4094327.7921465295, 1909216.4044747739, 4487348.4088659193);
var surfaceCartographic = new Cartographic(CesiumMath.toRadians(25.0), CesiumMath.toRadians(45.0), 0.0);
it('default constructor creates zero Ellipsoid', function() {
var ellipsoid = new Ellipsoid();
expect(ellipsoid.radii).toEqual(Cartesian3.ZERO);
expect(ellipsoid.radiiSquared).toEqual(Cartesian3.ZERO);
expect(ellipsoid.radiiToTheFourth).toEqual(Cartesian3.ZERO);
expect(ellipsoid.oneOverRadii).toEqual(Cartesian3.ZERO);
expect(ellipsoid.oneOverRadiiSquared).toEqual(Cartesian3.ZERO);
expect(ellipsoid.minimumRadius).toEqual(0.0);
expect(ellipsoid.maximumRadius).toEqual(0.0);
});
it('fromCartesian3 creates zero Ellipsoid with no parameters', function() {
var ellipsoid = Ellipsoid.fromCartesian3();
expect(ellipsoid.radii).toEqual(Cartesian3.ZERO);
expect(ellipsoid.radiiSquared).toEqual(Cartesian3.ZERO);
expect(ellipsoid.radiiToTheFourth).toEqual(Cartesian3.ZERO);
expect(ellipsoid.oneOverRadii).toEqual(Cartesian3.ZERO);
expect(ellipsoid.oneOverRadiiSquared).toEqual(Cartesian3.ZERO);
expect(ellipsoid.minimumRadius).toEqual(0.0);
expect(ellipsoid.maximumRadius).toEqual(0.0);
});
it('constructor computes correct values', function() {
var ellipsoid = new Ellipsoid(radii.x, radii.y, radii.z);
expect(ellipsoid.radii).toEqual(radii);
expect(ellipsoid.radiiSquared).toEqual(radiiSquared);
expect(ellipsoid.radiiToTheFourth).toEqual(radiiToTheFourth);
expect(ellipsoid.oneOverRadii).toEqual(oneOverRadii);
expect(ellipsoid.oneOverRadiiSquared).toEqual(oneOverRadiiSquared);
expect(ellipsoid.minimumRadius).toEqual(minimumRadius);
expect(ellipsoid.maximumRadius).toEqual(maximumRadius);
});
it('fromCartesian3 computes correct values', function() {
var ellipsoid = Ellipsoid.fromCartesian3(radii);
expect(ellipsoid.radii).toEqual(radii);
expect(ellipsoid.radiiSquared).toEqual(radiiSquared);
expect(ellipsoid.radiiToTheFourth).toEqual(radiiToTheFourth);
expect(ellipsoid.oneOverRadii).toEqual(oneOverRadii);
expect(ellipsoid.oneOverRadiiSquared).toEqual(oneOverRadiiSquared);
expect(ellipsoid.minimumRadius).toEqual(minimumRadius);
expect(ellipsoid.maximumRadius).toEqual(maximumRadius);
});
it('geodeticSurfaceNormalCartographic works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.geodeticSurfaceNormalCartographic(spaceCartographic);
expect(returnedResult).toEqualEpsilon(spaceCartographicGeodeticSurfaceNormal, CesiumMath.EPSILON15);
});
it('geodeticSurfaceNormalCartographic works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var result = new Cartesian3();
var returnedResult = ellipsoid.geodeticSurfaceNormalCartographic(spaceCartographic, result);
expect(returnedResult).toBe(result);
expect(returnedResult).toEqualEpsilon(spaceCartographicGeodeticSurfaceNormal, CesiumMath.EPSILON15);
});
it('geodeticSurfaceNormal works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.geodeticSurfaceNormal(spaceCartesian);
expect(returnedResult).toEqualEpsilon(spaceCartesianGeodeticSurfaceNormal, CesiumMath.EPSILON15);
});
it('geodeticSurfaceNormal works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var result = new Cartesian3();
var returnedResult = ellipsoid.geodeticSurfaceNormal(spaceCartesian, result);
expect(returnedResult).toBe(result);
expect(returnedResult).toEqualEpsilon(spaceCartesianGeodeticSurfaceNormal, CesiumMath.EPSILON15);
});
it('cartographicToCartesian works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartographicToCartesian(spaceCartographic);
expect(returnedResult).toEqualEpsilon(spaceCartesian, CesiumMath.EPSILON7);
});
it('cartographicToCartesian works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var result = new Cartesian3();
var returnedResult = ellipsoid.cartographicToCartesian(spaceCartographic, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(spaceCartesian, CesiumMath.EPSILON7);
});
it('cartographicArrayToCartesianArray works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartographicArrayToCartesianArray([spaceCartographic, surfaceCartographic]);
expect(returnedResult.length).toEqual(2);
expect(returnedResult[0]).toEqualEpsilon(spaceCartesian, CesiumMath.EPSILON7);
expect(returnedResult[1]).toEqualEpsilon(surfaceCartesian, CesiumMath.EPSILON7);
});
it('cartographicArrayToCartesianArray works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var resultCartesian = new Cartesian3();
var result = [resultCartesian];
var returnedResult = ellipsoid.cartographicArrayToCartesianArray([spaceCartographic, surfaceCartographic], result);
expect(result).toBe(returnedResult);
expect(result[0]).toBe(resultCartesian);
expect(returnedResult.length).toEqual(2);
expect(returnedResult[0]).toEqualEpsilon(spaceCartesian, CesiumMath.EPSILON7);
expect(returnedResult[1]).toEqualEpsilon(surfaceCartesian, CesiumMath.EPSILON7);
});
it('cartesianToCartographic works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartesianToCartographic(surfaceCartesian);
expect(returnedResult).toEqualEpsilon(surfaceCartographic, CesiumMath.EPSILON8);
});
it('cartesianToCartographic works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var result = new Cartographic();
var returnedResult = ellipsoid.cartesianToCartographic(surfaceCartesian, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqualEpsilon(surfaceCartographic, CesiumMath.EPSILON8);
});
it('cartesianToCartographic works close to center', function() {
var expected = new Cartographic(9.999999999999999e-11, 1.0067394967422763e-20, -6378137.0);
var returnedResult = Ellipsoid.WGS84.cartesianToCartographic(new Cartesian3(1e-50, 1e-60, 1e-70));
expect(returnedResult).toEqual(expected);
});
it('cartesianToCartographic return undefined very close to center', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartesianToCartographic(new Cartesian3(1e-150, 1e-150, 1e-150));
expect(returnedResult).toBeUndefined();
});
it('cartesianToCartographic return undefined at center', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartesianToCartographic(Cartesian3.ZERO);
expect(returnedResult).toBeUndefined();
});
it('cartesianArrayToCartographicArray works without a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var returnedResult = ellipsoid.cartesianArrayToCartographicArray([spaceCartesian, surfaceCartesian]);
expect(returnedResult.length).toEqual(2);
expect(returnedResult[0]).toEqualEpsilon(spaceCartographic, CesiumMath.EPSILON7);
expect(returnedResult[1]).toEqualEpsilon(surfaceCartographic, CesiumMath.EPSILON7);
});
it('cartesianArrayToCartographicArray works with a result parameter', function() {
var ellipsoid = Ellipsoid.WGS84;
var resultCartographic = new Cartographic();
var result = [resultCartographic];
var returnedResult = ellipsoid.cartesianArrayToCartographicArray([spaceCartesian, surfaceCartesian], result);
expect(result).toBe(returnedResult);
expect(result.length).toEqual(2);
expect(result[0]).toBe(resultCartographic);
expect(result[0]).toEqualEpsilon(spaceCartographic, CesiumMath.EPSILON7);
expect(result[1]).toEqualEpsilon(surfaceCartographic, CesiumMath.EPSILON7);
});
it('scaleToGeodeticSurface scaled in the x direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(1.0, 0.0, 0.0);
var cartesian = new Cartesian3(9.0, 0.0, 0.0);
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeodeticSurface scaled in the y direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.0, 2.0, 0.0);
var cartesian = new Cartesian3(0.0, 8.0, 0.0);
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeodeticSurface scaled in the z direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.0, 0.0, 3.0);
var cartesian = new Cartesian3(0.0, 0.0, 8.0);
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeodeticSurface works without a result parameter', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.2680893773941855, 1.1160466902266495, 2.3559801120411263);
var cartesian = new Cartesian3(4.0, 5.0, 6.0);
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('scaleToGeodeticSurface works with a result parameter', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.2680893773941855, 1.1160466902266495, 2.3559801120411263);
var cartesian = new Cartesian3(4.0, 5.0, 6.0);
var result = new Cartesian3();
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian, result);
expect(returnedResult).toBe(result);
expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('scaleToGeocentricSurface scaled in the x direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(1.0, 0.0, 0.0);
var cartesian = new Cartesian3(9.0, 0.0, 0.0);
var returnedResult = ellipsoid.scaleToGeocentricSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeocentricSurface scaled in the y direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.0, 2.0, 0.0);
var cartesian = new Cartesian3(0.0, 8.0, 0.0);
var returnedResult = ellipsoid.scaleToGeocentricSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeocentricSurface scaled in the z direction', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.0, 0.0, 3.0);
var cartesian = new Cartesian3(0.0, 0.0, 8.0);
var returnedResult = ellipsoid.scaleToGeocentricSurface(cartesian);
expect(returnedResult).toEqual(expected);
});
it('scaleToGeocentricSurface works without a result parameter', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.7807200583588266, 0.9759000729485333, 1.1710800875382399);
var cartesian = new Cartesian3(4.0, 5.0, 6.0);
var returnedResult = ellipsoid.scaleToGeocentricSurface(cartesian);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('scaleToGeocentricSurface works with a result parameter', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var expected = new Cartesian3(0.7807200583588266, 0.9759000729485333, 1.1710800875382399);
var cartesian = new Cartesian3(4.0, 5.0, 6.0);
var result = new Cartesian3();
var returnedResult = ellipsoid.scaleToGeocentricSurface(cartesian, result);
expect(returnedResult).toBe(result);
expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('scaleToGeodeticSurface returns undefined at center', function() {
var ellipsoid = new Ellipsoid(1.0, 2.0, 3.0);
var cartesian = new Cartesian3(0.0, 0.0, 0.0);
var returnedResult = ellipsoid.scaleToGeodeticSurface(cartesian);
expect(returnedResult).toBeUndefined();
});
it('transformPositionToScaledSpace works without a result parameter', function() {
var ellipsoid = new Ellipsoid(2.0, 3.0, 4.0);
var expected = new Cartesian3(2.0, 2.0, 2.0);
var cartesian = new Cartesian3(4.0, 6.0, 8.0);
var returnedResult = ellipsoid.transformPositionToScaledSpace(cartesian);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('transformPositionToScaledSpace works with a result parameter', function() {
var ellipsoid = new Ellipsoid(2.0, 3.0, 4.0);
var expected = new Cartesian3(3.0, 3.0, 3.0);
var cartesian = new Cartesian3(6.0, 9.0, 12.0);
var result = new Cartesian3();
var returnedResult = ellipsoid.transformPositionToScaledSpace(cartesian, result);
expect(returnedResult).toBe(result);
expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('transformPositionFromScaledSpace works without a result parameter', function() {
var ellipsoid = new Ellipsoid(2.0, 3.0, 4.0);
var expected = new Cartesian3(4.0, 6.0, 8.0);
var cartesian = new Cartesian3(2.0, 2.0, 2.0);
var returnedResult = ellipsoid.transformPositionFromScaledSpace(cartesian);
expect(returnedResult).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('transformPositionFromScaledSpace works with a result parameter', function() {
var ellipsoid = new Ellipsoid(2.0, 3.0, 4.0);
var expected = new Cartesian3(6.0, 9.0, 12.0);
var cartesian = new Cartesian3(3.0, 3.0, 3.0);
var result = new Cartesian3();
var returnedResult = ellipsoid.transformPositionFromScaledSpace(cartesian, result);
expect(returnedResult).toBe(result);
expect(result).toEqualEpsilon(expected, CesiumMath.EPSILON16);
});
it('equals works in all cases', function() {
var ellipsoid = new Ellipsoid(1.0, 0.0, 0.0);
expect(ellipsoid.equals(new Ellipsoid(1.0, 0.0, 0.0))).toEqual(true);
expect(ellipsoid.equals(new Ellipsoid(1.0, 1.0, 0.0))).toEqual(false);
expect(ellipsoid.equals(undefined)).toEqual(false);
});
it('toString produces expected values', function() {
var expected = "(1, 2, 3)";
var ellipsoid = new Ellipsoid(1, 2, 3);
expect(ellipsoid.toString()).toEqual(expected);
});
it('constructor throws if x less than 0', function() {
expect(function() {
return new Ellipsoid(-1, 0, 0);
}).toThrowDeveloperError();
});
it('constructor throws if y less than 0', function() {
expect(function() {
return new Ellipsoid(0, -1, 0);
}).toThrowDeveloperError();
});
it('constructor throws if z less than 0', function() {
expect(function() {
return new Ellipsoid(0, 0, -1);
}).toThrowDeveloperError();
});
it('expect Ellipsoid.geocentricSurfaceNormal is be Cartesian3.normalize', function() {
expect(Ellipsoid.WGS84.geocentricSurfaceNormal).toBe(Cartesian3.normalize);
});
it('geodeticSurfaceNormalCartographic throws with no cartographic', function() {
expect(function() {
Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(undefined);
}).toThrowDeveloperError();
});
it('geodeticSurfaceNormal throws with no cartesian', function() {
expect(function() {
Ellipsoid.WGS84.geodeticSurfaceNormal(undefined);
}).toThrowDeveloperError();
});
it('cartographicToCartesian throws with no cartographic', function() {
expect(function() {
Ellipsoid.WGS84.cartographicToCartesian(undefined);
}).toThrowDeveloperError();
});
it('cartographicArrayToCartesianArray throws with no cartographics', function() {
expect(function() {
Ellipsoid.WGS84.cartographicArrayToCartesianArray(undefined);
}).toThrowDeveloperError();
});
it('cartesianToCartographic throws with no cartesian', function() {
expect(function() {
Ellipsoid.WGS84.cartesianToCartographic(undefined);
}).toThrowDeveloperError();
});
it('cartesianArrayToCartographicArray throws with no cartesians', function() {
expect(function() {
Ellipsoid.WGS84.cartesianArrayToCartographicArray(undefined);
}).toThrowDeveloperError();
});
it('scaleToGeodeticSurface throws with no cartesian', function() {
expect(function() {
Ellipsoid.WGS84.scaleToGeodeticSurface(undefined);
}).toThrowDeveloperError();
});
it('scaleToGeocentricSurface throws with no cartesian', function() {
expect(function() {
Ellipsoid.WGS84.scaleToGeocentricSurface(undefined);
}).toThrowDeveloperError();
});
it('clone copies any object with the proper structure', function() {
var myEllipsoid = {
_radii : { x : 1.0, y : 2.0, z : 3.0 },
_radiiSquared : { x : 4.0, y : 5.0, z : 6.0 },
_radiiToTheFourth : { x: 7.0, y : 8.0, z : 9.0 },
_oneOverRadii : { x : 10.0, y : 11.0, z : 12.0 },
_oneOverRadiiSquared : { x : 13.0, y : 14.0, z : 15.0 },
_minimumRadius : 16.0,
_maximumRadius : 17.0,
_centerToleranceSquared : 18.0
};
var cloned = Ellipsoid.clone(myEllipsoid);
expect(cloned instanceof Ellipsoid).toBe(true);
expect(cloned).toEqual(myEllipsoid);
});
it('clone uses result parameter if provided', function() {
var myEllipsoid = {
_radii : { x : 1.0, y : 2.0, z : 3.0 },
_radiiSquared : { x : 4.0, y : 5.0, z : 6.0 },
_radiiToTheFourth : { x: 7.0, y : 8.0, z : 9.0 },
_oneOverRadii : { x : 10.0, y : 11.0, z : 12.0 },
_oneOverRadiiSquared : { x : 13.0, y : 14.0, z : 15.0 },
_minimumRadius : 16.0,
_maximumRadius : 17.0,
_centerToleranceSquared : 18.0
};
var result = new Ellipsoid();
var cloned = Ellipsoid.clone(myEllipsoid, result);
expect(cloned).toBe(result);
expect(cloned).toEqual(myEllipsoid);
});
});