-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.hpp
61 lines (46 loc) · 1.47 KB
/
point.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
#pragma once
#include <vector>
namespace point {
struct Point;
auto scale(const Point& p, float s) -> Point;
auto add(const Point& p, const Point& q) -> Point;
auto sub(const Point& p, const Point& q) -> Point;
auto distance(const Point& p, const Point& q) -> float;
auto equals(const point::Point& p, const point::Point& q) -> bool;
auto randomPoints(int n, const Point& mid, float r)
-> std::vector<Point>;
auto mockPoints(int n, point::Point start) -> std::vector<point::Point>;
auto shufflePoints(std::vector<Point>& ps) -> void;
auto toStr(const Point& p) -> std::string;
template <typename T>
auto toStringMany(const T& vec) -> std::string {
std::string s = "Points{\n";
for (const auto& p : vec) {
s += " " + point::toStr(p) + '\n';
}
return s + "}";
}
struct Point {
float x;
float y;
auto operator+(const Point& other) const -> Point {
return add(*this, other);
}
auto operator-(const Point& other) const -> Point {
return sub(*this, other);
}
auto operator*(float s) const -> Point {
return scale(*this, s);
}
auto operator/(float s) const -> Point {
return scale(*this, 1.f / s);
}
auto operator+=(const Point& other) -> Point& {
*this = add(*this, other);
return *this;
}
auto operator==(const Point& other) const -> bool {
return equals(*this, other);
}
};
}