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
//! VSOP87E implementation
//!
//! This module calculates barycentric ecliptic rectangular coordinates for the equinox J2000.0
//! for the planets in the solar system. These coordinates are centered in the barycenter of the
//! solar system.

mod sun;
mod mercury;
mod venus;
mod earth;
mod mars;
mod jupiter;
mod saturn;
mod uranus;
mod neptune;

use super::{calculate_t, calculate_var};

/// Calculates VSOP87E solution for the Sun
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the Sun. The parameter needed is the Julian Day Efemeris (*JDE*) for
/// the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the VSOP87E
/// solution. Those values are the rectangular coordinates of the Sun, in *AU*, with the barycenter
/// of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::sun(2451545.0);
///
/// assert!(x > -0.0071415280 && x < -0.0071415278);
/// assert!(y > -0.0027881716 && y < -0.0027881714);
/// assert!(z > 0.0002041 && z < 0.0002081);
/// ```
pub fn sun(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &sun::X0);
    let x1 = calculate_var(t, &sun::X1);
    let x2 = calculate_var(t, &sun::X2);
    let x3 = calculate_var(t, &sun::X3);
    let x4 = calculate_var(t, &sun::X4);
    let x5 = calculate_var(t, &sun::X5);

    let y0 = calculate_var(t, &sun::Y0);
    let y1 = calculate_var(t, &sun::Y1);
    let y2 = calculate_var(t, &sun::Y2);
    let y3 = calculate_var(t, &sun::Y3);
    let y4 = calculate_var(t, &sun::Y4);
    let y5 = calculate_var(t, &sun::Y5);

    let z0 = calculate_var(t, &sun::Z0);
    let z1 = calculate_var(t, &sun::Z1);
    let z2 = calculate_var(t, &sun::Z2);
    let z3 = calculate_var(t, &sun::Z3);
    let z4 = calculate_var(t, &sun::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}


