# Path: skyfield/earthlib.py
# def terra(latitude, longitude, elevation, gast):
# def reverse_terra(xyz_au, gast, iterations=3):
# def compute_limb_angle(position_au, observer_au):
# def sidereal_time(t):
# def earth_rotation_angle(jd_ut1, fraction_ut1=0.0):
# def refraction(alt_degrees, temperature_C, pressure_mbar):
# def refract(alt_degrees, temperature_C, pressure_mbar):
#     R = sqrt(x*x + y*y)
#     C = 1.0
#         C = 1.0 / sqrt(1.0 - e2 * (sin(lat) ** 2.0))


from numpy import array, sqrt
from skyfield.earthlib import AU_M, ERAD, reverse_terra, tau

def test_reverse_terra_with_zero_iterations():
    # With zero iterations, should return "geocentric" rather than
    # "geodetic" (="correct") longitude and latitude.
    lat, lon, elevation = reverse_terra(array([1, 0, 1]), 0, iterations=0)
    assert abs(lat - tau / 8) < 1e-16
    assert lon == 0.0

# Path: skyfield/earthlib.py
# def terra(latitude, longitude, elevation, gast):
# def reverse_terra(xyz_au, gast, iterations=3):
# def compute_limb_angle(position_au, observer_au):
# def sidereal_time(t):
# def earth_rotation_angle(jd_ut1, fraction_ut1=0.0):
# def refraction(alt_degrees, temperature_C, pressure_mbar):
# def refract(alt_degrees, temperature_C, pressure_mbar):
#     R = sqrt(x*x + y*y)
#     C = 1.0
#         C = 1.0 / sqrt(1.0 - e2 * (sin(lat) ** 2.0))


# Path: skyfield/tests/test_earthlib.py
from numpy import array, sqrt
from skyfield.earthlib import AU_M, ERAD, reverse_terra, tau


def test_reverse_terra_with_zero_iterations():
    # With zero iterations, should return "geocentric" rather than
    # "geodetic" (="correct") longitude and latitude.
    lat, lon, elevation = reverse_terra(array([1, 0, 1]), 0, iterations=0)
    assert abs(lat - tau / 8) < 1e-16
    assert lon == 0.0

    assert abs(elevation - (AU_M * sqrt(2) - ERAD)) < 1e-16