-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinate.hpp
More file actions
39 lines (27 loc) · 2.39 KB
/
Copy pathCoordinate.hpp
File metadata and controls
39 lines (27 loc) · 2.39 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
#pragma once
#include <iostream>
struct Coordinate {
int x, y;
Coordinate& operator-() { x = -x; y = -y; return *this; }
Coordinate& operator+=(const Coordinate& other) { return *this = *this + other; }
Coordinate& operator-=(const Coordinate& other) { return *this = *this - other; }
Coordinate& operator*=(const Coordinate& other) { return *this = *this * other; }
Coordinate& operator/=(const Coordinate& other) { return *this = *this / other; }
Coordinate& operator*=(const int scalar) { return *this = *this * scalar; }
Coordinate& operator/=(const int scalar) { return *this = *this / scalar; }
bool in_bounds(const Coordinate& dimensions) const { return *this >= Coordinate{ 0, 0 } and *this < dimensions; }
friend Coordinate operator+(const Coordinate& lhs, const Coordinate& rhs) { return { lhs.x + rhs.x, lhs.y + rhs.y }; }
friend Coordinate operator-(const Coordinate& lhs, const Coordinate& rhs) { return { lhs.x - rhs.x, lhs.y - rhs.y }; }
friend Coordinate operator*(const Coordinate& lhs, const Coordinate& rhs) { return { lhs.x * rhs.x, lhs.y * rhs.y }; }
friend Coordinate operator/(const Coordinate& lhs, const Coordinate& rhs) { return { lhs.x / rhs.x, lhs.y / rhs.y }; }
friend Coordinate operator*(const Coordinate& lhs, const int rhs) { return { lhs.x * rhs, lhs.y * rhs }; }
friend Coordinate operator*(const int lhs, const Coordinate& rhs) { return rhs * lhs; }
friend Coordinate operator/(const Coordinate& lhs, const int rhs) { return { lhs.x / rhs, lhs.y / rhs }; }
friend bool operator< (const Coordinate& lhs, const Coordinate& rhs) { return lhs.x < rhs.x and lhs.y < rhs.y; }
friend bool operator<=(const Coordinate& lhs, const Coordinate& rhs) { return lhs.x <= rhs.x and lhs.y <= rhs.y; }
friend bool operator==(const Coordinate& lhs, const Coordinate& rhs) { return lhs.x == rhs.x and lhs.y == rhs.y; }
friend bool operator>=(const Coordinate& lhs, const Coordinate& rhs) { return lhs.x >= rhs.x and lhs.y >= rhs.y; }
friend bool operator> (const Coordinate& lhs, const Coordinate& rhs) { return lhs.x > rhs.x and lhs.y > rhs.y; }
friend std::wostream& operator<<(std::wostream& stream, const Coordinate& coordinate) { return stream << coordinate.x << L' ' << coordinate.y; }
friend std::wistream& operator>>(std::wistream& stream, Coordinate& coordinate) { return stream >> coordinate.x >> coordinate.y; }
};