/// Calculates VSOP87E solution for Mercury
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Mercury. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::mercury(2415020.0);
///
/// assert!(x > -0.3865370328 && x < -0.3865370326);
/// assert!(y > -0.1438666202 && y < -0.1438666200);
/// assert!(z > 0.0235142 && z < 0.0235182);
/// ```
pub fn mercury(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &mercury::X0);
    let x1 = calculate_var(t, &mercury::X1);
    let x2 = calculate_var(t, &mercury::X2);
    let x3 = calculate_var(t, &mercury::X3);
    let x4 = calculate_var(t, &mercury::X4);
    let x5 = calculate_var(t, &mercury::X5);

    let y0 = calculate_var(t, &mercury::Y0);
    let y1 = calculate_var(t, &mercury::Y1);
    let y2 = calculate_var(t, &mercury::Y2);
    let y3 = calculate_var(t, &mercury::Y3);
    let y4 = calculate_var(t, &mercury::Y4);
    let y5 = calculate_var(t, &mercury::Y5);

    let z0 = calculate_var(t, &mercury::Z0);
    let z1 = calculate_var(t, &mercury::Z1);
    let z2 = calculate_var(t, &mercury::Z2);
    let z3 = calculate_var(t, &mercury::Z3);
    let z4 = calculate_var(t, &mercury::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Venus
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Venus. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::venus(2378495.0);
///
/// assert!(x > -0.5948645228 && x < -0.5948645226);
/// assert!(y > 0.3900421674 && y < 0.3900421676);
/// assert!(z > 0.0397542 && z < 0.0397582);
/// ```
pub fn venus(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &venus::X0);
    let x1 = calculate_var(t, &venus::X1);
    let x2 = calculate_var(t, &venus::X2);
    let x3 = calculate_var(t, &venus::X3);
    let x4 = calculate_var(t, &venus::X4);
    let x5 = calculate_var(t, &venus::X5);

    let y0 = calculate_var(t, &venus::Y0);
    let y1 = calculate_var(t, &venus::Y1);
    let y2 = calculate_var(t, &venus::Y2);
    let y3 = calculate_var(t, &venus::Y3);
    let y4 = calculate_var(t, &venus::Y4);
    let y5 = calculate_var(t, &venus::Y5);

    let z0 = calculate_var(t, &venus::Z0);
    let z1 = calculate_var(t, &venus::Z1);
    let z2 = calculate_var(t, &venus::Z2);
    let z3 = calculate_var(t, &venus::Z3);
    let z4 = calculate_var(t, &venus::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Earth
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Earth. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::earth(2341970.0);
///
/// assert!(x > -0.2155959338 && x < -0.2155959336);
/// assert!(y > 0.9651943804 && y < 0.9651943806);
/// assert!(z > 0.0007705 && z < 0.0007745);
/// ```
pub fn earth(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &earth::X0);
    let x1 = calculate_var(t, &earth::X1);
    let x2 = calculate_var(t, &earth::X2);
    let x3 = calculate_var(t, &earth::X3);
    let x4 = calculate_var(t, &earth::X4);
    let x5 = calculate_var(t, &earth::X5);

    let y0 = calculate_var(t, &earth::Y0);
    let y1 = calculate_var(t, &earth::Y1);
    let y2 = calculate_var(t, &earth::Y2);
    let y3 = calculate_var(t, &earth::Y3);
    let y4 = calculate_var(t, &earth::Y4);
    let y5 = calculate_var(t, &earth::Y5);

    let z0 = calculate_var(t, &earth::Z0);
    let z1 = calculate_var(t, &earth::Z1);
    let z2 = calculate_var(t, &earth::Z2);
    let z3 = calculate_var(t, &earth::Z3);
    let z4 = calculate_var(t, &earth::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Mars
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Mars. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::mars(2305445.0);
///
/// assert!(x > -0.8237565239 && x < -0.8237565237);
/// assert!(y > 1.4065798250 && y < 1.4065798252);
/// assert!(z > 0.0502476 && z < 0.0502516);
/// ```
pub fn mars(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &mars::X0);
    let x1 = calculate_var(t, &mars::X1);
    let x2 = calculate_var(t, &mars::X2);
    let x3 = calculate_var(t, &mars::X3);
    let x4 = calculate_var(t, &mars::X4);
    let x5 = calculate_var(t, &mars::X5);

    let y0 = calculate_var(t, &mars::Y0);
    let y1 = calculate_var(t, &mars::Y1);
    let y2 = calculate_var(t, &mars::Y2);
    let y3 = calculate_var(t, &mars::Y3);
    let y4 = calculate_var(t, &mars::Y4);
    let y5 = calculate_var(t, &mars::Y5);

    let z0 = calculate_var(t, &mars::Z0);
    let z1 = calculate_var(t, &mars::Z1);
    let z2 = calculate_var(t, &mars::Z2);
    let z3 = calculate_var(t, &mars::Z3);
    let z4 = calculate_var(t, &mars::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Jupiter
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Jupiter. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::jupiter(2268920.0);
///
/// assert!(x > 4.5819830418 && x < 4.5819830420);
/// assert!(y > -1.9854861384 && y < -1.9854861382);
/// assert!(z > -0.0959289 && z < -0.0959249);
/// ```
pub fn jupiter(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &jupiter::X0);
    let x1 = calculate_var(t, &jupiter::X1);
    let x2 = calculate_var(t, &jupiter::X2);
    let x3 = calculate_var(t, &jupiter::X3);
    let x4 = calculate_var(t, &jupiter::X4);
    let x5 = calculate_var(t, &jupiter::X5);

    let y0 = calculate_var(t, &jupiter::Y0);
    let y1 = calculate_var(t, &jupiter::Y1);
    let y2 = calculate_var(t, &jupiter::Y2);
    let y3 = calculate_var(t, &jupiter::Y3);
    let y4 = calculate_var(t, &jupiter::Y4);
    let y5 = calculate_var(t, &jupiter::Y5);

    let z0 = calculate_var(t, &jupiter::Z0);
    let z1 = calculate_var(t, &jupiter::Z1);
    let z2 = calculate_var(t, &jupiter::Z2);
    let z3 = calculate_var(t, &jupiter::Z3);
    let z4 = calculate_var(t, &jupiter::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Saturn
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Saturn. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::saturn(2232395.0);
///
/// assert!(x > 1.2645936161 && x < 1.2645936163);
/// assert!(y > -10.0240954526 && y < -10.0240954524);
/// assert!(z > 0.1345888 && z < 0.1345928);
/// ```
pub fn saturn(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &saturn::X0);
    let x1 = calculate_var(t, &saturn::X1);
    let x2 = calculate_var(t, &saturn::X2);
    let x3 = calculate_var(t, &saturn::X3);
    let x4 = calculate_var(t, &saturn::X4);
    let x5 = calculate_var(t, &saturn::X5);

    let y0 = calculate_var(t, &saturn::Y0);
    let y1 = calculate_var(t, &saturn::Y1);
    let y2 = calculate_var(t, &saturn::Y2);
    let y3 = calculate_var(t, &saturn::Y3);
    let y4 = calculate_var(t, &saturn::Y4);
    let y5 = calculate_var(t, &saturn::Y5);

    let z0 = calculate_var(t, &saturn::Z0);
    let z1 = calculate_var(t, &saturn::Z1);
    let z2 = calculate_var(t, &saturn::Z2);
    let z3 = calculate_var(t, &saturn::Z3);
    let z4 = calculate_var(t, &saturn::Z4);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4) + x5*t.powi(5);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4) + y5*t.powi(5);
    let z = z0 + z1*t + z2*t*t + z3*t.powi(3) + z4*t.powi(4);

    (x, y, z)
}

/// Calculates VSOP87E solution for Uranus
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Uranus. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::uranus(2195870.0);
///
/// assert!(x > -17.6538791198 && x < -17.6538791196);
/// assert!(y > -5.1666300881 && y < -5.1666300879);
/// assert!(z > 0.2124594 && z < 0.2124634);
/// ```
pub fn uranus(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &uranus::X0);
    let x1 = calculate_var(t, &uranus::X1);
    let x2 = calculate_var(t, &uranus::X2);
    let x3 = calculate_var(t, &uranus::X3);
    let x4 = calculate_var(t, &uranus::X4);

    let y0 = calculate_var(t, &uranus::Y0);
    let y1 = calculate_var(t, &uranus::Y1);
    let y2 = calculate_var(t, &uranus::Y2);
    let y3 = calculate_var(t, &uranus::Y3);
    let y4 = calculate_var(t, &uranus::Y4);

    let z0 = calculate_var(t, &uranus::Z0);
    let z1 = calculate_var(t, &uranus::Z1);
    let z2 = calculate_var(t, &uranus::Z2);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4);
    let z = z0 + z1*t + z2*t*t;

    (x, y, z)
}

