Coverage Report

Created: 2026-07-30 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sofars-0.6.1/src/projection/tpxes.rs
Line
Count
Source
1
/// In the tangent plane projection, given celestial spherical
2
/// coordinates for a star and the tangent point, solve for the star's
3
/// rectangular coordinates in the tangent plane.
4
///
5
/// Status:  support function.
6
///
7
/// Given:
8
///    a,b       f64  star's spherical coordinates
9
///    a0,b0     f64  tangent point's spherical coordinates
10
///
11
/// Returned:
12
///    xi,eta    f64  rectangular coordinates of star image (Note 2)
13
///    status    i32  status:  0 = OK
14
///                          1 = star too far from axis
15
///                          2 = antistar on tangent plane
16
///                          3 = antistar too far from axis
17
///
18
/// Notes:
19
///
20
/// 1) The tangent plane projection is also called the "gnomonic
21
///    projection" and the "central projection".
22
///
23
/// 2) The eta axis points due north in the adopted coordinate system.
24
///    If the spherical coordinates are observed (RA,Dec), the tangent
25
///    plane coordinates (xi,eta) are conventionally called the
26
///    "standard coordinates".  For right-handed spherical coordinates,
27
///    (xi,eta) are also right-handed.  The units of (xi,eta) are,
28
///    effectively, radians at the tangent point.
29
///
30
/// 3) All angular arguments are in radians.
31
///
32
/// 4) This function is a member of the following set:
33
///
34
///        spherical      vector         solve for
35
///
36
///      > tpxes <       tpxev          xi,eta
37
///        tpsts         tpstv           star
38
///        tpors         tporv          origin
39
///
40
/// References:
41
///
42
///    Calabretta M.R. & Greisen, E.W., 2002, "Representations of
43
///    celestial coordinates in FITS", Astron.Astrophys. 395, 1077
44
///
45
///    Green, R.M., "Spherical Astronomy", Cambridge University Press,
46
///    1987, Chapter 13.
47
0
pub fn tpxes(a: f64, b: f64, a0: f64, b0: f64) -> (f64, f64, i32) {
48
    const TINY: f64 = 1e-6;
49
50
    /* Functions of the spherical coordinates. */
51
0
    let sb0 = b0.sin();
52
0
    let sb = b.sin();
53
0
    let cb0 = b0.cos();
54
0
    let cb = b.cos();
55
0
    let da = a - a0;
56
0
    let sda = da.sin();
57
0
    let cda = da.cos();
58
59
    /* Reciprocal of star vector length to tangent plane. */
60
0
    let mut d = sb * sb0 + cb * cb0 * cda;
61
62
    /* Check for error cases. */
63
0
    let status = if d > TINY {
64
0
        0
65
0
    } else if d >= 0.0 {
66
0
        d = TINY;
67
0
        1
68
0
    } else if d > -TINY {
69
0
        d = -TINY;
70
0
        2
71
    } else {
72
0
        3
73
    };
74
75
    /* Return the tangent plane coordinates (even in dubious cases). */
76
0
    let xi = cb * sda / d;
77
0
    let eta = (sb * cb0 - cb * sb0 * cda) / d;
78
79
0
    (xi, eta, status)
80
0
}