-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPoint.h
More file actions
124 lines (104 loc) · 2.94 KB
/
Point.h
File metadata and controls
124 lines (104 loc) · 2.94 KB
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
116
117
118
119
120
121
122
123
124
#ifndef INCLUDED_MATH_POINT
#define INCLUDED_MATH_POINT
#include "Triple.h"
#include "Vector.h"
#include "Unit_vector.h"
namespace Dubious {
namespace Math {
template <int T>
class PointT;
template <int T>
bool operator==(const PointT<T>& a, const PointT<T>& b);
template <int T>
bool operator!=(const PointT<T>& a, const PointT<T>& b);
template <int T>
std::ostream& operator<<(std::ostream& o, const PointT<T>& a);
/// @brief A 3D Point
///
/// Represents a 3D point. This is different from a Vector in that
/// it is not a direction, it is simply a point in space. It is
/// a template only so that we can create Points intended for different
/// uses that the compiler can enforce
template <int T>
class PointT {
public:
/// @brief Default Constructor
///
/// Creates a Point at 0,0,0
PointT() = default;
/// @brief Constructor
///
/// Creates the point at the coordinate specified
/// @param x - [in] X component
/// @param y - [in] Y component
/// @param z - [in] Z component
PointT(float x, float y, float z) : m_coords(x, y, z) {}
/// @brief X accessor
/// @returns X coordinate
float x() const { return m_coords.m_x; }
/// @brief Y accessor
/// @returns Y coordinate
float y() const { return m_coords.m_y; }
/// @brief Z accessor
/// @returns Z coordinate
float z() const { return m_coords.m_z; }
private:
friend bool operator==<>(const PointT<T>& a, const PointT<T>& b);
friend bool operator!=<>(const PointT<T>& a, const PointT<T>& b);
friend std::ostream& operator<<<>(std::ostream& o, const PointT<T>& a);
Triple m_coords;
};
template <int T>
VectorT<T>
operator-(const PointT<T>& a, const PointT<T>& b)
{
return VectorT<T>(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
}
template <int T>
PointT<T>
operator+(const PointT<T>& a, const VectorT<T>& b)
{
return PointT<T>(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
}
template <int T>
PointT<T>
operator-(const PointT<T>& a, const VectorT<T>& b)
{
return PointT<T>(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
}
template <int T>
PointT<T>
operator+(const PointT<T>& a, const Unit_vectorT<T>& b)
{
return PointT<T>(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
}
template <int T>
PointT<T>
operator-(const PointT<T>& a, const Unit_vectorT<T>& b)
{
return PointT<T>(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
}
template <int T>
bool
operator==(const PointT<T>& a, const PointT<T>& b)
{
return a.m_coords == b.m_coords;
}
template <int T>
bool
operator!=(const PointT<T>& a, const PointT<T>& b)
{
return a.m_coords != b.m_coords;
}
template <int T>
std::ostream&
operator<<(std::ostream& o, const PointT<T>& a)
{
o << a.m_coords;
return o;
}
typedef PointT<0> Point;
typedef PointT<1> Local_point;
} // namespace Math
} // namespace Dubious
#endif