opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
chrono_helpers.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cmath>
5#include <type_traits>
6
7namespace osc
8{
9 // returns the linear interpolation between `a` and `b`, if the parameter `t` is inside [0, 1) (the linear
10 // extrapolation otherwise)
11 template<typename Rep, typename Period, typename Arithmetic>
12 requires std::is_arithmetic_v<Rep> and std::is_arithmetic_v<Arithmetic>
13 constexpr std::chrono::duration<Rep, Period> lerp(
14 const std::chrono::duration<Rep, Period>& a,
15 const std::chrono::duration<Rep, Period>& b,
16 const Arithmetic& t)
17 {
18 return std::chrono::duration<Rep, Period>(static_cast<Rep>(std::lerp(a.count(), b.count(), t)));
19 }
20
21 // returns the linear interpolation between `a` and `b`, if the parameter `t` is inside [0, 1) (the linear
22 // extrapolation otherwise)
23 template<typename Clock, typename Duration, typename Arithmetic>
24 requires std::is_arithmetic_v<Arithmetic>
25 constexpr std::chrono::time_point<Clock, Duration> lerp(
26 const std::chrono::time_point<Clock, Duration>& a,
27 const std::chrono::time_point<Clock, Duration>& b,
28 const Arithmetic& t)
29 {
30 return std::chrono::time_point<Clock, Duration>{lerp(a.time_since_epoch(), b.time_since_epoch(), t)};
31 }
32}
Definition custom_decoration_generator.h:5
constexpr auto lerp(const Rgba< T > &x, const Rgba< T > &y, TInterpolant t)
Definition rgba.h:230
constexpr U to(T &&value)
Definition conversion.h:56
and
Definition algorithms.h:158