forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_traits.h
107 lines (101 loc) · 2.32 KB
/
point_traits.h
1
2
3
4
5
6
7
8
9
10
11
12
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef CATA_SRC_POINT_TRAITS_H
#define CATA_SRC_POINT_TRAITS_H
#include <type_traits>
struct point;
struct tripoint;
struct rl_vec2d;
struct rl_vec3d;
template<typename Point, typename = void>
struct point_traits {
static int &x( Point &p ) {
return p.x();
}
static int x( const Point &p ) {
return p.x();
}
static int &y( Point &p ) {
return p.y();
}
static int y( const Point &p ) {
return p.y();
}
static int &z( Point &p ) {
return p.z();
}
static int z( const Point &p ) {
return p.z();
}
};
template<typename Point>
struct point_traits <
Point,
std::enable_if_t < std::is_same<Point, point>::value || std::is_same<Point, tripoint>::value >
> {
static int &x( Point &p ) {
return p.x;
}
static const int &x( const Point &p ) {
return p.x;
}
static int &y( Point &p ) {
return p.y;
}
static const int &y( const Point &p ) {
return p.y;
}
static int &z( Point &p ) {
return p.z;
}
static const int &z( const Point &p ) {
return p.z;
}
};
template<typename Point>
struct point_traits <
Point,
std::enable_if_t < std::is_same<Point, rl_vec2d>::value || std::is_same<Point, rl_vec3d>::value >
> {
static float &x( Point &p ) {
return p.x;
}
static const float &x( const Point &p ) {
return p.x;
}
static float &y( Point &p ) {
return p.y;
}
static const float &y( const Point &p ) {
return p.y;
}
static float &z( Point &p ) {
return p.z;
}
static const float &z( const Point &p ) {
return p.z;
}
// TODO: Template
constexpr static float &at( Point &p, size_t i ) {
switch( i ) {
case 0:
return x( p );
case 1:
return y( p );
case 2:
return z( p );
}
// Template would make this impossible
return x( p );
}
constexpr static const float &at( const Point &p, size_t i ) {
switch( i ) {
case 0:
return x( p );
case 1:
return y( p );
case 2:
return z( p );
}
return x( p );
}
};
#endif // CATA_SRC_POINT_TRAITS_H