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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const DSKSHP: i32 = 2;
const ELLSHP: i32 = 1;
const MTHLEN: i32 = 500;
const SUBLEN: i32 = 20;
const CVTLEN: i32 = 20;
const TANGNT: i32 = 1;
const GUIDED: i32 = 2;
const TMTLEN: i32 = 20;
const LMBCRV: i32 = 0;
const UMBRAL: i32 = 1;
const PNMBRL: i32 = 2;
const ACLLEN: i32 = 25;
const CTRCOR: i32 = 1;
const ELLCOR: i32 = 2;
struct SaveVars {
SVAXIS: StackArray<f64, 3>,
SVET: f64,
SVIRAD: f64,
SVNRML: StackArray<f64, 3>,
SVVRTX: StackArray<f64, 3>,
SVCURV: i32,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SVAXIS = StackArray::<f64, 3>::new(1..=3);
let mut SVET: f64 = 0.0;
let mut SVIRAD: f64 = 0.0;
let mut SVNRML = StackArray::<f64, 3>::new(1..=3);
let mut SVVRTX = StackArray::<f64, 3>::new(1..=3);
let mut SVCURV: i32 = 0;
Self {
SVAXIS,
SVET,
SVIRAD,
SVNRML,
SVVRTX,
SVCURV,
}
}
}
//$Procedure ZZTANUTL ( DSK, tangent ray utilities )
pub fn ZZTANUTL(
CURVE: i32,
SRCRAD: f64,
SHAPE: i32,
TRGCDE: i32,
NSURF: i32,
SRFLST: &[i32],
FIXFID: i32,
ET: f64,
PLNVEC: &[f64],
AXIS: &[f64],
ANGLE: f64,
OCULTD: bool,
POINT: &[f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
//
// SPICELIB functions
//
//
// Local variables
//
//
// Saved variables
//
CHKIN(b"ZZTANUTL", ctx)?;
SIGERR(b"SPICE(BOGUSENTRY)", ctx)?;
CHKOUT(b"ZZTANUTL", ctx)?;
Ok(())
}
//$Procedure ZZTANINI ( DSK, tangent utility initialization )
pub fn ZZTANINI(
CURVE: i32,
SRCRAD: f64,
SHAPE: i32,
TRGCDE: i32,
NSURF: i32,
SRFLST: &[i32],
FIXFID: i32,
ET: f64,
PLNVEC: &[f64],
AXIS: &[f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let SRFLST = DummyArray::new(SRFLST, 1..);
let PLNVEC = DummyArray::new(PLNVEC, 1..=3);
let AXIS = DummyArray::new(AXIS, 1..=3);
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZTANINI", ctx)?;
//
// Check for zero vectors on input.
//
if VZERO(AXIS.as_slice()) {
SETMSG(b"Input axis vector is the zero vector.", ctx);
SIGERR(b"SPICE(ZEROVECTOR)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
if VZERO(PLNVEC.as_slice()) {
SETMSG(b"Input reference vector is the zero vector.", ctx);
SIGERR(b"SPICE(ZEROVECTOR)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
//
// Save the curve type.
//
if (((CURVE != LMBCRV) && (CURVE != UMBRAL)) && (CURVE != PNMBRL)) {
SETMSG(b"Curve type code # was not recognized.", ctx);
ERRINT(b"#", CURVE, ctx);
SIGERR(b"SPICE(BADCURVETYPE)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
save.SVCURV = CURVE;
//
// Save the illumination source radius.
//
if ((CURVE == UMBRAL) || (CURVE == PNMBRL)) {
if (SRCRAD <= 0.0) {
SETMSG(b"The source radius was #. The radius must be positive for a terminator computation.", ctx);
ERRDP(b"#", SRCRAD, ctx);
SIGERR(b"SPICE(BADSOURCERADIUS)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
}
save.SVIRAD = SRCRAD;
//
// Compute a normal vector to the plane defined by
// AXIS and PLNVEC. The direction of positive rotation
// about the normal is from AXIS toward PLNVEC.
//
VCRSS(
AXIS.as_slice(),
PLNVEC.as_slice(),
save.SVNRML.as_slice_mut(),
);
if VZERO(save.SVNRML.as_slice()) {
SETMSG(
b"Input reference vector and axis vector are linearly dependent.",
ctx,
);
SIGERR(b"SPICE(DEGENERATECASE)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
//
// Scale the normal vector to unit length.
//
VHATIP(save.SVNRML.as_slice_mut());
//
// Save a unit-length copy of the input axis.
// Save the original axis as the ray's vertex; this
// will be used directly in the limb computation and
// will be used, after addition of an offset, in the
// terminator computations. Save the evaluation epoch.
//
VEQU(AXIS.as_slice(), save.SVVRTX.as_slice_mut());
VHAT(AXIS.as_slice(), save.SVAXIS.as_slice_mut());
save.SVET = ET;
//
// Prepare the DSK SINCPT utilities for a computation with
// the input surface set.
//
if (SHAPE == ELLSHP) {
//
// This is the ellipsoid case.
//
ZZSUELIN(TRGCDE, ctx)?;
} else if (SHAPE == DSKSHP) {
//
// This is the DSK case.
//
ZZSUDSKI(TRGCDE, NSURF, SRFLST.as_slice(), FIXFID, ctx)?;
} else {
SETMSG(b"Target shape code # was not recognized.", ctx);
ERRINT(b"#", SHAPE, ctx);
SIGERR(b"SPICE(BADSHAPE)", ctx)?;
CHKOUT(b"ZZTANINI", ctx)?;
return Ok(());
}
CHKOUT(b"ZZTANINI", ctx)?;
Ok(())
}
//$Procedure ZZTANSTA ( DSK, tangent ray state )
pub fn ZZTANSTA(
ANGLE: f64,
OCULTD: &mut bool,
POINT: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut POINT = DummyArrayMut::new(POINT, 1..=3);
let mut APEX = StackArray::<f64, 3>::new(1..=3);
let mut RAYDIR = StackArray::<f64, 3>::new(1..=3);
let mut VRTOFF = StackArray::<f64, 3>::new(1..=3);
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZTANSTA", ctx)?;
if (save.SVCURV == LMBCRV) {
//
// This is the limb case.
//
// We'll rotate SVAXIS by ANGLE to achieve the desired result.
//
VROTV(
save.SVAXIS.as_slice(),
save.SVNRML.as_slice(),
ANGLE,
RAYDIR.as_slice_mut(),
);
ZZRAYSFX(
save.SVVRTX.as_slice(),
RAYDIR.as_slice(),
save.SVET,
POINT.as_slice_mut(),
OCULTD,
ctx,
)?;
} else if (save.SVCURV == UMBRAL) {
//
// This is the umbral terminator case.
//
// Produce the ray's direction vector by rotating
// the axis about the cutting half-plane normal by
// the input angle.
//
VROTV(
save.SVAXIS.as_slice(),
save.SVNRML.as_slice(),
ANGLE,
RAYDIR.as_slice_mut(),
);
//
// Produce the offset of the ray's vertex from the
// center of the source by rotating the axis
// vector by ANGLE-pi/2 radians. The length
// of the vector must be SVIRAD. The saved axis
// has unit length.
//
VROTV(
save.SVAXIS.as_slice(),
save.SVNRML.as_slice(),
(ANGLE - (PI(ctx) / 2 as f64)),
VRTOFF.as_slice_mut(),
);
VSCLIP(save.SVIRAD, VRTOFF.as_slice_mut());
VADD(
save.SVVRTX.as_slice(),
VRTOFF.as_slice(),
APEX.as_slice_mut(),
);
ZZRAYSFX(
APEX.as_slice(),
RAYDIR.as_slice(),
save.SVET,
POINT.as_slice_mut(),
OCULTD,
ctx,
)?;
} else if (save.SVCURV == PNMBRL) {
//
// This is the penumbral terminator case.
//
// Produce the ray's direction vector by rotating
// the axis about the cutting half-plane normal by
// the *negative* of the input angle.
//
VROTV(
save.SVAXIS.as_slice(),
save.SVNRML.as_slice(),
-ANGLE,
RAYDIR.as_slice_mut(),
);
//
// Produce the ray's vertex by rotating the axis
// vector about the normal, *not its negative,*
// by 3*pi/2 - ANGLE radians. The length of the vector
// must be SRCRAD. The saved axis has unit length.
//
VROTV(
save.SVAXIS.as_slice(),
save.SVNRML.as_slice(),
((1.5 * PI(ctx)) - ANGLE),
VRTOFF.as_slice_mut(),
);
VSCLIP(save.SVIRAD, VRTOFF.as_slice_mut());
VADD(
save.SVVRTX.as_slice(),
VRTOFF.as_slice(),
APEX.as_slice_mut(),
);
ZZRAYSFX(
APEX.as_slice(),
RAYDIR.as_slice(),
save.SVET,
POINT.as_slice_mut(),
OCULTD,
ctx,
)?;
} else {
//
// This case should have been ruled out by a check in
// ZZTANINI. Check again anyway.
//
SETMSG(b"Bad curve type code #.", ctx);
ERRINT(b"#", save.SVCURV, ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZTANSTA", ctx)?;
return Ok(());
}
CHKOUT(b"ZZTANSTA", ctx)?;
Ok(())
}