3namespace tinyrobotics {
6
7
8
9
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
43 Distance(
float distance,
DistanceUnit unit) { setValue(distance, unit); }
46 distance = newDistance;
51 if (
unit == desiredUnit)
return distance;
54 if (desiredUnit ==
DistanceUnit::CM)
return distance * 100;
55 if (desiredUnit ==
DistanceUnit::MM)
return distance * 1000;
56 if (desiredUnit ==
DistanceUnit::FEET)
return distance * 3.28084f;
59 if (desiredUnit ==
DistanceUnit::M)
return distance / 100;
60 if (desiredUnit ==
DistanceUnit::MM)
return distance * 10;
61 if (desiredUnit ==
DistanceUnit::FEET)
return distance * 0.0328084f;
64 if (desiredUnit ==
DistanceUnit::M)
return distance / 1000;
65 if (desiredUnit ==
DistanceUnit::CM)
return distance / 10;
66 if (desiredUnit ==
DistanceUnit::FEET)
return distance * 0.00328084f;
69 if (desiredUnit ==
DistanceUnit::M)
return distance / 3.28084f;
70 if (desiredUnit ==
DistanceUnit::CM)
return distance / 0.0328084f;
71 if (desiredUnit ==
DistanceUnit::MM)
return distance / 0.00328084f;
78 float otherDistance = other.getValue(
unit);
83 float otherDistance = other.getValue(
unit);
87 Distance operator*(
float scalar)
const {
91 Distance operator/(
float scalar)
const {
96 bool operator==(
const Distance& other)
const {
97 return distance == other.getValue(
unit);
100 bool operator!=(
const Distance& other)
const {
return !(*
this == other); }
102 bool operator<(
const Distance& other)
const {
103 return distance < other.getValue(
unit);
106 bool operator<=(
const Distance& other)
const {
107 return distance <= other.getValue(
unit);
110 bool operator>(
const Distance& other)
const {
111 return distance > other.getValue(
unit);
114 bool operator>=(
const Distance& other)
const {
115 return distance >= other.getValue(
unit);
119 distance += other.getValue(
unit);
124 distance -= other.getValue(
unit);
128 Distance& operator*=(
float scalar) {
133 Distance& operator/=(
float scalar) {
143 float distance = 0.0f;
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
166 Distance3D() =
default;
167 Distance3D(
float x,
float y,
float z,
DistanceUnit unit)
168 : x(x), y(y), z(z),
unit(unit) {}
177 if (
unit == desiredUnit)
return x;
179 return tempDistance.getValue(desiredUnit);
182 if (
unit == desiredUnit)
return y;
184 return tempDistance.getValue(desiredUnit);
187 if (
unit == desiredUnit)
return z;
189 return tempDistance.getValue(desiredUnit);
Represents a 3D distance or position vector with unit support.
Definition: Distance.h:164
DistanceUnit unit
Unit of the 3D distance.
Definition: Distance.h:173
Represents a distance measurement with unit conversion support.
Definition: Distance.h:40
DistanceUnit unit
Unit of the distance.
Definition: Distance.h:144
DistanceUnit
Supported distance units for conversion and representation.
Definition: Distance.h:10