From e9c9d5a883e819e7799e630a883917ce4c69b41a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Sep 2024 19:53:08 +0100 Subject: Add new mathematical constants to lib --- lib/maths.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/maths.h b/lib/maths.h index 018ef0e..3127d3c 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -42,6 +42,10 @@ constexpr auto half_pi {glm::half_pi()}; constexpr auto quarter_pi {half_pi / 2}; constexpr auto pi {glm::pi()}; constexpr auto two_pi {glm::two_pi()}; +constexpr auto degreesToRads = pi / 180.F; + +constexpr auto earthMeanRadius = 6371.01F; // In km +constexpr auto astronomicalUnit = 149597890.F; // In km template constexpr inline GlobalPosition -- cgit v1.2.3 From b16d51e7d108c50e960d4598cb7cd47854c76f3e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 19 Sep 2024 19:55:14 +0100 Subject: Add helper to quickly parse an ISO date/time --- lib/chronology.cpp | 12 ++++++++++++ lib/chronology.h | 2 ++ 2 files changed, 14 insertions(+) create mode 100644 lib/chronology.cpp (limited to 'lib') diff --git a/lib/chronology.cpp b/lib/chronology.cpp new file mode 100644 index 0000000..8707bba --- /dev/null +++ b/lib/chronology.cpp @@ -0,0 +1,12 @@ +#include "chronology.h" + +time_t +operator""_time_t(const char * iso, size_t) +{ + struct tm tm {}; + + if (const auto end = strptime(iso, "%FT%T", &tm); !end || *end) { + throw std::invalid_argument("Invalid date"); + } + return mktime(&tm); +} diff --git a/lib/chronology.h b/lib/chronology.h index 1980116..688a1f7 100644 --- a/lib/chronology.h +++ b/lib/chronology.h @@ -1,5 +1,7 @@ #pragma once #include +#include using TickDuration = std::chrono::duration; +time_t operator""_time_t(const char * iso, size_t); -- cgit v1.2.3