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)
47 ? len
48 : (temp > S(0))
49 ? S(0)
50 : temp;
51 }
52 return (temp > len)
53 ? len
54 : (temp < S(0))
55 ? S(0)
56 : temp;
57 }
58 return temp;
59}
60
69template<class T>
70inline auto clip(const T value, const T min_val, const T max_val) -> T
71{
72 return (value < min_val)
73 ? min_val
74 : (
75 (value > max_val)
76 ? max_val
77 : value
78 );
79}
80
81}// 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:70
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