-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpos.cpp
More file actions
76 lines (58 loc) · 1003 Bytes
/
pos.cpp
File metadata and controls
76 lines (58 loc) · 1003 Bytes
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
/*
* pos.cpp
*
* Created on: Sep 12, 2017
* Author: Nathan Pankowsky
*/
#include <iostream> // ostream
#include <cmath> // sqrt
#include "pos.hpp"
namespace logic {
Pos::Pos() :
m_x(0), m_y(0)
{
}
Pos::Pos(double x, double y) :
m_x(x), m_y(y)
{
}
Pos::~Pos()
{
}
Pos::Pos(const Pos &pos) :
m_x(pos.get_x()), m_y(pos.get_y())
{
}
Pos& Pos::operator=(const Pos &pos)
{
m_x = pos.get_x();
m_y = pos.get_y();
}
double Pos::get_x() const
{
return m_x;
}
void Pos::set_x(double x)
{
this->m_x = x;
}
double Pos::get_y() const
{
return m_y;
}
void Pos::set_y(double y)
{
this->m_y = y;
}
double Pos::distance(const Pos &Pos) const
{
double d_x = (m_x - Pos.get_x());
double d_y = (m_y - Pos.get_y());
return sqrt((d_x * d_x) + (d_y * d_y));
}
std::ostream& operator<<(std::ostream& os_, const logic::Pos& pos_)
{
os_ << "(" << pos_.get_x() << ", " << pos_.get_y() << ")";
return os_;
}
} /* namespace logic */