Skip to content

Commit 704b199

Browse files
committed
feat(util): add pixel_type operators
1 parent 08d69ff commit 704b199

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/util.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,27 @@ typedef struct tag_vertex_type {
7272
* Structure to store coordinates and an associated ARGB color
7373
*/
7474
typedef struct tag_pixel_type {
75-
vertex_type vertex; // vertex
75+
vertex_type vertex;
7676
std::uint32_t color; // ARGB 8-8-8-8 color
77+
78+
// operators
79+
inline bool operator==(const tag_pixel_type& rhs) const {
80+
return vertex == rhs.vertex;
81+
}
82+
inline bool operator!=(const tag_pixel_type& rhs) const {
83+
return vertex != rhs.vertex;
84+
}
85+
inline tag_pixel_type operator+(const tag_vertex_type& rhs) const {
86+
return {{ static_cast<std::int16_t>(vertex.x + rhs.x), static_cast<std::int16_t>(vertex.y + rhs.y) }, color };
87+
}
88+
inline tag_pixel_type operator-(const tag_vertex_type& rhs) const {
89+
return {{ static_cast<std::int16_t>(vertex.x - rhs.x), static_cast<std::int16_t>(vertex.y - rhs.y) }, color };
90+
}
91+
inline tag_pixel_type& operator+=(const tag_vertex_type& rhs) {
92+
vertex.x = static_cast<std::int16_t>(vertex.x + rhs.x);
93+
vertex.y = static_cast<std::int16_t>(vertex.y + rhs.y);
94+
return *this;
95+
}
7796
} pixel_type;
7897

7998

0 commit comments

Comments
 (0)