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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
pub const LT: i32 = -1;
pub const EQ: i32 = 0;
pub const GT: i32 = 1;
struct SaveVars {
APEX: StackArray<f64, 3>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut APEX = 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([]);
APEX.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_f64());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { APEX }
}
}
//$Procedure ZZPDCMPL (Planetodetic coordinates, compare latitudes )
pub fn ZZPDCMPL(
RE: f64,
F: f64,
P: &[f64],
LAT: f64,
REL: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let P = DummyArray::new(P, 1..=3);
let mut LON: f64 = 0.0;
let mut OFFPCL: f64 = 0.0;
let mut OFFSET = StackArray::<f64, 3>::new(1..=3);
let mut R: f64 = 0.0;
let mut RP: f64 = 0.0;
let mut XINCPT: f64 = 0.0;
let mut YINCPT: f64 = 0.0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZPDCMPL", ctx)?;
//
// Treat points on the Z axis as a special case. The
// computations performed in the general case may introduce
// round-off errors that will lead to false results for
// this case.
//
if ((P[1] == 0.0) && (P[2] == 0.0)) {
if (P[3] > 0.0) {
if (LAT == HALFPI(ctx)) {
*REL = EQ;
} else {
*REL = GT;
}
} else if (P[3] == 0.0) {
//
// We consider the latitude of P to be zero.
//
if (LAT > 0.0) {
*REL = LT;
} else if (LAT == 0.0) {
*REL = EQ;
} else {
*REL = GT;
}
} else {
//
// P(3) < 0.
//
if (LAT == -HALFPI(ctx)) {
*REL = EQ;
} else {
*REL = LT;
}
}
CHKOUT(b"ZZPDCMPL", ctx)?;
return Ok(());
}
//
// Latitude zero is a special case. The planetodetic latitude of the
// input point has the same sign as the Z component of the point.
//
RP = (RE * (1.0 - F));
//
// Get the y-intercept of the latitude cone for LAT. Note that a
// result is defined for LAT = +/- pi/2.
//
ZZELNAXX(RE, RP, LAT, &mut XINCPT, &mut YINCPT, ctx)?;
if FAILED(ctx) {
CHKOUT(b"ZZPDCMPL", ctx)?;
return Ok(());
}
//
// Ideally YINCPT is zero if and only if LAT is zero.
// We'll group these conditions together.
//
if ((LAT == 0.0) || (YINCPT == 0.0)) {
if (P[3] > 0.0) {
*REL = GT;
} else if (P[3] == 0.0) {
*REL = EQ;
} else {
*REL = LT;
}
CHKOUT(b"ZZPDCMPL", ctx)?;
return Ok(());
}
//
// This is the normal case.
//
// Find the offset of the point from the latitude cone's apex.
// Create a unit-length copy of the offset vector.
//
save.APEX[3] = YINCPT;
VSUB(P.as_slice(), save.APEX.as_slice(), OFFSET.as_slice_mut());
// We'll use the planetocentric [sic] latitude of the offset
// vector for comparison.
//
RECLAT(OFFSET.as_slice(), &mut R, &mut LON, &mut OFFPCL);
if (LAT > 0.0) {
if (YINCPT > 0 as f64) {
//
// This is the prolate case.
//
if (OFFPCL > LAT) {
*REL = GT;
} else if (OFFPCL == LAT) {
*REL = EQ;
} else {
*REL = LT;
}
} else {
//
// YINCPT = 0 was handled previously, so YINCPT < 0.
//
// This is the oblate case.
//
// In addition to the comparison of angles, we need to know
// the input point is above the X-Y plane in order for the
// GT or EQ relations to hold.
//
if (P[3] > 0.0) {
if (OFFPCL > LAT) {
*REL = GT;
} else if (OFFPCL == LAT) {
*REL = EQ;
} else {
*REL = LT;
}
} else {
//
// The input latitude is positive, while the point
// is on or below the X-Y plane.
//
*REL = LT;
}
}
} else {
//
// LAT < 0, since the case LAT = 0 has already been handled.
//
if (YINCPT < 0.0) {
//
// This is the prolate case.
//
if (OFFPCL > LAT) {
*REL = GT;
} else if (OFFPCL == LAT) {
*REL = EQ;
} else {
*REL = LT;
}
} else {
//
// YINCPT > 0, since the case YINCPT = 0 was handled
// previously.
//
// This is the oblate case.
//
if (P[3] < 0.0) {
if (OFFPCL > LAT) {
*REL = GT;
} else if (OFFPCL == LAT) {
*REL = EQ;
} else {
*REL = LT;
}
} else {
//
// The input latitude is negative, while the point
// is on or above the X-Y plane.
//
*REL = GT;
}
}
}
CHKOUT(b"ZZPDCMPL", ctx)?;
Ok(())
}