Scanframe DevOps Trial App 0.1.0
Loading...
Searching...
No Matches
template.h
Go to the documentation of this file.
1#pragma once
2#include <limits>
3#include <type_traits>
4
10namespace MySpace
11{
12
25template<class T, class S>
26auto calculateOffset(T value, T min_val, T max_val, S len, bool clip) -> S
27{
28 max_val -= min_val;
29 value -= min_val;
30 S temp;
31 if constexpr (std::is_floating_point<T>())
32 {
33 temp = len * (value / max_val);
34 }
35 else
36 {
37 temp = (len * value) / max_val;
38 }
39 temp = (max_val && value) ? temp : 0;
40 // Clip when required.
41 if (clip)
42 {
43 // When the len is a negative value.
44 if (len < 0)
45 {
46 return (temp < len) ? len : (temp > S(0)) ? S(0) : temp;
47 }
48 return (temp > len) ? len : (temp < S(0)) ? S(0) : temp;
49 }
50 return temp;
51}
52
61template<class T>
62inline auto clip(const T value, const T min_val, const T max_val) -> T
63{
64 return (value < min_val) ? min_val : ((value > max_val) ? max_val : value);
65}
66
67}// namespace MySpace
Definition template.h:11
auto clip(const T value, const T min_val, const T max_val) -> T
Returns clipped value of v between a and b where a < b.
Definition template.h:62
auto calculateOffset(T value, T min_val, T max_val, S len, bool clip) -> S
Calculates the offset for a given range and set point.
Definition template.h:26