mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: implement interpolate() function for unit types
Calls the global interpolate() function for integer types. For now, the template is enabled if the arguments are not integer types. Might want to refine that in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
133bc50d53
commit
64945a1c96
4 changed files with 22 additions and 4 deletions
17
core/units.h
17
core/units.h
|
@ -2,6 +2,8 @@
|
|||
#ifndef UNITS_H
|
||||
#define UNITS_H
|
||||
|
||||
#include "interpolate.h"
|
||||
|
||||
#include <math.h>
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
@ -86,6 +88,12 @@
|
|||
* _permille -> fraction_t in ‰
|
||||
* _percent -> fraction_t in %
|
||||
*
|
||||
* For now, addition and subtraction of values of the same type
|
||||
* are supported.
|
||||
*
|
||||
* A free standing interpolate() function can be used to interpolate
|
||||
* between types of the same kind (see also the interpolate.h header).
|
||||
*
|
||||
* We don't actually use these all yet, so maybe they'll change, but
|
||||
* I made a number of types as guidelines.
|
||||
*/
|
||||
|
@ -140,6 +148,15 @@ struct unit_base {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T,
|
||||
std::enable_if_t<!std::is_integral<T>::value, bool> = true>
|
||||
T interpolate(T a, T b, int part, int whole)
|
||||
{
|
||||
return T::from_base(
|
||||
interpolate(a.get_base(), b.get_base(), part, whole)
|
||||
);
|
||||
}
|
||||
|
||||
struct duration_t : public unit_base<duration_t>
|
||||
{
|
||||
int32_t seconds = 0; // durations up to 34 yrs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue