-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpos.hpp
88 lines (71 loc) · 1.69 KB
/
pos.hpp
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
#pragma once
#include <cmath>
class pos {
private:
double X, Y;
public:
void SetPos(double X, double Y) {
this->X = X;
this->Y = Y;
}
void SetX(double X) {
this->X = X;
}
void SetY(double Y) {
this->Y = Y;
}
void AddPos(double X, double Y) {
this->X += X;
this->Y += Y;
}
void AddX(double X) {
this->X += X;
}
void AddY(double Y) {
this->Y += Y;
}
double GetX() {
return this->X;
}
double GetY() {
return this->Y;
}
/*
* Mode 0:四捨五入 1:切り捨て 2:切り上げ
*/
long GetXInt(int Mode = 0) {
switch (Mode) {
case 0: // 四捨五入
return (long)std::round(this->X);
case 1: // 切り捨て
return (long)std::floor(this->X);
case 2: // 切り上げ
return (long)std::ceil(this->X);
}
return (long)std::round(this->X);
}
/*
* Mode 0:四捨五入 1:切り捨て 2:切り上げ
*/
long GetYInt(int Mode = 0) {
switch (Mode) {
case 0: // 四捨五入
return (long)std::round(this->Y);
case 1: // 切り捨て
return (long)std::floor(this->Y);
case 2: // 切り上げ
return (long)std::ceil(this->Y);
}
return (long)std::round(this->Y);
}
pos(double X = 0.0, double Y = 0.0) {
this->SetPos(X, Y);
}
};
// 2点間の距離
static double Distance2d(pos Pos1, pos Pos2) {
return std::sqrt(
std::pow(Pos1.GetX() - Pos2.GetX(), 2) +
std::pow(Pos1.GetY() - Pos2.GetY(), 2)
);
}