forked from dcblack/ModernSystemC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoord.hpp
More file actions
61 lines (61 loc) · 1.76 KB
/
coord.hpp
File metadata and controls
61 lines (61 loc) · 1.76 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
/**
* @file coord.hpp
* @brief 3-dimensional coordinate using floating point
*/
#include <systemc>
#include <string>
#include <ostream>
#include <valarray>
struct Coordinate
{
using T = double;
Coordinate( const T& x, const T& y, const T& z ): m_data( {x, y, z} ) {}
Coordinate( void ) = default;
~Coordinate( void ) = default;
Coordinate( const Coordinate& rhs ) : m_data( rhs.m_data ) {}
Coordinate( Coordinate&& rhs ) : m_data( std::move( rhs.m_data ) ) {}
Coordinate& operator=( const Coordinate& rhs ) {
if( this != &rhs ) {
m_data = rhs.m_data;
}
return *this;
}
Coordinate& operator=( Coordinate&& rhs ) {
m_data = std::move( rhs.m_data );
return *this;
}
bool operator==( const Coordinate& rhs ) const {
return *this == rhs;
}
// Convenience
T& x( void ) { return m_data[0]; }
T& y( void ) { return m_data[1]; }
T& z( void ) { return m_data[2]; }
const T& x( void ) const { return m_data[0]; }
const T& y( void ) const { return m_data[1]; }
const T& z( void ) const { return m_data[2]; }
// Arithmetic
Coordinate& operator+=( const Coordinate& rhs ) {
m_data += rhs.m_data;
return *this;
}
const Coordinate& operator+( const Coordinate& rhs ) {
return Coordinate(*this) += rhs;
}
Coordinate& operator-=( const Coordinate& rhs ) {
m_data -= rhs.m_data;
return *this;
}
const Coordinate& operator-( const Coordinate& rhs ) {
return Coordinate(*this) -= rhs;
}
Coordinate operator*( T rhs ) {
Coordinate result( *this );
for( auto& v : result.m_data ) v *= rhs;
return std::move(result);
}
friend Coordinate operator*( T lhs, Coordinate rhs );
friend std::ostream& operator<<( std::ostream& os, const Coordinate& rhs );
private:
std::valarray<T> m_data;
};