-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.cpp
42 lines (41 loc) · 1.05 KB
/
Point.cpp
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 <cmath>
#include "Point.hpp"
namespace Engine {
Point::Point() : Point(0, 0) {}
Point::Point(float x, float y) : x(x), y(y) {}
bool Point::operator==(const Point& rhs) const {
return x == rhs.x && y == rhs.y;
}
bool Point::operator!=(const Point& rhs) const {
return !operator==(rhs);
}
Point Point::operator+(const Point& rhs) const {
return Point(x + rhs.x, y + rhs.y);
}
Point Point::operator-(const Point& rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
Point Point::operator*(const float& rhs) const {
return Point(x * rhs, y * rhs);
}
Point Point::operator/(const float& rhs) const {
return Point(x / rhs, y / rhs);
}
Point Point::Normalize() const {
if (Magnitude() == 0)
return Point();
return Point(x, y) / Magnitude();
}
float Point::Dot(const Point& rhs) const {
return x * rhs.x + y * rhs.y;
}
float Point::MagnitudeSquared() const {
return x * x + y * y;
}
float Point::Magnitude() const {
return sqrt(MagnitudeSquared());
};
Point operator*(const float& lhs, const Point& rhs) {
return rhs * lhs;
}
}