forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_float.h
115 lines (102 loc) · 3.1 KB
/
point_float.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
108
109
110
111
112
113
114
115
#pragma once
#ifndef CATA_SRC_POINT_FLOAT_H
#define CATA_SRC_POINT_FLOAT_H
#include "point_traits.h"
struct point;
struct tripoint;
struct rl_vec2d {
static constexpr int dimension = 2;
float x;
float y;
explicit rl_vec2d( float x = 0, float y = 0 ) : x( x ), y( y ) {}
template<typename Point, typename Traits = point_traits<Point>>
constexpr explicit rl_vec2d( const Point &p ) : x( Traits::x( p ) ), y( Traits::y( p ) ) {}
float magnitude() const;
rl_vec2d normalized() const;
rl_vec2d rotated( float angle ) const;
float dot_product( const rl_vec2d &v ) const;
bool is_null() const;
point as_point() const;
// scale.
rl_vec2d operator* ( float rhs ) const;
rl_vec2d operator/ ( float rhs ) const;
// subtract
rl_vec2d operator- ( const rl_vec2d &rhs ) const;
// unary negation
rl_vec2d operator- () const;
rl_vec2d operator+ ( const rl_vec2d &rhs ) const;
};
struct rl_vec3d {
static constexpr int dimension = 3;
float x;
float y;
float z;
constexpr explicit rl_vec3d( float x = 0, float y = 0, float z = 0 ) : x( x ), y( y ), z( z ) {}
template<typename Point, typename Traits = point_traits<Point>>
constexpr explicit rl_vec3d( const Point &p ) : x( Traits::x( p ) ), y( Traits::y( p ) ),
z( Traits::z( p ) ) {}
float magnitude() const;
rl_vec3d normalized() const;
rl_vec3d rotated( float angle ) const;
float dot_product( const rl_vec3d &v ) const;
rl_vec3d cross_product( const rl_vec3d &v ) const;
bool is_null() const;
tripoint as_point() const;
// scale.
constexpr rl_vec3d operator* ( float rhs ) const {
rl_vec3d ret;
ret.x = x * rhs;
ret.y = y * rhs;
ret.z = z * rhs;
return ret;
}
constexpr rl_vec3d operator/ ( float rhs ) const {
rl_vec3d ret;
ret.x = x / rhs;
ret.y = y / rhs;
ret.z = z / rhs;
return ret;
}
// subtract
constexpr rl_vec3d operator- ( const rl_vec3d &rhs ) const {
rl_vec3d ret;
ret.x = x - rhs.x;
ret.y = y - rhs.y;
ret.z = z - rhs.z;
return ret;
}
// unary negation
constexpr rl_vec3d operator- () const {
rl_vec3d ret;
ret.x = -x;
ret.y = -y;
ret.z = -z;
return ret;
}
constexpr rl_vec3d operator+ ( const rl_vec3d &rhs ) const {
rl_vec3d ret;
ret.x = x + rhs.x;
ret.y = y + rhs.y;
ret.z = z + rhs.z;
return ret;
}
friend inline constexpr bool operator==( const rl_vec3d &a, const rl_vec3d &b ) {
return a.x == b.x && a.y == b.y && a.z == b.z;
}
friend inline constexpr bool operator!=( const rl_vec3d &a, const rl_vec3d &b ) {
return !( a == b );
}
friend inline constexpr bool operator<( const rl_vec3d &a, const rl_vec3d &b ) {
if( a.x != b.x ) {
return a.x < b.x;
}
if( a.y != b.y ) {
return a.y < b.y;
}
if( a.z != b.z ) {
return a.z < b.z;
}
return false;
}
};
#endif // CATA_SRC_POINT_FLOAT_H