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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const TIGHT: f64 = 0.00000000000001;
const MSGLEN: i32 = 400;
const NSIMPL: i32 = 3;
const NRANDM: i32 = 5000;
struct SaveVars {
SMPA: StackArray<f64, 3>,
SMPB: StackArray<f64, 3>,
SMPC: StackArray<f64, 3>,
SMPDIR: StackArray2D<f64, 9>,
SMPPT: StackArray2D<f64, 9>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SMPA = StackArray::<f64, 3>::new(1..=NSIMPL);
let mut SMPB = StackArray::<f64, 3>::new(1..=NSIMPL);
let mut SMPC = StackArray::<f64, 3>::new(1..=NSIMPL);
let mut SMPDIR = StackArray2D::<f64, 9>::new(1..=3, 1..=NSIMPL);
let mut SMPPT = StackArray2D::<f64, 9>::new(1..=3, 1..=NSIMPL);
{
use f2rust_std::data::Val;
let mut clist = [Val::D(10.0), Val::D(200.0), Val::D(3000.0)].into_iter();
SMPA[1] = clist.next().unwrap().into_f64();
SMPB[1] = clist.next().unwrap().into_f64();
SMPC[1] = clist.next().unwrap().into_f64();
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(20.0), Val::D(0.0), Val::D(0.0)].into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPPT[[I, 1]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(0.0), Val::D(-1.0)].into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPDIR[[I, 1]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [
Val::D(3000000000000000000000000000000.0),
Val::D(3000000000000000000000000000000.0),
Val::D(3000000000000000000000000000000.0),
]
.into_iter();
SMPA[2] = clist.next().unwrap().into_f64();
SMPB[2] = clist.next().unwrap().into_f64();
SMPC[2] = clist.next().unwrap().into_f64();
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [
Val::D(4000000000000000000000000000000.0),
Val::D(0.0),
Val::D(4000000000000000000000000000000.0),
]
.into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPPT[[I, 2]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(-1.0), Val::D(0.0), Val::D(2.0)].into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPDIR[[I, 2]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.01), Val::D(0.01), Val::D(0.005)].into_iter();
SMPA[3] = clist.next().unwrap().into_f64();
SMPB[3] = clist.next().unwrap().into_f64();
SMPC[3] = clist.next().unwrap().into_f64();
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(1.0), Val::D(1.0)].into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPPT[[I, 3]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
{
use f2rust_std::data::Val;
let mut clist = [Val::D(0.0), Val::D(-2.0), Val::D(-1.0)].into_iter();
for I in intrinsics::range(1, 3, 1) {
SMPDIR[[I, 3]] = clist.next().unwrap().into_f64();
}
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self {
SMPA,
SMPB,
SMPC,
SMPDIR,
SMPPT,
}
}
}
//$Procedure F_NPEDLN ( NPEDLN tests )
pub fn F_NPEDLN(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' '; MSGLEN as usize];
let mut A: f64 = 0.0;
let mut B: f64 = 0.0;
let mut C: f64 = 0.0;
let mut DIST: f64 = 0.0;
let mut LINEDR = StackArray::<f64, 3>::new(1..=3);
let mut LINEPT = StackArray::<f64, 3>::new(1..=3);
let mut NEGDIR = StackArray::<f64, 3>::new(1..=3);
let mut PNEAR = StackArray::<f64, 3>::new(1..=3);
let mut SFACTR: f64 = 0.0;
let mut XPT = StackArray::<f64, 3>::new(1..=3);
let mut SEED: i32 = 0;
let mut FOUND: bool = false;
let mut FOUND2: bool = false;
let mut ORTHOG: bool = false;
let mut VALPT: bool = false;
//
// Other functions
//
//
// Local Parameters
//
// INTEGER NEASY
// PARAMETER ( NEASY = 3 )
// INTEGER NUMSCL
// PARAMETER ( NUMSCL = 5 )
//
// Local Variables
//
//
// Saved values
//
//
// Initial values
//
//
// The simple test cases.
//
//
// In this test family, we encapsulate some of the geometric
// tests within functions defined in this file. The function
//
// T_ISEDPT
//
// tests a point is on a specified ellipsoid:
//
// - A point P = (x,y,z) is "on" the ellipsoid with semi-axis
// lengths a, b, c if the "level surface parameter"
//
// lambda = x**2/a**2 + y**2/b**2 + z**2/c**2
//
// is sufficiently close to 1.
//
//
// The function
//
// T_ISNPLN
//
// test whether the near point found by NPEDLN has the property
// that the outward normal at the near point can be extended to
// intersect the input line at right angles.
//
// T_ISNPLN also checks the distance of the near point from the line:
// the distance is checked against the value obtained from NPLNPT.
//
//
//
// Open the test family.
//
testutil::TOPEN(b"F_NPEDLN", ctx)?;
//
// Run some simple tests where the correct results can be
// determined by inspection.
//
for I in 1..=NSIMPL {
//
// --- Case: ------------------------------------------------------
//
fstr::assign(&mut TITLE, b"NPEDLN simple case #");
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
spicelib::NPEDLN(
save.SMPA[I],
save.SMPB[I],
save.SMPC[I],
save.SMPPT.subarray([1, I]),
save.SMPDIR.subarray([1, I]),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Make sure the intersection ellipse we found is contained in
// both the plane and the surface of the ellipsoid.
//
VALPT = T_ISEDPT(
PNEAR.as_slice(),
save.SMPA[I],
save.SMPB[I],
save.SMPC[I],
OK,
ctx,
)?;
testutil::CHCKSL(b"Is near point on surface?", VALPT, true, OK, ctx)?;
ORTHOG = T_ISNPLN(
save.SMPA[I],
save.SMPB[I],
save.SMPC[I],
save.SMPPT.subarray([1, I]),
save.SMPDIR.subarray([1, I]),
PNEAR.as_slice(),
DIST,
OK,
ctx,
)?;
testutil::CHCKSL(
b"Does extension of outward normal hit line orthogonally? Is distance correct?",
ORTHOG,
true,
OK,
ctx,
)?;
}
//
// Now for some more difficult cases. We'll generate the ellipsoids
// and lines using random numbers. There are ten components to
// generate:
//
// - random line direction vectors
// - random line points
// - random ellipsoid axes
// - random scale factors for the ellipsoid and plane; these are
// used to create a wide range of scales
//
SEED = -1;
for I in 1..=NRANDM {
//
// --- Case: ------------------------------------------------------
//
//
// Get a scale factor.
//
SFACTR = f64::powf(10.0, testutil::T_RANDD(-290.0, 290.0, &mut SEED, ctx)?);
//
// Make up ellipsoid axes and plane constant.
//
A = (SFACTR * testutil::T_RANDD(1.0, 2.0, &mut SEED, ctx)?);
B = (SFACTR * testutil::T_RANDD(1.0, 2.0, &mut SEED, ctx)?);
C = (SFACTR * testutil::T_RANDD(1.0, 2.0, &mut SEED, ctx)?);
//
// We gotta have a line direction vector.
//
LINEDR[1] = (SFACTR * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
LINEDR[2] = (SFACTR * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
LINEDR[3] = (SFACTR * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
spicelib::VHATIP(LINEDR.as_slice_mut());
//
// We also need a point on the line. Scale the point up to
// increase the likelihood of a non-intercept case.
//
LINEPT[1] = (((10 as f64) * SFACTR) * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
LINEPT[2] = (((10 as f64) * SFACTR) * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
LINEPT[3] = (((10 as f64) * SFACTR) * testutil::T_RANDD(-1.0, 1.0, &mut SEED, ctx)?);
fstr::assign(
&mut TITLE,
b"NPEDLN Random case #. A, B, C = # # #; LINEDR = (#, #, #); LINEPT = (#, #, #)",
);
spicelib::REPMI(&TITLE.clone(), b"#", I, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", A, 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", B, 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", C, 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEDR[1], 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEDR[2], 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEDR[3], 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEPT[1], 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEPT[2], 14, &mut TITLE, ctx);
spicelib::REPMD(&TITLE.clone(), b"#", LINEPT[3], 14, &mut TITLE, ctx);
testutil::TCASE(&TITLE, ctx)?;
//
// Cross our fingers and toes and let 'er rip.
//
spicelib::NPEDLN(
A,
B,
C,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(false, b" ", OK, ctx)?;
//
// Make sure the intersection ellipse we found is contained in
// both the plane and the surface of the ellipsoid.
//
VALPT = T_ISEDPT(PNEAR.as_slice(), A, B, C, OK, ctx)?;
testutil::CHCKSL(b"Is near point on surface?", VALPT, true, OK, ctx)?;
//
// Check for surface intercept.
//
spicelib::SURFPT(
LINEPT.as_slice(),
LINEDR.as_slice(),
A,
B,
C,
XPT.as_slice_mut(),
&mut FOUND,
ctx,
)?;
if !FOUND {
//
// See whether the opposite ray hits the ellipsoid.
//
spicelib::VMINUS(LINEDR.as_slice(), NEGDIR.as_slice_mut());
spicelib::SURFPT(
LINEPT.as_slice(),
NEGDIR.as_slice(),
A,
B,
C,
XPT.as_slice_mut(),
&mut FOUND2,
ctx,
)?;
}
//
// If we have an intersection case, test the near point
// and distance.
//
if (FOUND || FOUND2) {
testutil::CHCKAD(
b"PNEAR",
PNEAR.as_slice(),
b"~~/",
XPT.as_slice(),
3,
TIGHT,
OK,
ctx,
)?;
testutil::CHCKSD(b"DIST", DIST, b"=", 0.0, 0.0, OK, ctx)?;
} else {
//
// If we have a non-intersection case, test the solution
// for the orthogonality condition. Also check the distance
// of the near point from the line.
//
ORTHOG = T_ISNPLN(
A,
B,
C,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice(),
DIST,
OK,
ctx,
)?;
testutil::CHCKSL(
b"Does extension of outward normal hit line orthogonally? Is distance correct?",
ORTHOG,
true,
OK,
ctx,
)?;
}
}
//
// NPEDLN error cases:
//
//
// --- Case: ------------------------------------------------------
//
testutil::TCASE(b"NPEDLN: zero direction vector,", ctx)?;
spicelib::FILLD(10.0, 3, LINEPT.as_slice_mut());
spicelib::CLEARD(3, LINEDR.as_slice_mut());
spicelib::NPEDLN(
1.0,
1.0,
1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(ZEROVECTOR)", OK, ctx)?;
//
// --- Case: ------------------------------------------------------
//
testutil::TCASE(b"NPEDLN: ellipsoid has one zero-length axis.", ctx)?;
spicelib::FILLD(10.0, 3, LINEPT.as_slice_mut());
spicelib::FILLD(-1.0, 3, LINEDR.as_slice_mut());
spicelib::NPEDLN(
0.0,
1.0,
1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
spicelib::NPEDLN(
1.0,
0.0,
1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
spicelib::NPEDLN(
1.0,
1.0,
0.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
//
// --- Case: ------------------------------------------------------
//
testutil::TCASE(b"NPEDLN: ellipsoid has one negative-length axis.", ctx)?;
spicelib::NPEDLN(
-1.0,
1.0,
1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
spicelib::NPEDLN(
1.0,
-1.0,
1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
spicelib::NPEDLN(
1.0,
1.0,
-1.0,
LINEPT.as_slice(),
LINEDR.as_slice(),
PNEAR.as_slice_mut(),
&mut DIST,
ctx,
)?;
testutil::CHCKXC(true, b"SPICE(INVALIDAXISLENGTH)", OK, ctx)?;
//
// --- Case: ------------------------------------------------------
//
//
// This error may not be detected on some systems. We exclude
// it for now.
//CC CALL TCASE ( 'NPEDLN: axis length underflow after squaring.' )
//CC CALL NPEDLN ( 1.D255, 1.D0, 1.D0, LINEPT, LINEDR, PNEAR, DIST )
//CC CALL CHCKXC ( .TRUE., 'SPICE(DEGENERATECASE)', OK )
//CC CALL NPEDLN ( 1.D0, 1.D255, 1.D0, LINEPT, LINEDR, PNEAR, DIST )
//CC CALL CHCKXC ( .TRUE., 'SPICE(DEGENERATECASE)', OK )
//CC CALL NPEDLN ( 1.D0, 1.D0, 1.D255, LINEPT, LINEDR, PNEAR, DIST )
//CC CALL CHCKXC ( .TRUE., 'SPICE(DEGENERATECASE)', OK )
//
// Close out the test family.
//
testutil::T_SUCCESS(OK, ctx);
Ok(())
}