Types.cpp
Go to the documentation of this file.
1#include "Types.h"
2
4{
5 // LinearConfig
6
7 LinearConfig::LinearConfig(float factor, float offset) :
8 factorAbs(std::abs(factor)), offset(offset), negativeFactor(factor < 0)
9 {
10 ;
11 }
12
15 {
16 if (other.factorAbs.has_value())
17 {
18 factorAbs = other.factorAbs;
19 }
20
21 if (other.negativeFactor.has_value())
22 {
23 negativeFactor = other.negativeFactor;
24 }
25
26 if (other.offset.has_value())
27 {
28 offset = other.offset;
29 }
30 return *this;
31 }
32
33 void
35 {
36 this->factorAbs = std::make_optional(factorAbs);
37 }
38
39 void
41 {
42 this->offset = std::make_optional(offset);
43 }
44
45 void
47 {
48 this->negativeFactor = isNegative;
49 }
50
51 float
53 {
54 return (negativeFactor.value_or(false) ? -1 : 1) * factorAbs.value_or(1.f);
55 }
56
57 float
59 {
60 return offset.value_or(0.f);
61 }
62
63 // ModularConvertedValueConfig
64
66 float discontinuityOffset,
67 float maxValue,
68 bool isInverted) :
69 zeroOffset(zeroOffset),
70 discontinuityOffset(discontinuityOffset),
71 maxValue(maxValue),
72 isInverted{isInverted}
73 {
74 ;
75 }
76
79 {
80 if (other.zeroOffset.has_value())
81 {
82 zeroOffset = other.zeroOffset;
83 }
84
85 if (other.discontinuityOffset.has_value())
86 {
87 discontinuityOffset = other.discontinuityOffset;
88 }
89
90 if (other.maxValue.has_value())
91 {
92 maxValue = other.maxValue;
93 }
94
95 if (other.isInverted.has_value())
96 {
97 isInverted = other.isInverted;
98 }
99
100 return *this;
101 }
102
103 void
105 {
106 this->zeroOffset = zeroOffset;
107 }
108
109 void
111 {
112 this->isInverted = isInverted;
113 }
114
115 float
117 {
118 return zeroOffset.value_or(0.f);
119 }
120
121 float
123 {
124 return discontinuityOffset.value_or(0.f);
125 }
126
127 float
129 {
130 return maxValue.value_or(0.f);
131 }
132
133 bool
135 {
136 return isInverted.value_or(false);
137 }
138
139
140} // namespace armarx::control::hardware_config::types
The LinearConfig class represents a linear conversion and has a factor and offset.
Definition Types.h:17
void setFactorAbsoluteValue(float factorAbs)
Set the absolute value for factor, keep sign unaffected.
Definition Types.cpp:34
LinearConfig(float factor, float offset)
Create LinearConfig with factor and offset.
Definition Types.cpp:7
void setFactorIsNegative(bool isNegative)
Set the new factor sign, keep the factor absolute value unaffected.
Definition Types.cpp:46
LinearConfig overrideWith(LinearConfig)
Perform partial override.
Definition Types.cpp:14
void setOffset(float offset)
Set the offset.
Definition Types.cpp:40
ModularConvertedValueConfig(float zeroOffset, float discontinuityOffset, float maxValue, bool isInverted)
Definition Types.cpp:65
ModularConvertedValueConfig overrideWith(const ModularConvertedValueConfig &)
Definition Types.cpp:78
std::vector< T > abs(const std::vector< T > &v)