Skip to content

Commit 08d69ff

Browse files
committed
refactor(util): improve vertex_type operators
1 parent de7c707 commit 08d69ff

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/util.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,26 @@ typedef struct tag_vertex_type {
4444
std::int16_t x;
4545
std::int16_t y;
4646

47-
bool operator==(const tag_vertex_type& o) {
48-
return (x == o.x) && (y == o.y);
47+
// operators
48+
inline bool operator==(const tag_vertex_type& rhs) const {
49+
return (x == rhs.x) && (y == rhs.y);
4950
}
50-
bool operator!=(const tag_vertex_type& o) {
51-
return (x != o.x) || (y != o.y);
51+
inline bool operator!=(const tag_vertex_type& rhs) const {
52+
return (x != rhs.x) || (y != rhs.y);
5253
}
53-
tag_vertex_type operator+(const tag_vertex_type& o) {
54-
return { static_cast<std::int16_t>(x + o.x), static_cast<std::int16_t>(y + o.y) };
54+
inline bool operator<(const tag_vertex_type& rhs) const {
55+
return (y < rhs.y) || ((y == rhs.y) && (x < rhs.x));
5556
}
56-
tag_vertex_type operator-(const tag_vertex_type& o) {
57-
return { static_cast<std::int16_t>(x - o.x), static_cast<std::int16_t>(y - o.y) };
57+
inline tag_vertex_type operator+(const tag_vertex_type& rhs) const {
58+
return { static_cast<std::int16_t>(x + rhs.x), static_cast<std::int16_t>(y + rhs.y) };
59+
}
60+
inline tag_vertex_type operator-(const tag_vertex_type& rhs) const {
61+
return { static_cast<std::int16_t>(x - rhs.x), static_cast<std::int16_t>(y - rhs.y) };
62+
}
63+
inline tag_vertex_type& operator+=(const tag_vertex_type& rhs) {
64+
x = static_cast<std::int16_t>(x + rhs.x);
65+
y = static_cast<std::int16_t>(y + rhs.y);
66+
return *this;
5867
}
5968
} vertex_type;
6069

0 commit comments

Comments
 (0)