-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point2D.h
43 lines (39 loc) · 823 Bytes
/
Point2D.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
#include <iostream>
#include <cmath>
#include <climits>
#include <float.h>
#include <cstring>
using namespace std;
class Point2D {
private:
double x, y;
public:
// get distance between two points
double get_distance(const Point2D & p2) const {
return pow(pow(x - p2.x, 2) + pow(y - p2.y, 2), 0.5);
}
private:
bool set_x(double const new_x) {
if(DBL_MAX >= new_x && new_x >= DBL_MIN) {
x = new_x;
return true;
} else {
return false;
}
}
bool set_y(double const new_y) {
if(DBL_MAX >= new_y && new_y >= DBL_MIN) {
y = new_y;
return true;
} else {
return false;
}
}
public:
bool set_values(double const new_x, double const new_y) {
return set_y(new_y) && set_x(new_x);
}
void p_self() const {
cout << "(" << x << ", " << y << ")\n";
}
};