Scanframe DevOps Trial App
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
template.h
Go to the documentation of this file.
1
#pragma once
2
#include <limits>
3
#include <type_traits>
4
10
namespace
MySpace
11
{
12
25
template
<
class
T,
class
S>
26
auto
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
61
template
<
class
T>
62
inline
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
MySpace
Definition
template.h:11
MySpace::clip
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
MySpace::calculateOffset
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
src
cli
template.h
Generated by
1.18.0