#ifndef GRID_CONVERT_H
#define GRID_CONVERT_H

#include <cmath>
#include <numbers>
#include <span>

static inline void
lonlat_to_xyz(double lon, double lat, std::span<double, 3> xyz) noexcept
{
  auto cos_lat = std::cos(lat);
  xyz[0] = cos_lat * std::cos(lon);
  xyz[1] = cos_lat * std::sin(lon);
  xyz[2] = std::sin(lat);
  /*
  double sin_lon, cos_lon, sin_lat, cos_lat;
#if defined(__GNUC__) || defined(__clang__)
  __builtin_sincos(lon, &sin_lon, &cos_lon);
  __builtin_sincos(lat, &sin_lat, &cos_lat);
#else
  sin_lon = std::sin(lon);
  cos_lon = std::cos(lon);
  sin_lat = std::sin(lat);
  cos_lat = std::cos(lat);
#endif
  xyz[0] = cos_lat * cos_lon;
  xyz[1] = cos_lat * sin_lon;
  xyz[2] = sin_lat;
  */
}

#ifndef RAD_CONVERT
#define RAD_CONVERT
constexpr double RAD2DEG = 180.0 / std::numbers::pi;  // conversion from radians to degrees
constexpr double DEG2RAD = std::numbers::pi / 180.0;  // conversion from degrees to radians
// clang-format off
inline constexpr double rad_to_deg(double rad) noexcept { return rad * 180.0 / std::numbers::pi; };
inline constexpr double deg_to_rad(double deg) noexcept { return deg * std::numbers::pi / 180.0; };
// clang-format on
#endif

#endif
