-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpoint.h
More file actions
executable file
·73 lines (65 loc) · 1.54 KB
/
Copy pathpoint.h
File metadata and controls
executable file
·73 lines (65 loc) · 1.54 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
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include <doublecomparison.h>
#include <QPoint>
#include <cmath>
class Point
{
public:
Point() = default;
Point(RealNumber x, RealNumber y) : x_(x), y_(y) {}
Point(const QPoint& point) : x_(point.x()), y_(point.y()) {}
QPoint GetQPoint() const
{
return QPoint(std::lround(x_), std::lround(y_));
}
RealNumber GetX() const
{
return x_;
}
RealNumber GetY() const
{
return y_;
}
void SetX(RealNumber x)
{
x_ = x;
}
void SetY(RealNumber y)
{
y_ = y;
}
void Rotate(const double angle)
{
auto old_x_ = x_;
auto old_y_ = y_;
x_ = old_x_ * cos(angle) - old_y_ * sin(angle);
y_ = old_x_ * sin(angle) + old_y_ * cos(angle);
}
Point operator+(const Point& other) const
{
return {x_ + other.x_, y_ + other.y_};
}
Point operator-() const
{
return {-x_, -y_};
}
Point operator-(const Point& other) const
{
return {x_ - other.x_, y_ - other.y_};
}
Point operator*(RealNumber factor) const
{
return {x_ * factor, y_ * factor};
}
Point operator/(RealNumber divisor) const
{
return {x_ / divisor, y_ / divisor};
}
private:
RealNumber x_ = 0;
RealNumber y_ = 0;
};
RealNumber ScalarProduct(const Point& lhs, const Point& rhs);
RealNumber SkewProduct(const Point& lhs, const Point& rhs);
RealNumber SquareDistance(const Point& lhs, const Point& rhs);
RealNumber Distance(const Point& lhs, const Point& rhs);