/// Calculates VSOP87E solution for Neptune
///
/// This function calculates the VSOP87E solution (barycentric ecliptic rectangular coordinates for
/// the equinox J2000.0) for the planet Neptune. The parameter needed is the Julian Day Efemeris
/// (*JDE*) for the given date. It returns, in order, a tuple with the values *x*, *y*, *z* of the
/// VSOP87E solution. Those values are the rectangular coordinates of the planet, in *AU*, with the
/// barycenter of the solar system in the center and the ecliptic plane as reference ```z = 0```.
///
/// # Examples
///
/// ```
/// use vsop87::vsop87e;
///
/// let (x, y, z) = vsop87e::neptune(2159345.0);
///
/// assert!(x > 29.8297729718 && x < 29.8297729720);
/// assert!(y > -2.0298541973 && y < -2.0298541971);
/// assert!(z > -0.6440972 && z < -0.6440932);
/// ```
pub fn neptune(jde: f64) -> (f64, f64, f64) {
    let t = calculate_t(jde);

    let x0 = calculate_var(t, &neptune::X0);
    let x1 = calculate_var(t, &neptune::X1);
    let x2 = calculate_var(t, &neptune::X2);
    let x3 = calculate_var(t, &neptune::X3);
    let x4 = calculate_var(t, &neptune::X4);

    let y0 = calculate_var(t, &neptune::Y0);
    let y1 = calculate_var(t, &neptune::Y1);
    let y2 = calculate_var(t, &neptune::Y2);
    let y3 = calculate_var(t, &neptune::Y3);
    let y4 = calculate_var(t, &neptune::Y4);

    let z0 = calculate_var(t, &neptune::Z0);
    let z1 = calculate_var(t, &neptune::Z1);
    let z2 = calculate_var(t, &neptune::Z2);

    let x = x0 + x1*t + x2*t*t + x3*t.powi(3) + x4*t.powi(4);
    let y = y0 + y1*t + y2*t*t + y3*t.powi(3) + y4*t.powi(4);
    let z = z0 + z1*t + z2*t*t;

    (x, y, z)
}