Horizon
Loading...
Searching...
No Matches
xyz_container.hpp
1#pragma once
2#include <stdexcept>
3
4namespace horizon {
5template <typename T> class XYZContainer {
6public:
7 T x;
8 T y;
9 T z;
10
11 void set(unsigned int ax, const T &v)
12 {
13 switch (ax) {
14 case 0:
15 x = v;
16 break;
17
18 case 1:
19 y = v;
20 break;
21
22 case 2:
23 z = v;
24 break;
25
26 default:
27 throw std::domain_error("axis out of range");
28 }
29 }
30
31 T &get(unsigned int ax)
32 {
33 switch (ax) {
34 case 0:
35 return x;
36
37 case 1:
38 return y;
39
40 case 2:
41 return z;
42
43 default:
44 throw std::domain_error("axis out of range");
45 }
46 }
47
48 void set_all(const T &v)
49 {
50 for (unsigned int i = 0; i < 3; i++) {
51 set(i, v);
52 }
53 }
54};
55} // namespace horizon
Definition xyz_container.hpp:5