-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxy.h
28 lines (21 loc) · 830 Bytes
/
xy.h
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
// X/Y coordinate and path manipulation.
#pragma once
#include <optional>
#include <utility>
#include <vector>
namespace pivid {
// Convenience struct for X/Y coordinate pairs.
template <typename T>
struct XY {
T x = {}, y = {};
template <typename U> XY<U> as() const { return XY<U>(x, y); }
operator bool() const { return x || y; }
bool operator==(XY const&) const = default;
auto operator<=>(XY const&) const = default;
XY operator+(XY const other) const { return {x + other.x, y + other.y}; }
XY operator-(XY const other) const { return {x - other.x, y - other.y}; }
XY operator-() const { return {-x, -y}; }
template <typename U> XY operator*(U m) const { return {x * m, y * m}; }
template <typename U> XY operator/(U d) const { return {x / d, y / d}; }
};
} // namespace pivid