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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const TOTAL1: i32 = -3;
const ANNLR1: i32 = -2;
const PARTL1: i32 = -1;
const NOOCC: i32 = 0;
const PARTL2: i32 = 1;
const ANNLR2: i32 = 2;
const TOTAL2: i32 = 3;
const ANGTOL: f64 = 0.000000000001;
const CNVTOL: f64 = 0.00000000000001;
const ADJTOL: f64 = 0.00000000000001;
const LNSIZE: i32 = 255;
const MAXITR: i32 = 2048;
const UBEL: i32 = 9;
const UBPL: i32 = 4;
const NCASE1: i32 = 200;
const NCASE2: i32 = 200;
struct SaveVars {
ORIGIN: StackArray<f64, 3>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut ORIGIN = StackArray::<f64, 3>::new(1..=3);
{
use f2rust_std::data::Val;
let mut clist = []
.into_iter()
.chain(std::iter::repeat_n(Val::D(0.0), 3 as usize))
.chain([]);
ORIGIN
.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { ORIGIN }
}
}
//$Procedure F_ZZOCCED3 ( Test ellipsoid occultation routine )
pub fn F_ZZOCCED3(OK: &mut bool, ctx: &mut Context) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut TITLE = [b' '; LNSIZE as usize];
let mut ALT: f64 = 0.0;
let mut ALPHA: f64 = 0.0;
let mut ANGLE: f64 = 0.0;
let mut AXIS = StackArray::<f64, 3>::new(1..=3);
let mut BASIS = StackArray3D::<f64, 18>::new(1..=3, 1..=3, 1..=2);
let mut BETA: f64 = 0.0;
let mut BIGSEP: f64 = 0.0;
let mut CENTR1 = StackArray::<f64, 3>::new(1..=3);
let mut CENTR2 = StackArray::<f64, 3>::new(1..=3);
let mut CTRSEP: f64 = 0.0;
let mut CHOP = StackArray::<f64, 4>::new(1..=UBPL);
let mut DIFF: f64 = 0.0;
let mut DIST = StackArray::<f64, 2>::new(1..=2);
let mut GAMMA: f64 = 0.0;
let mut HIGH: f64 = 0.0;
let mut LAT: f64 = 0.0;
let mut LIMB = StackArray::<f64, 9>::new(1..=UBEL);
let mut LIMIT: f64 = 0.0;
let mut LMBCTR = StackArray::<f64, 3>::new(1..=3);
let mut LMBMAJ = StackArray::<f64, 3>::new(1..=3);
let mut LMBMIN = StackArray::<f64, 3>::new(1..=3);
let mut LON: f64 = 0.0;
let mut LOW: f64 = 0.0;
let mut LVIEW = StackArray::<f64, 3>::new(1..=3);
let mut MAXANG = StackArray::<f64, 2>::new(1..=2);
let mut MAXRAD = StackArray::<f64, 2>::new(1..=2);
let mut MIDPT: f64 = 0.0;
let mut MINANG = StackArray::<f64, 2>::new(1..=2);
let mut MINRAD = StackArray::<f64, 3>::new(1..=3);
let mut NEWCTR = StackArray::<f64, 3>::new(1..=3);
let mut NORMAL = StackArray::<f64, 3>::new(1..=3);
let mut R = StackArray2D::<f64, 6>::new(1..=3, 1..=2);
let mut RADSUM: f64 = 0.0;
let mut RMAT = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut RSIGN: f64 = 0.0;
let mut RVEC = StackArray::<f64, 3>::new(1..=3);
let mut SCALE: f64 = 0.0;
let mut SEMAX1 = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut SEMAX2 = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
let mut SRFDIR = StackArray::<f64, 3>::new(1..=3);
let mut TSTVEC = StackArray::<f64, 3>::new(1..=3);
let mut XPT = StackArray::<f64, 3>::new(1..=3);
let mut UVPOFF = StackArray::<f64, 3>::new(1..=3);
let mut V1 = StackArray::<f64, 3>::new(1..=3);
let mut V2 = StackArray::<f64, 3>::new(1..=3);
let mut V3 = StackArray::<f64, 3>::new(1..=3);
let mut VIEWPT = StackArray::<f64, 3>::new(1..=3);
let mut VPCTR1 = StackArray::<f64, 3>::new(1..=3);
let mut VPCTR2 = StackArray::<f64, 3>::new(1..=3);
let mut VPOFF = StackArray::<f64, 3>::new(1..=3);
let mut VPOFF2 = StackArray::<f64, 3>::new(1..=3);
let mut VPXPT1 = StackArray::<f64, 3>::new(1..=3);
let mut XLIMB = StackArray::<f64, 9>::new(1..=UBEL);
let mut XPT1 = StackArray::<f64, 3>::new(1..=3);
let mut XPT2 = StackArray::<f64, 3>::new(1..=3);
let mut XSEP: f64 = 0.0;
let mut Y = StackArray::<f64, 3>::new(1..=3);
let mut Z = StackArray::<f64, 3>::new(1..=3);
let mut CODE: i32 = 0;
let mut NITR: i32 = 0;
let mut NXPTS: i32 = 0;
let mut SEED: i32 = 0;
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Other functions
//
//
// Local parameters
//
//
// Recommendation: increase the parameters NCASE1 and NCASE2
// to 1000 for robust testing.
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Begin every test family with an open call.
//
testutil::TOPEN(b"F_ZZOCCED3", ctx)?;
//
// The initial set of cases tests the accuracy with which
// ZZOCCED can detect transitions between total occultation
// and partial occultation.
//
// In the discussion below, we use the terms "target" and
// "ellipsoid" interchangeably
//
// These cases attempt to cover a broad set of geometric cases.
// In order to do this efficiently, random numbers are used
// to generate most inputs:
//
// - A random scale factor is applied uniformly to all
// participating objects.
//
// - The principal axis matrices of both targets are
// generated from random Euler angles.
//
// - The radii of each target are chosen randomly, with
// each radius in the range of 1:100 prior to scaling.
//
// - The location of the observer's sub-point on the first
// target is selected using a direction vector with random
// components. The ray emanating from the center of the
// first target and parallel to this direction vector
// defines the sub-point.
//
// - The altitude of the observer above its sub-point on the
// first target is selected randomly.
//
// - The original position of the center of the second target
// is on the ray emanating from the observer and passing
// through the center of the first target. The distance
// between the target centers is chosen randomly.
//
// The second target is scaled to make sure it is in total
// occultation by the first target.
//
// - To search for state transitions, the second target is
// displaced from its original position. The displacement
// is accomplished by rotating the vector from the observer
// to the center of the second target. This rotated vector
// is constrained to lie in a plane whose normal vector is
// orthogonal to the vector from the observer to the center
// of the first target. The orientation of this normal vector
// is selected randomly.
//
//
//
//
// Initialize the random number seed.
//
SEED = -1;
for I in 1..=NCASE1 {
// WRITE (*,*) '=========================='
//
// --- Case: ------------------------------------------------------
//
fstr::assign(&mut TITLE, b"\"General\" case: search for transitions from total to partial occultation for ellipsoids of different shape, size and orientation. Loop iteration = #.");
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
//
// Pick a scale factor; we'll scale all of the participating
// objects using this factor.
//
SCALE = f64::powf(10.0, testutil::T_RANDD(-10.0, 10.0, &mut SEED, ctx)?);
//
// Create random orientation matrices for both ellipsoids. We
// start with three Euler angles. Also pick random radii for
// the ellipsoids.
//
for J in 1..=2 {
ALPHA = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
BETA = testutil::T_RANDD(
-spicelib::HALFPI(ctx),
spicelib::HALFPI(ctx),
&mut SEED,
ctx,
)?;
GAMMA = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
spicelib::EUL2M(ALPHA, BETA, GAMMA, 1, 2, 3, RMAT.as_slice_mut(), ctx)?;
spicelib::XPOSE(RMAT.as_slice(), BASIS.subarray_mut([1, 1, J]));
//
// Pick unscaled radius values in the range 1:10 for the
// Jth ellipsoid.
//
R[[1, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
R[[2, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
R[[3, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
//
// Scale the radii using our global scale factor.
//
spicelib::VSCLIP(SCALE, R.subarray_mut([1, J]));
//
// Save the minimum and maximum radii of each ellipsoid.
//
MINRAD[J] = intrinsics::DMIN1(&[R[[1, J]], R[[2, J]], R[[3, J]]]);
MAXRAD[J] = intrinsics::DMAX1(&[R[[1, J]], R[[2, J]], R[[3, J]]]);
// WRITE (*,*) 'MINRAD, MAXRAD = ', MINRAD(J), MAXRAD(J)
//
// Create the Jth semi-axis matrix by scaling the column
// vectors of RMAT.
//
for K in 1..=3 {
if (J == 1) {
spicelib::VSCL(
R[[K, J]],
BASIS.subarray([1, K, 1]),
SEMAX1.subarray_mut([1, K]),
);
} else {
spicelib::VSCL(
R[[K, J]],
BASIS.subarray([1, K, 2]),
SEMAX2.subarray_mut([1, K]),
);
}
}
}
//
// Pick a center for the first ellipsoid.
//
for J in 1..=3 {
CENTR1[J] = (SCALE * testutil::T_RANDD(-1000.0, 1000.0, &mut SEED, ctx)?);
}
//
// Pick a random viewing point. Start by picking longitude
// and latitude of a surface point on the first ellipsoid.
//
LON = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
LAT = testutil::T_RANDD(
-spicelib::HALFPI(ctx),
spicelib::HALFPI(ctx),
&mut SEED,
ctx,
)?;
spicelib::LATREC(1.0, LON, LAT, SRFDIR.as_slice_mut());
//
// Since the origin of this ray is the center of the
// ellipsoid, we don't have to check the found flag.
//
spicelib::SURFPT(
save.ORIGIN.as_slice(),
SRFDIR.as_slice(),
R[[1, 1]],
R[[2, 1]],
R[[3, 1]],
XPT.as_slice_mut(),
&mut FOUND,
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
//
// Pick a random altitude.
//
ALT = (SCALE * f64::powf(10.0, testutil::T_RANDD(-1.0, 4.0, &mut SEED, ctx)?));
//
// Find the local outward unit surface normal, scale it by
// the altitude, and add it to XPT to obtain the view point.
//
spicelib::SURFNM(
R[[1, 1]],
R[[2, 1]],
R[[3, 1]],
XPT.as_slice(),
NORMAL.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VLCOM(
1.0,
XPT.as_slice(),
ALT,
NORMAL.as_slice(),
VIEWPT.as_slice_mut(),
);
//
//
// We want to find the limb of the first ellipsoid as seen
// from the viewing point.
//
// Express the viewing point as an offset from the center
// of the first ellipsoid.
//
spicelib::VSUB(VIEWPT.as_slice(), CENTR1.as_slice(), VPOFF.as_slice_mut());
//
// Transform the viewing point into the principal axis frame
// of the first ellipsoid.
//
spicelib::MTXV(
BASIS.subarray([1, 1, 1]),
VPOFF.as_slice(),
LVIEW.as_slice_mut(),
);
//
// Find the limb of the ellipsoid. Rotate the limb back to the
// original reference frame and shift the limb center to reflect
// the offset of the first ellipsoid's center from the origin.
//
spicelib::EDLIMB(
R[[1, 1]],
R[[2, 1]],
R[[3, 1]],
LVIEW.as_slice(),
XLIMB.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::EL2CGV(
XLIMB.as_slice(),
V1.as_slice_mut(),
V2.as_slice_mut(),
V3.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::MXV(
BASIS.subarray([1, 1, 1]),
V1.as_slice(),
LMBCTR.as_slice_mut(),
);
spicelib::MXV(
BASIS.subarray([1, 1, 1]),
V2.as_slice(),
LMBMAJ.as_slice_mut(),
);
spicelib::MXV(
BASIS.subarray([1, 1, 1]),
V3.as_slice(),
LMBMIN.as_slice_mut(),
);
spicelib::VADD(CENTR1.as_slice(), LMBCTR.as_slice(), V1.as_slice_mut());
spicelib::VEQU(V1.as_slice(), LMBCTR.as_slice_mut());
//
// Construct the limb in the original frame.
//
spicelib::CGV2EL(
LMBCTR.as_slice(),
LMBMAJ.as_slice(),
LMBMIN.as_slice(),
LIMB.as_slice_mut(),
ctx,
)?;
//
// Determine the center of the second ellipsoid. This ellipsoid
// is centered on the ray from the view point through the center
// of the first ellipsoid.
//
// The second ellipsoid must be placed far enough from the first
// so that no overlap of the ellipsoids occurs.
//
DIST[1] = spicelib::VNORM(VPOFF.as_slice());
//
// Let UVPOFF be the unit vector pointing from the view point
// to the center of the first ellipsoid.
//
spicelib::VMINUS(VPOFF.as_slice(), UVPOFF.as_slice_mut());
spicelib::VHATIP(UVPOFF.as_slice_mut());
//
// Pick a random distance between the centers; the distance
// must be at least 1.25 * the sum of the maximum radii of
// the ellipsoids. Here 1.25 is an arbitrary factor "slightly"
// greater than 1.
//
RADSUM = (MAXRAD[1] + MAXRAD[2]);
CTRSEP = testutil::T_RANDD((1.25 * RADSUM), (100.0 * RADSUM), &mut SEED, ctx)?;
//
// The second center is placed at distance CTRSEP along
// the ray emanating from the first center in direction UVPOFF.
//
spicelib::VLCOM(
1.0,
CENTR1.as_slice(),
CTRSEP,
UVPOFF.as_slice(),
CENTR2.as_slice_mut(),
);
//
// Now make sure the second ellipsoid is occulted. We'll
// adjust its size if necessary.
//
// Find a lower bound on the angular radius, as seen from the
// view point, of the first ellipsoid.
//
MINANG[1] = spicelib::DASINE((MINRAD[1] / DIST[1]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Find the maximum angular radius of the second ellipsoid,
// based on its nominal radii.
//
DIST[2] = (DIST[1] + CTRSEP);
MAXANG[2] = spicelib::DASINE((MAXRAD[2] / DIST[2]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
MINANG[2] = 0.0;
// MINANG(2) = DASINE ( MINRAD(2)/DIST(2), 0.D0 )
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// If we can't guarantee the second ellipsoid is occulted based
// on its maximum angular radius, scale it down until it "fits."
//
if (MAXANG[2] >= MINANG[1]) {
//
// Find the limit on MAXRAD(2). We pick LIMIT so that
//
// ASIN ( LIMIT/DIST(2) ) < MINANG(1)
//
LIMIT = ((0.5 * DIST[2]) * f64::sin(MINANG[1]));
//
// Scale down the radii of the second ellipsoid.
//
spicelib::VSCLIP((LIMIT / MAXRAD[2]), R.subarray_mut([1, 2]));
MINRAD[2] = intrinsics::DMIN1(&[R[[1, 2]], R[[2, 2]], R[[3, 2]]]);
MAXRAD[2] = intrinsics::DMAX1(&[R[[1, 2]], R[[2, 2]], R[[3, 2]]]);
//
// We must re-create the second semi-axis matrix too.
//
for J in 1..=3 {
spicelib::VSCL(
R[[J, 2]],
BASIS.subarray([1, J, 2]),
SEMAX2.subarray_mut([1, J]),
);
}
}
//
// Sanity check: validate MAXANG(2).
//
MAXANG[2] = spicelib::DASINE((MAXRAD[2] / DIST[2]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSD(b"MAXANG(2)", MAXANG[2], b"<", MINANG[1], 0.0, OK, ctx)?;
//
// The second ellipsoid should be in total occultation
// by the first. Verify this.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial total occultation)",
CODE,
b"=",
TOTAL2,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial total occultation)",
CODE,
b"=",
TOTAL2,
0,
OK,
ctx,
)?;
//
// Repeat with arguments switched.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial total occ/switched)",
CODE,
b"=",
TOTAL1,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial total occ/switched)",
CODE,
b"=",
TOTAL1,
0,
OK,
ctx,
)?;
//
// Now we're going to displace the second ellipsoid in
// a direction orthogonal to the vector UVPOFF. We'll
// do this by selecting a rotation axis and rotating the
// vector from the viewpoint to the center of the second
// ellipsoid about this axis until we detect a change of
// occultation classification (from total to partial).
// We'll then make sure that both ZZOCCED and our alternative
// computation performed by T_OCCED agree that we have a
// transition at the same angle.
//
// We're now going to pick a random vector orthogonal to
// UVPOFF. First pick an orthogonal basis, with UVPOFF the
// first vector of the basis.
//
spicelib::FRAME(UVPOFF.as_slice_mut(), Y.as_slice_mut(), Z.as_slice_mut());
//
// Pick a random rotation angle; we'll rotate Y about X by
// this angle to create a rotation axis.
//
ANGLE = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
spicelib::VROTV(Y.as_slice(), UVPOFF.as_slice(), ANGLE, AXIS.as_slice_mut());
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// We're now going to bracket the rotation angle needed to
// find the occultation state transition from total to partial.
// If the vector from the view point to the center of the
// second ellipsoid intersects the limb of the first ellipsoid,
// we definitely have a partial occultation, so determine
// the angular displacement required to make this happen.
//
// Create the plane containing the second center and normal
// to the rotation axis.
//
spicelib::NVP2PL(AXIS.as_slice(), CENTR2.as_slice(), CHOP.as_slice_mut(), ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Chop the first limb with the plane.
//
spicelib::INELPL(
LIMB.as_slice(),
CHOP.as_slice(),
&mut NXPTS,
XPT1.as_slice_mut(),
XPT2.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// If we don't have two points of intersection, something's
// wrong.
//
testutil::CHCKSI(b"NXPTS", NXPTS, b"=", 2, 0, OK, ctx)?;
//
// Find the vector from the view point to the first
// intersection point XPT1; find the angular separation
// of this vector from UVPOFF.
//
spicelib::VSUB(XPT1.as_slice(), VIEWPT.as_slice(), VPXPT1.as_slice_mut());
XSEP = spicelib::VSEP(VPXPT1.as_slice(), UVPOFF.as_slice(), ctx);
//
// Determine the sign of the rotation angle by which
// we rotate UVPOFF to align it with VPXPT1.
//
spicelib::VROTV(
UVPOFF.as_slice(),
AXIS.as_slice(),
XSEP,
TSTVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (spicelib::VSEP(TSTVEC.as_slice(), VPXPT1.as_slice(), ctx) > ANGTOL) {
XSEP = -XSEP;
spicelib::VROTV(
UVPOFF.as_slice(),
AXIS.as_slice(),
XSEP,
TSTVEC.as_slice_mut(),
);
}
testutil::CHCKSD(
b"VSEP(TSTVEC, VPXPT1)",
spicelib::VSEP(TSTVEC.as_slice(), VPXPT1.as_slice(), ctx),
b"~",
0.0,
ANGTOL,
OK,
ctx,
)?;
//
// Time for another sanity check: rotate the vector from
// the viewpoint to the center of the second ellipsoid about
// AXIS by XSEP, then add this to the view point,
// yielding a new center vector for the second ellipsoid.
// verify that the ellipsoid is in partial occultation.
//
spicelib::VSUB(CENTR2.as_slice(), VIEWPT.as_slice(), VPCTR2.as_slice_mut());
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
XSEP,
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Sanity check: make sure RVEC points from the view point
// to XPT1.
//
testutil::CHCKSD(
b"VSEP(RVEC, VPXPT1)",
spicelib::VSEP(RVEC.as_slice(), VPXPT1.as_slice(), ctx),
b"~",
0.0,
ANGTOL,
OK,
ctx,
)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
// CALL VSUB ( NEWCTR, VIEWPT, TSTVEC )
// WRITE (*,*) 'VPXPT1 sep = ', VSEP ( TSTVEC, VPXPT1 )
// WRITE (*,*) 'VPCTR2 sep = ', VSEP ( TSTVEC, VPCTR2 )
//
// Check for partial occultation of the second ellipsoid.
//
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE, (initial partial occultation)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE, (initial partial occultation)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
//
// Repeat with arguments switched.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial partial occ/switched)",
CODE,
b"=",
TOTAL1,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial partial occ/switched)",
CODE,
b"=",
TOTAL1,
0,
OK,
ctx,
)?;
//
// We now know that a rotation of the vector from the
// view point to the center of the second ellipsoid about
// AXIS by an angle between 0 and XSEP radians should yield
// a state transition. Find the angle via binary search.
//
if (XSEP > 0.0) {
RSIGN = 1.0;
} else {
RSIGN = -1.0;
}
LOW = 0.0;
HIGH = f64::abs(XSEP);
DIFF = (HIGH - LOW);
NITR = 0;
while ((DIFF > CNVTOL) && *OK) {
NITR = (NITR + 1);
testutil::CHCKSI(b"NITR", NITR, b"<", MAXITR, 0, OK, ctx)?;
MIDPT = ((HIGH + LOW) / 2.0);
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * MIDPT),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (CODE == PARTL2) {
HIGH = MIDPT;
} else {
//
// The code had better be TOTAL2.
//
testutil::CHCKSI(b"(bisection) CODE", CODE, b"=", TOTAL2, 0, OK, ctx)?;
LOW = MIDPT;
}
DIFF = (HIGH - LOW);
}
//
// Now that we've dropped out of the loop, verify that T_OCCED
// says the occultation is total at rotation angle RSIGN*LOW and
// partial at rotation angle RSIGN*HIGH. We adjust each
// of these angles by ADJTOL to allow for differences in
// round-off between ZZOCCED and T_OCCED.
//
//
// Verify that when we switch the order of the ellipsoids,
// we see a transition from total occultation of ellipsoid 1
// to partial occultation of ellipsoid 1.
//
//
// Check for total occultation:
//
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * (LOW - ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(b"CODE from T_OCCED (total)", CODE, b"=", TOTAL2, 0, OK, ctx)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (total, args switched)",
CODE,
b"=",
TOTAL1,
0,
OK,
ctx,
)?;
//
// Check for partial occultation:
//
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * (HIGH + ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 0)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 0, args switched)",
CODE,
b"=",
PARTL1,
0,
OK,
ctx,
)?;
//
// --- Case: ------------------------------------------------------
//
fstr::assign(&mut TITLE, b"\"General\" case: search for transitions from partial occultation to no occultation, for ellipsoids of different shape, size and orientation. Loop iteration = #.");
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
//
// The next step is to test for transitions from partial
// occultation to no occultation.
//
// Let BIGSEP be a displacement angle large enough to guarantee
// that no occultation will be found.
//
BIGSEP = spicelib::PI(ctx);
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * BIGSEP),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(b"CODE", CODE, b"=", NOOCC, 0, OK, ctx)?;
//
// We now know that a rotation of the vector from the
// view point to the center of the second ellipsoid about
// AXIS by an angle between 0 and XSEP radians should yield
// a state transition. Find the angle via binary search.
//
LOW = f64::abs(XSEP);
HIGH = BIGSEP;
DIFF = (HIGH - LOW);
NITR = 0;
while ((DIFF > CNVTOL) && *OK) {
NITR = (NITR + 1);
testutil::CHCKSI(b"NITR", NITR, b"<", MAXITR, 0, OK, ctx)?;
MIDPT = ((HIGH + LOW) / 2.0);
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * MIDPT),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (CODE == NOOCC) {
HIGH = MIDPT;
} else {
//
// The code had better be PARTL2.
//
testutil::CHCKSI(b"(bisection) CODE", CODE, b"=", PARTL2, 0, OK, ctx)?;
LOW = MIDPT;
}
DIFF = (HIGH - LOW);
}
//
// Now that we've dropped out of the loop, verify that T_OCCED
// says the occultation is partial at rotation angle RSIGN*LOW and
// "none" at rotation angle RSIGN*HIGH. We adjust each
// of these angles by CNVTOL to allow for differences in
// round-off between ZZOCCED and T_OCCED.
//
//
// Check for partial occultation:
//
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * (LOW - ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 1)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
//
// Check for no occultation:
//
spicelib::VROTV(
VPCTR2.as_slice(),
AXIS.as_slice(),
(RSIGN * (HIGH + ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
NEWCTR.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(b"CODE from T_OCCED (none)", CODE, b"=", NOOCC, 0, OK, ctx)?;
}
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//
//
// Transit cases follow.
//
//
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//*****************************************************************
//
//
// The following tests are quite similar to the preceding ones,
// with the difference that now we're going to have the first
// ellipsoid start out in annular transit across the second one.
//
for I in 1..=NCASE2 {
// WRITE (*,*) '=========================='
//
// --- Case: ------------------------------------------------------
//
fstr::assign(&mut TITLE, b"\"General\" case: search for transitions from annular to partial transit for ellipsoids of different shape, size and orientation. Loop iteration = #.");
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
//
// Pick a scale factor; we'll scale all of the participating
// objects using this factor.
//
SCALE = f64::powf(10.0, testutil::T_RANDD(-10.0, 10.0, &mut SEED, ctx)?);
//
// Create random orientation matrices for both ellipsoids. We
// start with three Euler angles. Also pick random radii for
// the ellipsoids.
//
for J in 1..=2 {
ALPHA = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
BETA = testutil::T_RANDD(
-spicelib::HALFPI(ctx),
spicelib::HALFPI(ctx),
&mut SEED,
ctx,
)?;
GAMMA = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
spicelib::EUL2M(ALPHA, BETA, GAMMA, 1, 2, 3, RMAT.as_slice_mut(), ctx)?;
spicelib::XPOSE(RMAT.as_slice(), BASIS.subarray_mut([1, 1, J]));
//
// Pick unscaled radius values in the range 1:10 for the
// Jth ellipsoid.
//
R[[1, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
R[[2, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
R[[3, J]] = testutil::T_RANDD(1.0, 100.0, &mut SEED, ctx)?;
//
// Scale the radii using our global scale factor.
//
spicelib::VSCLIP(SCALE, R.subarray_mut([1, J]));
//
// Save the minimum and maximum radii of each ellipsoid.
//
MINRAD[J] = intrinsics::DMIN1(&[R[[1, J]], R[[2, J]], R[[3, J]]]);
MAXRAD[J] = intrinsics::DMAX1(&[R[[1, J]], R[[2, J]], R[[3, J]]]);
// WRITE (*,*) 'MINRAD, MAXRAD = ', MINRAD(J), MAXRAD(J)
//
// Create the Jth semi-axis matrix by scaling the column
// vectors of RMAT.
//
for K in 1..=3 {
if (J == 1) {
spicelib::VSCL(
R[[K, J]],
BASIS.subarray([1, K, 1]),
SEMAX1.subarray_mut([1, K]),
);
} else {
spicelib::VSCL(
R[[K, J]],
BASIS.subarray([1, K, 2]),
SEMAX2.subarray_mut([1, K]),
);
}
}
}
//
// Pick a center for the first ellipsoid.
//
for J in 1..=3 {
CENTR1[J] = (SCALE * testutil::T_RANDD(-1000.0, 1000.0, &mut SEED, ctx)?);
}
//
// Pick a random viewing point. Start by picking longitude
// and latitude of a surface point on the first ellipsoid.
//
LON = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
LAT = testutil::T_RANDD(
-spicelib::HALFPI(ctx),
spicelib::HALFPI(ctx),
&mut SEED,
ctx,
)?;
spicelib::LATREC(1.0, LON, LAT, SRFDIR.as_slice_mut());
//
// Since the origin of this ray is the center of the
// ellipsoid, we don't have to check the found flag.
//
spicelib::SURFPT(
save.ORIGIN.as_slice(),
SRFDIR.as_slice(),
R[[1, 1]],
R[[2, 1]],
R[[3, 1]],
XPT.as_slice_mut(),
&mut FOUND,
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSL(b"FOUND", FOUND, true, OK, ctx)?;
//
// Pick a random altitude. Note the we move the observer
// farther away from the target than in the total occultation
// cases. For those, the minimum exponent was -1.
//
ALT = (SCALE * f64::powf(10.0, testutil::T_RANDD(1.0, 4.0, &mut SEED, ctx)?));
//
// Find the local outward unit surface normal, scale it by
// the altitude, and add it to XPT to obtain the view point.
//
spicelib::SURFNM(
R[[1, 1]],
R[[2, 1]],
R[[3, 1]],
XPT.as_slice(),
NORMAL.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VLCOM(
1.0,
XPT.as_slice(),
ALT,
NORMAL.as_slice(),
VIEWPT.as_slice_mut(),
);
//
// Find the offset from the viewing point to the center of the
// first ellipsoid.
//
spicelib::VSUB(VIEWPT.as_slice(), CENTR1.as_slice(), VPOFF.as_slice_mut());
DIST[1] = spicelib::VNORM(VPOFF.as_slice());
//
// Let UVPOFF be the unit vector pointing from the view point
// to the center of the first ellipsoid.
//
spicelib::VMINUS(VPOFF.as_slice(), UVPOFF.as_slice_mut());
spicelib::VHATIP(UVPOFF.as_slice_mut());
// Determine the center of the second ellipsoid. This ellipsoid
// is centered on the ray from the view point through the center
// of the first ellipsoid.
//
// The second ellipsoid must be placed far enough from the first
// so that no overlap of the ellipsoids occurs.
//
// Pick a random distance between the centers; the distance
// must be at least 1.25 * the sum of the maximum radii of
// the ellipsoids. Here 1.25 is an arbitrary factor "slightly"
// larger than 1.
//
RADSUM = (MAXRAD[1] + MAXRAD[2]);
CTRSEP = testutil::T_RANDD((1.25 * RADSUM), (100.0 * RADSUM), &mut SEED, ctx)?;
//
// The second center is placed at distance CTRSEP along
// the ray emanating from the first center in direction UVPOFF.
//
spicelib::VLCOM(
1.0,
CENTR1.as_slice(),
CTRSEP,
UVPOFF.as_slice(),
CENTR2.as_slice_mut(),
);
//
// Now make sure the second ellipsoid is in annular occultation
// by the first. We'll adjust the size of the first
// ellipsoid if necessary.
//
// Find a upper bound on the angular radius, as seen from the
// view point, of the first ellipsoid.
//
MAXANG[1] = spicelib::DASINE((MAXRAD[1] / DIST[1]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Find the minimum angular radius of the second ellipsoid,
// based on its nominal radii.
//
DIST[2] = (DIST[1] + CTRSEP);
MAXANG[2] = 0.0;
// MAXANG(2) = DASINE ( MAXRAD(2)/DIST(2), 0.D0 )
// CALL CHCKXC ( .FALSE., ' ', OK )
MINANG[1] = 0.0;
MINANG[2] = spicelib::DASINE((MINRAD[2] / DIST[2]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// If we can't guarantee the second ellipsoid is in annular
// occultation by the first, based on the second ellipsoid's
// minimum angular radius, shrink the first ellipsoid until this
// condition is met.
//
if (MINANG[2] <= MAXANG[1]) {
//
// Find the limit on MAXRAD(1). We pick LIMIT so that
//
// ASIN ( LIMIT/DIST(1) ) = MINANG(2)
//
LIMIT = (DIST[1] * f64::sin(MINANG[2]));
//
// Scale down the radii of the first ellipsoid. Use the
// arbitrary safety factor 0.75.
//
spicelib::VSCLIP(((0.75 * LIMIT) / MAXRAD[1]), R.subarray_mut([1, 1]));
MINRAD[1] = intrinsics::DMIN1(&[R[[1, 1]], R[[2, 1]], R[[3, 1]]]);
MAXRAD[1] = intrinsics::DMAX1(&[R[[1, 1]], R[[2, 1]], R[[3, 1]]]);
//
// We must re-create the first semi-axis matrix too.
//
for J in 1..=3 {
spicelib::VSCL(
R[[J, 1]],
BASIS.subarray([1, J, 1]),
SEMAX1.subarray_mut([1, J]),
);
}
}
//
// Sanity check: validate MAXANG(1).
//
MAXANG[1] = spicelib::DASINE((MAXRAD[1] / DIST[1]), 0.0, ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSD(b"MAXANG(1)", MAXANG[1], b"<", MINANG[2], 0.0, OK, ctx)?;
//
//
// We want to find the limb of the *second* ellipsoid as seen
// from the viewing point.
//
// Express the viewing point as an offset from the center
// of the first ellipsoid.
//
spicelib::VSUB(VIEWPT.as_slice(), CENTR2.as_slice(), VPOFF2.as_slice_mut());
//
// Transform the viewing point into the principal axis frame
// of the second ellipsoid.
//
spicelib::MTXV(
BASIS.subarray([1, 1, 2]),
VPOFF2.as_slice(),
LVIEW.as_slice_mut(),
);
//
// Find the limb of the second ellipsoid. Rotate the limb back to
// the original reference frame and shift the limb center to
// reflect the offset of the second ellipsoid's center from the
// origin.
//
spicelib::EDLIMB(
R[[1, 2]],
R[[2, 2]],
R[[3, 2]],
LVIEW.as_slice(),
XLIMB.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::EL2CGV(
XLIMB.as_slice(),
V1.as_slice_mut(),
V2.as_slice_mut(),
V3.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::MXV(
BASIS.subarray([1, 1, 2]),
V1.as_slice(),
LMBCTR.as_slice_mut(),
);
spicelib::MXV(
BASIS.subarray([1, 1, 2]),
V2.as_slice(),
LMBMAJ.as_slice_mut(),
);
spicelib::MXV(
BASIS.subarray([1, 1, 2]),
V3.as_slice(),
LMBMIN.as_slice_mut(),
);
spicelib::VADD(CENTR2.as_slice(), LMBCTR.as_slice(), V1.as_slice_mut());
spicelib::VEQU(V1.as_slice(), LMBCTR.as_slice_mut());
//
// Construct the limb of the second ellipsoid
// in the original frame.
//
spicelib::CGV2EL(
LMBCTR.as_slice(),
LMBMAJ.as_slice(),
LMBMIN.as_slice(),
LIMB.as_slice_mut(),
ctx,
)?;
//
// The second ellipsoid should be in annular occultation
// by the first. Verify this.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial annular occultation)",
CODE,
b"=",
ANNLR2,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial annular occultation)",
CODE,
b"=",
ANNLR2,
0,
OK,
ctx,
)?;
//
// Repeat with arguments switched.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial annular occ/switched)",
CODE,
b"=",
ANNLR1,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
CENTR1.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial annular occ/switched)",
CODE,
b"=",
ANNLR1,
0,
OK,
ctx,
)?;
//
// Now we're going to displace the first ellipsoid in
// a direction orthogonal to the vector UVPOFF. We'll
// do this by selecting a rotation axis and rotating the
// vector from the viewpoint to the center of the first
// ellipsoid about this axis until we detect a change of
// transit classification (from annular to partial).
// We'll then make sure that both ZZOCCED and our alternative
// computation performed by T_OCCED agree that we have a
// transition at the same angle.
//
// We're now going to pick a random vector orthogonal to
// UVPOFF. First pick an orthogonal basis, with UVPOFF the
// first vector of the basis.
//
spicelib::FRAME(UVPOFF.as_slice_mut(), Y.as_slice_mut(), Z.as_slice_mut());
//
// Pick a random rotation angle; we'll rotate Y about X by
// this angle to create a rotation axis.
//
ANGLE = testutil::T_RANDD(-spicelib::PI(ctx), spicelib::PI(ctx), &mut SEED, ctx)?;
spicelib::VROTV(Y.as_slice(), UVPOFF.as_slice(), ANGLE, AXIS.as_slice_mut());
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// We're now going to bracket the rotation angle needed to find
// the transit state transition from annular to partial. If
// the vector from the view point to the center of the *first*
// ellipsoid intersects the limb of the *second* ellipsoid, we
// definitely have a partial transit, so determine the
// angular displacement required to make this happen.
//
// Create the plane containing the second center and normal
// to the rotation axis.
//
spicelib::NVP2PL(AXIS.as_slice(), CENTR2.as_slice(), CHOP.as_slice_mut(), ctx)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Chop the second limb with the plane.
//
spicelib::INELPL(
LIMB.as_slice(),
CHOP.as_slice(),
&mut NXPTS,
XPT1.as_slice_mut(),
XPT2.as_slice_mut(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// If we don't have two points of intersection, something's
// wrong.
//
testutil::CHCKSI(b"NXPTS", NXPTS, b"=", 2, 0, OK, ctx)?;
//
// Find the vector from the view point to the first
// intersection point XPT1; find the angular separation
// of this vector from UVPOFF.
//
spicelib::VSUB(XPT1.as_slice(), VIEWPT.as_slice(), VPXPT1.as_slice_mut());
XSEP = spicelib::VSEP(VPXPT1.as_slice(), UVPOFF.as_slice(), ctx);
//
// Determine the sign of the rotation angle by which
// we rotate UVPOFF to align it with VPXPT1.
//
spicelib::VROTV(
UVPOFF.as_slice(),
AXIS.as_slice(),
XSEP,
TSTVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (spicelib::VSEP(TSTVEC.as_slice(), VPXPT1.as_slice(), ctx) > ANGTOL) {
XSEP = -XSEP;
spicelib::VROTV(
UVPOFF.as_slice(),
AXIS.as_slice(),
XSEP,
TSTVEC.as_slice_mut(),
);
}
testutil::CHCKSD(
b"VSEP(TSTVEC, VPXPT1)",
spicelib::VSEP(TSTVEC.as_slice(), VPXPT1.as_slice(), ctx),
b"~",
0.0,
ANGTOL,
OK,
ctx,
)?;
//
// Time for another sanity check: rotate the vector from
// the viewpoint to the center of the first ellipsoid about
// AXIS by XSEP, then add this to the view point,
// yielding a new center vector for the first ellipsoid.
// Verify that the first ellipsoid is in partial transit.
//
spicelib::VSUB(CENTR1.as_slice(), VIEWPT.as_slice(), VPCTR1.as_slice_mut());
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
XSEP,
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Sanity check: make sure RVEC points from the view point
// to XPT1.
//
testutil::CHCKSD(
b"VSEP(RVEC, VPXPT1)",
spicelib::VSEP(RVEC.as_slice(), VPXPT1.as_slice(), ctx),
b"~",
0.0,
ANGTOL,
OK,
ctx,
)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
// CALL VSUB ( NEWCTR, VIEWPT, TSTVEC )
// WRITE (*,*) 'VPXPT1 sep = ', VSEP ( TSTVEC, VPXPT1 )
// WRITE (*,*) 'VPCTR2 sep = ', VSEP ( TSTVEC, VPCTR2 )
//
// Check for partial transit of the first ellipsoid across
// the second.
//
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE, (initial partial transit)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE, (initial partial transit)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
//
// Repeat with arguments switched.
//
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"ZZOCCED CODE (initial partial occ/switched)",
CODE,
b"=",
PARTL1,
0,
OK,
ctx,
)?;
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"T_OCCED CODE (initial partial occ/switched)",
CODE,
b"=",
PARTL1,
0,
OK,
ctx,
)?;
//
// We now know that a rotation of the vector from the
// view point to the center of the second ellipsoid about
// AXIS by an angle between 0 and XSEP radians should yield
// a state transition. Find the angle via binary search.
//
if (XSEP > 0.0) {
RSIGN = 1.0;
} else {
RSIGN = -1.0;
}
LOW = 0.0;
HIGH = f64::abs(XSEP);
DIFF = (HIGH - LOW);
NITR = 0;
while ((DIFF > CNVTOL) && *OK) {
NITR = (NITR + 1);
testutil::CHCKSI(b"NITR", NITR, b"<", MAXITR, 0, OK, ctx)?;
MIDPT = ((HIGH + LOW) / 2.0);
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * MIDPT),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
//XXX
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (CODE == PARTL2) {
HIGH = MIDPT;
} else {
//
// The code had better be ANNLR2.
//
testutil::CHCKSI(b"(bisection) CODE", CODE, b"=", ANNLR2, 0, OK, ctx)?;
LOW = MIDPT;
}
DIFF = (HIGH - LOW);
}
//
// Now that we've dropped out of the loop, verify that T_OCCED
// says the transit is total at rotation angle RSIGN*LOW and
// partial at rotation angle RSIGN*HIGH. We adjust each
// of these angles by ADJTOL to allow for differences in
// round-off between ZZOCCED and T_OCCED.
//
//
// Verify that when we switch the order of the ellipsoids,
// we see a transition from total transit of ellipsoid 1
// to partial transit of ellipsoid 1.
//
//
// Check for annular transit:
//
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * (LOW - ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (annular)",
CODE,
b"=",
ANNLR2,
0,
OK,
ctx,
)?;
//
// IF ( .NOT. OK ) THEN
//
// WRITE (*,*) '============='
// WRITE (*,*) 'XSEP = ', XSEP
// WRITE (*,*) 'MINANG: ', MINANG
// WRITE (*,*) 'MAXANG: ', MAXANG
// WRITE (*,*) 'LIMB = ', LIMB
// WRITE (*,*) 'VIEWPT = ', VIEWPT
// WRITE (*,*) 'LOW, HIGH = ', LOW, HIGH
// END IF
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (annular, args switched)",
CODE,
b"=",
ANNLR1,
0,
OK,
ctx,
)?;
//
// Check for partial transit:
//
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * (HIGH + ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 0)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
//
// IF ( .NOT. OK ) THEN
//
// WRITE (*,*) '============='
// WRITE (*,*) 'XSEP = ', XSEP
// WRITE (*,*) 'MINANG: ', MINANG
// WRITE (*,*) 'MAXANG: ', MAXANG
// WRITE (*,*) 'LIMB = ', LIMB
// WRITE (*,*) 'VIEWPT = ', VIEWPT
// WRITE (*,*) 'LOW, HIGH = ', LOW, HIGH
// END IF
//
CODE = T_OCCED(
VIEWPT.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 0, args switched)",
CODE,
b"=",
PARTL1,
0,
OK,
ctx,
)?;
//
// --- Case: ------------------------------------------------------
//
fstr::assign(&mut TITLE, b"\"General\" case: search for transitions from partial transit to no occultation, for ellipsoids of different shape, size and orientation. Loop iteration = #.");
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
//
// The next step is to test for transitions from partial
// transit to no occultation.
//
// Let BIGSEP be a displacement angle large enough to guarantee
// that no occultation will be found.
//
BIGSEP = spicelib::PI(ctx);
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * BIGSEP),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(b"CODE", CODE, b"=", NOOCC, 0, OK, ctx)?;
//
// We now know that a rotation of the vector from the
// view point to the center of the first ellipsoid about
// AXIS by an angle between 0 and XSEP radians should yield
// a state transition. Find the angle via binary search.
//
LOW = f64::abs(XSEP);
HIGH = BIGSEP;
DIFF = (HIGH - LOW);
NITR = 0;
while ((DIFF > CNVTOL) && *OK) {
NITR = (NITR + 1);
testutil::CHCKSI(b"NITR", NITR, b"<", MAXITR, 0, OK, ctx)?;
MIDPT = ((HIGH + LOW) / 2.0);
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * MIDPT),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = spicelib::ZZOCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
if (CODE == NOOCC) {
HIGH = MIDPT;
} else {
//
// The code had better be PARTL2.
//
testutil::CHCKSI(b"(bisection) CODE", CODE, b"=", PARTL2, 0, OK, ctx)?;
LOW = MIDPT;
}
DIFF = (HIGH - LOW);
}
//
// Now that we've dropped out of the loop, verify that T_OCCED
// says the transit is partial at rotation angle RSIGN*LOW and
// "none" at rotation angle RSIGN*HIGH. We adjust each
// of these angles by CNVTOL to allow for differences in
// round-off between ZZOCCED and T_OCCED.
//
//
// Check for partial transit:
//
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * (LOW - ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(
b"CODE from T_OCCED (partial 1)",
CODE,
b"=",
PARTL2,
0,
OK,
ctx,
)?;
//
// Check for no occultation:
//
spicelib::VROTV(
VPCTR1.as_slice(),
AXIS.as_slice(),
(RSIGN * (HIGH + ADJTOL)),
RVEC.as_slice_mut(),
);
testutil::CHCKXC(false, b" ", OK, ctx)?;
spicelib::VADD(VIEWPT.as_slice(), RVEC.as_slice(), NEWCTR.as_slice_mut());
CODE = T_OCCED(
VIEWPT.as_slice(),
NEWCTR.as_slice(),
SEMAX1.as_slice(),
CENTR2.as_slice(),
SEMAX2.as_slice(),
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
testutil::CHCKSI(b"CODE from T_OCCED (none)", CODE, b"=", NOOCC, 0, OK, ctx)?;
}
testutil::T_SUCCESS(OK, ctx);
Ok(())
}