forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCartesian4Spec.js
951 lines (826 loc) · 39.9 KB
/
Cartesian4Spec.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
defineSuite([
'Core/Cartesian4',
'Core/Color',
'Core/Math',
'Specs/createPackableArraySpecs',
'Specs/createPackableSpecs'
], function(
Cartesian4,
Color,
CesiumMath,
createPackableArraySpecs,
createPackableSpecs) {
'use strict';
it('construct with default values', function() {
var cartesian = new Cartesian4();
expect(cartesian.x).toEqual(0.0);
expect(cartesian.y).toEqual(0.0);
expect(cartesian.z).toEqual(0.0);
expect(cartesian.w).toEqual(0.0);
});
it('construct with all values', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
expect(cartesian.x).toEqual(1.0);
expect(cartesian.y).toEqual(2.0);
expect(cartesian.z).toEqual(3.0);
expect(cartesian.w).toEqual(4.0);
});
it('fromArray creates a Cartesian4', function() {
var cartesian = Cartesian4.fromArray([1.0, 2.0, 3.0, 4.0]);
expect(cartesian).toEqual(new Cartesian4(1.0, 2.0, 3.0, 4.0));
});
it('fromArray with an offset creates a Cartesian4', function() {
var cartesian = Cartesian4.fromArray([0.0, 1.0, 2.0, 3.0, 4.0, 0.0], 1);
expect(cartesian).toEqual(new Cartesian4(1.0, 2.0, 3.0, 4.0));
});
it('fromArray creates a Cartesian4 with a result parameter', function() {
var cartesian = new Cartesian4();
var result = Cartesian4.fromArray([1.0, 2.0, 3.0, 4.0], 0, cartesian);
expect(result).toBe(cartesian);
expect(result).toEqual(new Cartesian4(1.0, 2.0, 3.0, 4.0));
});
it('fromArray throws without values', function() {
expect(function() {
Cartesian4.fromArray();
}).toThrowDeveloperError();
});
it('fromElements returns a cartesian4 with corrrect coordinates', function(){
var cartesian4 = Cartesian4.fromElements(2, 2, 4, 7);
var expectedResult = new Cartesian4(2, 2, 4, 7);
expect(cartesian4).toEqual(expectedResult);
});
it('fromElements result param returns cartesian4 with correct coordinates', function(){
var cartesian4 = new Cartesian4();
Cartesian4.fromElements(2, 2, 4, 7, cartesian4);
var expectedResult = new Cartesian4(2, 2, 4, 7);
expect(cartesian4).toEqual(expectedResult);
});
it('fromColor returns a cartesian4 with corrrect coordinates', function(){
var cartesian4 = Cartesian4.fromColor(new Color(1.0, 2.0, 3.0, 4.0));
expect(cartesian4).toEqual(new Cartesian4(1.0, 2.0, 3.0, 4.0));
});
it('fromColor result param returns cartesian4 with correct coordinates', function(){
var cartesian4 = new Cartesian4();
var result = Cartesian4.fromColor(new Color(1.0, 2.0, 3.0, 4.0), cartesian4);
expect(cartesian4).toBe(result);
expect(cartesian4).toEqual(new Cartesian4(1.0, 2.0, 3.0, 4.0));
});
it('fromColor throws without color', function() {
expect(function() {
Cartesian4.fromColor();
}).toThrowDeveloperError();
});
it('clone without a result parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var result = Cartesian4.clone(cartesian, new Cartesian4());
expect(cartesian).not.toBe(result);
expect(cartesian).toEqual(result);
});
it('clone with a result parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var result = new Cartesian4();
var returnedResult = Cartesian4.clone(cartesian, result);
expect(cartesian).not.toBe(result);
expect(result).toBe(returnedResult);
expect(cartesian).toEqual(result);
});
it('clone works with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var returnedResult = Cartesian4.clone(cartesian, cartesian);
expect(cartesian).toBe(returnedResult);
});
it('maximumComponent works when X is greater', function() {
var cartesian = new Cartesian4(2.0, 1.0, 0.0, -1.0);
expect(Cartesian4.maximumComponent(cartesian)).toEqual(cartesian.x);
});
it('maximumComponent works when Y is greater', function() {
var cartesian = new Cartesian4(1.0, 2.0, 0.0, -1.0);
expect(Cartesian4.maximumComponent(cartesian)).toEqual(cartesian.y);
});
it('maximumComponent works when Z is greater', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, -1.0);
expect(Cartesian4.maximumComponent(cartesian)).toEqual(cartesian.z);
});
it('maximumComponent works when W is greater', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
expect(Cartesian4.maximumComponent(cartesian)).toEqual(cartesian.w);
});
it('minimumComponent works when X is lesser', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
expect(Cartesian4.minimumComponent(cartesian)).toEqual(cartesian.x);
});
it('minimumComponent works when Y is lesser', function() {
var cartesian = new Cartesian4(2.0, 1.0, 3.0, 4.0);
expect(Cartesian4.minimumComponent(cartesian)).toEqual(cartesian.y);
});
it('minimumComponent works when Z is lesser', function() {
var cartesian = new Cartesian4(2.0, 1.0, 0.0, 4.0);
expect(Cartesian4.minimumComponent(cartesian)).toEqual(cartesian.z);
});
it('minimumComponent works when W is lesser', function() {
var cartesian = new Cartesian4(2.0, 1.0, 0.0, -1.0);
expect(Cartesian4.minimumComponent(cartesian)).toEqual(cartesian.w);
});
it('minimumByComponent without a result parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4();
var expected = new Cartesian4(1.0, 0.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(1.0, 0.0, 0.0, 0.0);
second = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expected = new Cartesian4(1.0, 0.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 0.0, 0.0);
second = new Cartesian4(1.0, -20.0, 0.0, 0.0);
expected = new Cartesian4(1.0, -20.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -20.0, 0.0, 0.0);
second = new Cartesian4(1.0, -15.0, 0.0, 0.0);
expected = new Cartesian4(1.0, -20.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.4, 0.0);
second = new Cartesian4(1.0, -20.0, 26.5, 0.0);
expected = new Cartesian4(1.0, -20.0, 26.4, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.5, 0.0);
second = new Cartesian4(1.0, -20.0, 26.4, 0.0);
expected = new Cartesian4(1.0, -20.0, 26.4, 0.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.4, -450.0);
second = new Cartesian4(1.0, -20.0, 26.5, 450.0);
expected = new Cartesian4(1.0, -20.0, 26.4, -450.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.5, 450.0);
second = new Cartesian4(1.0, -20.0, 26.4, -450.0);
expected = new Cartesian4(1.0, -20.0, 26.4, -450.0);
expect(Cartesian4.minimumByComponent(first, second, result)).toEqual(expected);
});
it('minimumByComponent with a result parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4();
var returnedResult = Cartesian4.minimumByComponent(first, second, result);
expect(returnedResult).toBe(result);
expect(returnedResult).toEqual(result);
});
it('minimumByComponent with a result parameter that is an input parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(1.0, 0.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, first)).toEqual(result);
first.x = 1.0;
second.x = 2.0;
expect(Cartesian4.minimumByComponent(first, second, first)).toEqual(result);
});
it('minimumByComponent with a result parameter that is an input parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(1.0, 0.0, 0.0, 0.0);
expect(Cartesian4.minimumByComponent(first, second, second)).toEqual(result);
first.x = 1.0;
second.x = 2.0;
expect(Cartesian4.minimumByComponent(first, second, second)).toEqual(result);
});
it('minimumByComponent throws without first', function() {
expect(function() {
Cartesian4.minimumByComponent();
}).toThrowDeveloperError();
});
it('minimumByComponent throws without second', function() {
expect(function() {
Cartesian4.minimumByComponent(new Cartesian4());
}).toThrowDeveloperError();
});
it('minimumByComponent works when first\'s or second\'s X is lesser', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
second.x = 3.0;
result.x = 2.0;
expect(Cartesian4.minimumByComponent(first, second,r )).toEqual(result);
});
it('minimumByComponent works when first\'s or second\'s Y is lesser', function() {
var first = new Cartesian4(0.0, 2.0, 0.0, 0.0);
var second = new Cartesian4(0.0, 1.0, 0.0, 0.0);
var result = new Cartesian4(0.0, 1.0, 0.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
second.y = 3.0;
result.y = 2.0;
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
});
it('minimumByComponent works when first\'s or second\'s Z is lesser', function() {
var first = new Cartesian4(0.0, 0.0, 2.0, 0.0);
var second = new Cartesian4(0.0, 0.0, 1.0, 0.0);
var result = new Cartesian4(0.0, 0.0, 1.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
second.z = 3.0;
result.z = 2.0;
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
});
it('minimumByComponent works when first\'s or second\'s W is lesser', function() {
var first = new Cartesian4(0.0, 0.0, 0.0, 2.0);
var second = new Cartesian4(0.0, 0.0, 0.0, 1.0);
var result = new Cartesian4(0.0, 0.0, 0.0, 1.0);
var r = new Cartesian4();
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
second.w = 3.0;
result.w = 2.0;
expect(Cartesian4.minimumByComponent(first, second, r)).toEqual(result);
});
it('maximumByComponent', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4();
var expected = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(1.0, 0.0, 0.0, 0.0);
second = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expected = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 0.0, 0.0);
second = new Cartesian4(1.0, -20.0, 0.0, 0.0);
expected = new Cartesian4(2.0, -15.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -20.0, 0.0, 0.0);
second = new Cartesian4(1.0, -15.0, 0.0, 0.0);
expected = new Cartesian4(2.0, -15.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.4, 0.0);
second = new Cartesian4(1.0, -20.0, 26.5, 0.0);
expected = new Cartesian4(2.0, -15.0, 26.5, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.5, 0.0);
second = new Cartesian4(1.0, -20.0, 26.4, 0.0);
expected = new Cartesian4(2.0, -15.0, 26.5, 0.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.5, 450.0);
second = new Cartesian4(1.0, -20.0, 26.4, -450.0);
expected = new Cartesian4(2.0, -15.0, 26.5, 450.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
first = new Cartesian4(2.0, -15.0, 26.5, -450.0);
second = new Cartesian4(1.0, -20.0, 26.4, 450.0);
expected = new Cartesian4(2.0, -15.0, 26.5, 450.0);
expect(Cartesian4.maximumByComponent(first, second, result)).toEqual(expected);
});
it('maximumByComponent with a result parameter that is an input parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, first)).toEqual(result);
first.x = 1.0;
second.x = 2.0;
expect(Cartesian4.maximumByComponent(first, second, first)).toEqual(result);
});
it('maximumByComponent with a result parameter that is an input parameter', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(2.0, 0.0, 0.0, 0.0);
expect(Cartesian4.maximumByComponent(first, second, second)).toEqual(result);
first.x = 1.0;
second.x = 2.0;
expect(Cartesian4.maximumByComponent(first, second, second)).toEqual(result);
});
it('maximumByComponent throws without first', function() {
expect(function() {
Cartesian4.maximumByComponent();
}).toThrowDeveloperError();
});
it('maximumByComponent throws without second', function() {
expect(function() {
Cartesian4.maximumByComponent(new Cartesian4());
}).toThrowDeveloperError();
});
it('maximumByComponent works when first\'s or second\'s X is greater', function() {
var first = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var second = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
second.x = 3.0;
result.x = 3.0;
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
});
it('maximumByComponent works when first\'s or second\'s Y is greater', function() {
var first = new Cartesian4(0.0, 2.0, 0.0, 0.0);
var second = new Cartesian4(0.0, 1.0, 0.0, 0.0);
var result = new Cartesian4(0.0, 2.0, 0.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
second.y = 3.0;
result.y = 3.0;
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
});
it('maximumByComponent works when first\'s or second\'s Z is greater', function() {
var first = new Cartesian4(0.0, 0.0, 2.0, 0.0);
var second = new Cartesian4(0.0, 0.0, 1.0, 0.0);
var result = new Cartesian4(0.0, 0.0, 2.0, 0.0);
var r = new Cartesian4();
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
second.z = 3.0;
result.z = 3.0;
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
});
it('maximumByComponent works when first\'s or second\'s W is greater', function() {
var first = new Cartesian4(0.0, 0.0, 0.0, 2.0);
var second = new Cartesian4(0.0, 0.0, 0.0, 1.0);
var result = new Cartesian4(0.0, 0.0, 0.0, 2.0);
var r = new Cartesian4();
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
second.w = 3.0;
result.w = 3.0;
expect(Cartesian4.maximumByComponent(first, second, r)).toEqual(result);
});
it('magnitudeSquared', function() {
var cartesian = new Cartesian4(3.0, 4.0, 5.0, 6.0);
expect(Cartesian4.magnitudeSquared(cartesian)).toEqual(86.0);
});
it('magnitude', function() {
var cartesian = new Cartesian4(3.0, 4.0, 5.0, 6.0);
expect(Cartesian4.magnitude(cartesian)).toEqual(Math.sqrt(86.0));
});
it('distance', function() {
var distance = Cartesian4.distance(new Cartesian4(1.0, 0.0, 0.0, 0.0), new Cartesian4(2.0, 0.0, 0.0, 0.0));
expect(distance).toEqual(1.0);
});
it('distance throws without left', function() {
expect(function() {
Cartesian4.distance();
}).toThrowDeveloperError();
});
it('distance throws without right', function() {
expect(function() {
Cartesian4.distance(Cartesian4.UNIT_X);
}).toThrowDeveloperError();
});
it('distanceSquared', function() {
var distanceSquared = Cartesian4.distanceSquared(new Cartesian4(1.0, 0.0, 0.0, 0.0), new Cartesian4(3.0, 0.0, 0.0, 0.0));
expect(distanceSquared).toEqual(4.0);
});
it('distanceSquared throws without left', function() {
expect(function() {
Cartesian4.distanceSquared();
}).toThrowDeveloperError();
});
it('distanceSquared throws without right', function() {
expect(function() {
Cartesian4.distanceSquared(Cartesian4.UNIT_X);
}).toThrowDeveloperError();
});
it('normalize works with a result parameter', function() {
var cartesian = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var expectedResult = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var result = new Cartesian4();
var returnedResult = Cartesian4.normalize(cartesian, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('normalize works with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(2.0, 0.0, 0.0, 0.0);
var expectedResult = new Cartesian4(1.0, 0.0, 0.0, 0.0);
var returnedResult = Cartesian4.normalize(cartesian, cartesian);
expect(cartesian).toBe(returnedResult);
expect(cartesian).toEqual(expectedResult);
});
it('normalize throws with zero vector', function() {
expect(function() {
Cartesian4.normalize(Cartesian4.ZERO, new Cartesian4());
}).toThrowDeveloperError();
});
it('multiplyComponents works with a result parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 8.0);
var right = new Cartesian4(4.0, 5.0, 7.0, 9.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(8.0, 15.0, 42.0, 72.0);
var returnedResult = Cartesian4.multiplyComponents(left, right, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('multiplyComponents works with a result parameter that is an input parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 8.0);
var right = new Cartesian4(4.0, 5.0, 7.0, 9.0);
var expectedResult = new Cartesian4(8.0, 15.0, 42.0, 72.0);
var returnedResult = Cartesian4.multiplyComponents(left, right, left);
expect(left).toBe(returnedResult);
expect(left).toEqual(expectedResult);
});
it('divideComponents works with a result parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 15.0);
var right = new Cartesian4(4.0, 5.0, 8.0, 2.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(0.5, 0.6, 0.75, 7.5);
var returnedResult = Cartesian4.divideComponents(left, right, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('divideComponents works with a result parameter that is an input parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 15.0);
var right = new Cartesian4(4.0, 5.0, 8.0, 2.0);
var expectedResult = new Cartesian4(0.5, 0.6, 0.75, 7.5);
var returnedResult = Cartesian4.divideComponents(left, right, left);
expect(left).toBe(returnedResult);
expect(left).toEqual(expectedResult);
});
it('dot', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 8.0);
var right = new Cartesian4(4.0, 5.0, 7.0, 9.0);
var expectedResult = 137.0;
var result = Cartesian4.dot(left, right);
expect(result).toEqual(expectedResult);
});
it('add works with a result parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 8.0);
var right = new Cartesian4(4.0, 5.0, 7.0, 9.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(6.0, 8.0, 13.0, 17.0);
var returnedResult = Cartesian4.add(left, right, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('add works with a result parameter that is an input parameter', function() {
var left = new Cartesian4(2.0, 3.0, 6.0, 8.0);
var right = new Cartesian4(4.0, 5.0, 7.0, 9.0);
var expectedResult = new Cartesian4(6.0, 8.0, 13.0, 17.0);
var returnedResult = Cartesian4.add(left, right, left);
expect(left).toBe(returnedResult);
expect(left).toEqual(expectedResult);
});
it('subtract works with a result parameter', function() {
var left = new Cartesian4(2.0, 3.0, 4.0, 8.0);
var right = new Cartesian4(1.0, 5.0, 7.0, 9.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(1.0, -2.0, -3.0, -1.0);
var returnedResult = Cartesian4.subtract(left, right, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('subtract works with this result parameter', function() {
var left = new Cartesian4(2.0, 3.0, 4.0, 8.0);
var right = new Cartesian4(1.0, 5.0, 7.0, 9.0);
var expectedResult = new Cartesian4(1.0, -2.0, -3.0, -1.0);
var returnedResult = Cartesian4.subtract(left, right, left);
expect(returnedResult).toBe(left);
expect(left).toEqual(expectedResult);
});
it('multiplyByScalar with a result parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var result = new Cartesian4();
var scalar = 2;
var expectedResult = new Cartesian4(2.0, 4.0, 6.0, 8.0);
var returnedResult = Cartesian4.multiplyByScalar(cartesian, scalar, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('multiplyByScalar with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var scalar = 2;
var expectedResult = new Cartesian4(2.0, 4.0, 6.0, 8.0);
var returnedResult = Cartesian4.multiplyByScalar(cartesian, scalar, cartesian);
expect(cartesian).toBe(returnedResult);
expect(cartesian).toEqual(expectedResult);
});
it('divideByScalar with a result parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var result = new Cartesian4();
var scalar = 2;
var expectedResult = new Cartesian4(0.5, 1.0, 1.5, 2.0);
var returnedResult = Cartesian4.divideByScalar(cartesian, scalar, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('divideByScalar with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
var scalar = 2;
var expectedResult = new Cartesian4(0.5, 1.0, 1.5, 2.0);
var returnedResult = Cartesian4.divideByScalar(cartesian, scalar, cartesian);
expect(cartesian).toBe(returnedResult);
expect(cartesian).toEqual(expectedResult);
});
it('negate with a result parameter', function() {
var cartesian = new Cartesian4(1.0, -2.0, -5.0, 4.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(-1.0, 2.0, 5.0, -4.0);
var returnedResult = Cartesian4.negate(cartesian, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('negate with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(1.0, -2.0, -5.0);
var expectedResult = new Cartesian4(-1.0, 2.0, 5.0);
var returnedResult = Cartesian4.negate(cartesian, cartesian);
expect(cartesian).toBe(returnedResult);
expect(cartesian).toEqual(expectedResult);
});
it('abs with a result parameter', function() {
var cartesian = new Cartesian4(1.0, -2.0, -4.0, -3.0);
var result = new Cartesian4();
var expectedResult = new Cartesian4(1.0, 2.0, 4.0, 3.0);
var returnedResult = Cartesian4.abs(cartesian, result);
expect(result).toBe(returnedResult);
expect(result).toEqual(expectedResult);
});
it('abs with a result parameter that is an input parameter', function() {
var cartesian = new Cartesian4(1.0, -2.0, -4.0, -3.0);
var expectedResult = new Cartesian4(1.0, 2.0, 4.0, 3.0);
var returnedResult = Cartesian4.abs(cartesian, cartesian);
expect(cartesian).toBe(returnedResult);
expect(cartesian).toEqual(expectedResult);
});
it('lerp works with a result parameter that is an input parameter', function() {
var start = new Cartesian4(4.0, 8.0, 10.0, 20.0);
var end = new Cartesian4(8.0, 20.0, 20.0, 30.0);
var t = 0.25;
var expectedResult = new Cartesian4(5.0, 11.0, 12.5, 22.5);
var returnedResult = Cartesian4.lerp(start, end, t, start);
expect(start).toBe(returnedResult);
expect(start).toEqual(expectedResult);
});
it('lerp extrapolate forward', function() {
var start = new Cartesian4(4.0, 8.0, 10.0, 20.0);
var end = new Cartesian4(8.0, 20.0, 20.0, 30.0);
var t = 2.0;
var result = new Cartesian4();
var expectedResult = new Cartesian4(12.0, 32.0, 30.0, 40.0);
result = Cartesian4.lerp(start, end, t, result);
expect(result).toEqual(expectedResult);
});
it('lerp extrapolate backward', function() {
var start = new Cartesian4(4.0, 8.0, 10.0, 20.0);
var end = new Cartesian4(8.0, 20.0, 20.0, 30.0);
var t = -1.0;
var result = new Cartesian4();
var expectedResult = new Cartesian4(0.0, -4.0, 0.0, 10.0);
result = Cartesian4.lerp(start, end, t, result);
expect(result).toEqual(expectedResult);
});
it('most orthogonal angle is x', function() {
var v = new Cartesian4(0.0, 1.0, 2.0, 3.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_X);
});
it('most orthogonal angle is y', function() {
var v = new Cartesian4(1.0, 0.0, 2.0, 3.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_Y);
});
it('most orthogonal angle is z', function() {
var v = new Cartesian4(2.0, 3.0, 0.0, 1.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_Z);
v = new Cartesian4(3.0, 2.0, 0.0, 1.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_Z);
});
it('most orthogonal angle is w', function() {
var v = new Cartesian4(1.0, 2.0, 3.0, 0.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_W);
v = new Cartesian4(2.0, 3.0, 1.0, 0.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_W);
v = new Cartesian4(3.0, 1.0, 2.0, 0.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_W);
v = new Cartesian4(3.0, 2.0, 1.0, 0.0);
expect(Cartesian4.mostOrthogonalAxis(v, new Cartesian4())).toEqual(Cartesian4.UNIT_W);
});
it('equals', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
expect(Cartesian4.equals(cartesian, new Cartesian4(1.0, 2.0, 3.0, 4.0))).toEqual(true);
expect(Cartesian4.equals(cartesian, new Cartesian4(2.0, 2.0, 3.0, 4.0))).toEqual(false);
expect(Cartesian4.equals(cartesian, new Cartesian4(2.0, 1.0, 3.0, 4.0))).toEqual(false);
expect(Cartesian4.equals(cartesian, new Cartesian4(1.0, 2.0, 4.0, 4.0))).toEqual(false);
expect(Cartesian4.equals(cartesian, new Cartesian4(1.0, 2.0, 3.0, 5.0))).toEqual(false);
expect(Cartesian4.equals(cartesian, undefined)).toEqual(false);
});
it('equalsEpsilon', function() {
var cartesian = new Cartesian4(1.0, 2.0, 3.0, 4.0);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 3.0, 4.0), 0.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 3.0, 4.0), 1.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(2.0, 2.0, 3.0, 4.0), 1.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 3.0, 3.0, 4.0), 1.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 4.0, 4.0), 1.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 3.0, 5.0), 1.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(2.0, 2.0, 3.0, 4.0), CesiumMath.EPSILON6)).toEqual(false);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 3.0, 3.0, 4.0), CesiumMath.EPSILON6)).toEqual(false);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 4.0, 4.0), CesiumMath.EPSILON6)).toEqual(false);
expect(cartesian.equalsEpsilon(new Cartesian4(1.0, 2.0, 3.0, 5.0), CesiumMath.EPSILON6)).toEqual(false);
expect(cartesian.equalsEpsilon(undefined, 1)).toEqual(false);
cartesian = new Cartesian4(3000000.0, 4000000.0, 5000000.0, 6000000.0);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.0, 4000000.0, 5000000.0, 6000000.0), 0.0)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.2, 4000000.0, 5000000.0, 6000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.0, 4000000.2, 5000000.0, 6000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.0, 4000000.0, 5000000.2, 6000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.0, 4000000.0, 5000000.0, 6000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.2, 4000000.2, 5000000.2, 6000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(cartesian.equalsEpsilon(new Cartesian4(3000000.2, 4000000.2, 5000000.2, 6000000.2), CesiumMath.EPSILON9)).toEqual(false);
expect(cartesian.equalsEpsilon(undefined, 1)).toEqual(false);
expect(Cartesian4.equalsEpsilon(undefined, cartesian, 1)).toEqual(false);
});
it('toString', function() {
var cartesian = new Cartesian4(1.123, 2.345, 6.789, 6.123);
expect(cartesian.toString()).toEqual('(1.123, 2.345, 6.789, 6.123)');
});
it('clone returns undefined with no parameter', function() {
expect(Cartesian4.clone()).toBeUndefined();
});
it('maximumComponent throws with no parameter', function() {
expect(function() {
Cartesian4.maximumComponent();
}).toThrowDeveloperError();
});
it('minimumComponent throws with no parameter', function() {
expect(function() {
Cartesian4.minimumComponent();
}).toThrowDeveloperError();
});
it('magnitudeSquared throws with no parameter', function() {
expect(function() {
Cartesian4.magnitudeSquared();
}).toThrowDeveloperError();
});
it('magnitude throws with no parameter', function() {
expect(function() {
Cartesian4.magnitude();
}).toThrowDeveloperError();
});
it('normalize throws with no parameter', function() {
expect(function() {
Cartesian4.normalize();
}).toThrowDeveloperError();
});
it('dot throws with no left parameter', function() {
expect(function() {
Cartesian4.dot(undefined, new Cartesian4());
}).toThrowDeveloperError();
});
it('multiplyComponents throw with no left parameter', function() {
var right = new Cartesian4(4.0, 5.0, 6.0, 7.0);
expect(function() {
Cartesian4.multiplyComponents(undefined, right);
}).toThrowDeveloperError();
});
it('multiplyComponents throw with no right parameter', function() {
var left = new Cartesian4(4.0, 5.0, 6.0, 7.0);
expect(function() {
Cartesian4.multiplyComponents(left, undefined);
}).toThrowDeveloperError();
});
it('divideComponents throw with no left parameter', function() {
var right = new Cartesian4(4.0, 5.0, 6.0, 7.0);
expect(function() {
Cartesian4.divideComponents(undefined, right);
}).toThrowDeveloperError();
});
it('divideComponents throw with no right parameter', function() {
var left = new Cartesian4(4.0, 5.0, 6.0, 7.0);
expect(function() {
Cartesian4.divideComponents(left, undefined);
}).toThrowDeveloperError();
});
it('dot throws with no right parameter', function() {
expect(function() {
Cartesian4.dot(new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('add throws with no left parameter', function() {
expect(function() {
Cartesian4.add(undefined, new Cartesian4());
}).toThrowDeveloperError();
});
it('add throws with no right parameter', function() {
expect(function() {
Cartesian4.add(new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('subtract throws with no left parameter', function() {
expect(function() {
Cartesian4.subtract(undefined, new Cartesian4());
}).toThrowDeveloperError();
});
it('subtract throws with no right parameter', function() {
expect(function() {
Cartesian4.subtract(new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('multiplyByScalar throws with no cartesian parameter', function() {
expect(function() {
Cartesian4.multiplyByScalar(undefined, 2.0);
}).toThrowDeveloperError();
});
it('multiplyByScalar throws with no scalar parameter', function() {
expect(function() {
Cartesian4.multiplyByScalar(new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('divideByScalar throws with no cartesian parameter', function() {
expect(function() {
Cartesian4.divideByScalar(undefined, 2.0);
}).toThrowDeveloperError();
});
it('divideByScalar throws with no scalar parameter', function() {
expect(function() {
Cartesian4.divideByScalar(new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('negate throws with no cartesian parameter', function() {
expect(function() {
Cartesian4.negate(undefined);
}).toThrowDeveloperError();
});
it('abs throws with no cartesian parameter', function() {
expect(function() {
Cartesian4.abs(undefined);
}).toThrowDeveloperError();
});
it('lerp throws with no start parameter', function() {
var end = new Cartesian4(8.0, 20.0, 6.0);
var t = 0.25;
expect(function() {
Cartesian4.lerp(undefined, end, t);
}).toThrowDeveloperError();
});
it('lerp throws with no end parameter', function() {
var start = new Cartesian4(4.0, 8.0, 6.0);
var t = 0.25;
expect(function() {
Cartesian4.lerp(start, undefined, t);
}).toThrowDeveloperError();
});
it('lerp throws with no t parameter', function() {
var start = new Cartesian4(4.0, 8.0, 6.0, 7.0);
var end = new Cartesian4(8.0, 20.0, 6.0, 7.0);
expect(function() {
Cartesian4.lerp(start, end, undefined);
}).toThrowDeveloperError();
});
it('mostOrthogonalAxis throws with no cartesian parameter', function() {
expect(function() {
Cartesian4.mostOrthogonalAxis(undefined);
}).toThrowDeveloperError();
});
it('equalsEpsilon throws with no epsilon', function() {
expect(function() {
Cartesian4.equalsEpsilon(new Cartesian4(), new Cartesian4(), undefined);
}).toThrowDeveloperError();
});
it('minimumByComponent throws with no result', function() {
expect(function() {
Cartesian4.minimumByComponent(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('maximumByComponent throws with no result', function() {
expect(function() {
Cartesian4.maximumByComponent(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('normalize throws with no result', function() {
expect(function() {
Cartesian4.normalize(new Cartesian4());
}).toThrowDeveloperError();
});
it('multiplyComponents throws with no result', function() {
expect(function() {
Cartesian4.multiplyComponents(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('divideComponents throws with no result', function() {
expect(function() {
Cartesian4.divideComponents(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('add throws with no result', function() {
expect(function() {
Cartesian4.add(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('subtract throws with no result', function() {
expect(function() {
Cartesian4.subtract(new Cartesian4(), new Cartesian4());
}).toThrowDeveloperError();
});
it('multiplyByScalar throws with no result', function() {
expect(function() {
Cartesian4.multiplyByScalar(new Cartesian4(), 2);
}).toThrowDeveloperError();
});
it('divideByScalar throws with no result', function() {
expect(function() {
Cartesian4.divideByScalar(new Cartesian4(), 2);
}).toThrowDeveloperError();
});
it('negate throws with no result', function() {
expect(function() {
Cartesian4.negate(new Cartesian4());
}).toThrowDeveloperError();
});
it('abs throws with no result', function() {
expect(function() {
Cartesian4.abs(new Cartesian4());
}).toThrowDeveloperError();
});
it('mostOrthogonalAxis throws with no result', function() {
expect(function() {
Cartesian4.mostOrthogonalAxis(new Cartesian4());
}).toThrowDeveloperError();
});
createPackableSpecs(Cartesian4, new Cartesian4(1, 2, 3, 4), [1, 2, 3, 4]);
createPackableArraySpecs(Cartesian4, [new Cartesian4(1, 2, 3, 4), new Cartesian4(5, 6, 7, 8)], [1, 2, 3, 4, 5, 6, 7, 8]);
});