# Path: skyfield/constants.py
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# AU_KM = 149597870.700
# ASEC360 = 1296000.0
# DAY_S = 86400.0
# ASEC2RAD = 4.848136811095359935899141e-6
# DEG2RAD = 0.017453292519943296
# RAD2DEG = 57.295779513082321
# C = 299792458.0                            # m/s
# ANGVEL = 7.2921150e-5           # radians/s
# ERAD = 6378136.6                # meters
# IERS_2010_INVERSE_EARTH_FLATTENING = 298.25642
# GS = 1.32712440017987e+20
# T0 = 2451545.0
# B1950 = 2433282.4235
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/functions.py
# def from_spherical(r, theta, phi):
#     """Convert (r,theta,phi) to Cartesian coordinates |xyz|.
# 
#     ``r`` - vector length
#     ``theta`` - angle in radians above (+) or below (-) the xy-plane
#     ``phi`` - angle in radians around the z-axis
# 
#     Note that ``theta`` is an elevation angle measured up and down from
#     the xy-plane, not a polar angle measured from the z-axis, to match
#     the convention for both latitude and declination.
# 
#     """
#     rxy = r * cos(theta)
#     return array((rxy * cos(phi), rxy * sin(phi), r * sin(theta)))
# 
# def _reconcile(a, b):
#     """Coerce two NumPy generics-or-arrays to the same number of dimensions."""
#     an = getattr(a, 'ndim', 0)
#     bn = getattr(b, 'ndim', 0)
#     difference = bn - an
#     if difference > 0:
#         if an:
#             a.shape += (1,) * difference
#         else:
#             a = full_like(b, a)
#     elif difference < 0:
#         if bn:
#             b.shape += (1,) * -difference
#         else:
#             b = full_like(a, b)
#     return a, b


from numpy import array
from skyfield.constants import tau
from skyfield.functions import from_spherical, _reconcile


def test_right():
    dx, dy, dz = from_spherical(1, 0, 0) - [1, 0, 0]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_down():
    dx, dy, dz = from_spherical(1, 0, 0.75 * tau) - [0, -1, 0]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_up():
    dx, dy, dz = from_spherical(1, 0.25 * tau, 0) - [0, 0, 1]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_left_up():
    sqrt2 = 0.5 ** 0.5
    dx, dy, dz = from_spherical(1, 0.125 * tau, 0.5 * tau) - [-sqrt2, 0, sqrt2]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_reconcile():
    a = array([1,2])
    b = array([[1], [2]])

# Path: skyfield/constants.py
# AU_M = 149597870700             # per IAU 2012 Resolution B2
# AU_KM = 149597870.700
# ASEC360 = 1296000.0
# DAY_S = 86400.0
# ASEC2RAD = 4.848136811095359935899141e-6
# DEG2RAD = 0.017453292519943296
# RAD2DEG = 57.295779513082321
# C = 299792458.0                            # m/s
# ANGVEL = 7.2921150e-5           # radians/s
# ERAD = 6378136.6                # meters
# IERS_2010_INVERSE_EARTH_FLATTENING = 298.25642
# GS = 1.32712440017987e+20
# T0 = 2451545.0
# B1950 = 2433282.4235
# C_AUDAY = C * DAY_S / AU_M
# 
# Path: skyfield/functions.py
# def from_spherical(r, theta, phi):
#     """Convert (r,theta,phi) to Cartesian coordinates |xyz|.
# 
#     ``r`` - vector length
#     ``theta`` - angle in radians above (+) or below (-) the xy-plane
#     ``phi`` - angle in radians around the z-axis
# 
#     Note that ``theta`` is an elevation angle measured up and down from
#     the xy-plane, not a polar angle measured from the z-axis, to match
#     the convention for both latitude and declination.
# 
#     """
#     rxy = r * cos(theta)
#     return array((rxy * cos(phi), rxy * sin(phi), r * sin(theta)))
# 
# def _reconcile(a, b):
#     """Coerce two NumPy generics-or-arrays to the same number of dimensions."""
#     an = getattr(a, 'ndim', 0)
#     bn = getattr(b, 'ndim', 0)
#     difference = bn - an
#     if difference > 0:
#         if an:
#             a.shape += (1,) * difference
#         else:
#             a = full_like(b, a)
#     elif difference < 0:
#         if bn:
#             b.shape += (1,) * -difference
#         else:
#             b = full_like(a, b)
#     return a, b


# Path: skyfield/tests/test_functions.py
from numpy import array
from skyfield.constants import tau
from skyfield.functions import from_spherical, _reconcile



def test_right():
    dx, dy, dz = from_spherical(1, 0, 0) - [1, 0, 0]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_down():
    dx, dy, dz = from_spherical(1, 0, 0.75 * tau) - [0, -1, 0]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_up():
    dx, dy, dz = from_spherical(1, 0.25 * tau, 0) - [0, 0, 1]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_left_up():
    sqrt2 = 0.5 ** 0.5
    dx, dy, dz = from_spherical(1, 0.125 * tau, 0.5 * tau) - [-sqrt2, 0, sqrt2]
    assert abs(dx) < 1e-15
    assert abs(dy) < 1e-15
    assert abs(dz) < 1e-15

def test_reconcile():
    a = array([1,2])
    b = array([[1], [2]])

    a2, b2 = _reconcile(a, b)