Ver Fonte

[vec2.h] Adding vec2ui

Vinicius Teshima há 1 ano atrás
pai
commit
056d18df8d
1 ficheiros alterados com 68 adições e 0 exclusões
  1. 68 0
      src/vec2.h

+ 68 - 0
src/vec2.h

@@ -48,6 +48,22 @@ struct vec2i vec2i_mul4(struct vec2i a, struct vec2i b,
 			struct vec2i c, struct vec2i d);
 struct vec2i vec2i_div(struct vec2i a, struct vec2i b);
 
+struct vec2ui {
+	uint32_t x, y;
+};
+
+struct vec2ui vec2ui(uint32_t x, uint32_t y);
+struct vec2ui vec2uis(uint32_t x);
+struct vec2ui vec2_to_ui(struct vec2 a);
+
+struct vec2ui vec2ui_add(struct vec2ui a, struct vec2ui b);
+struct vec2ui vec2ui_sub(struct vec2ui a, struct vec2ui b);
+struct vec2ui vec2ui_mul(struct vec2ui a, struct vec2ui b);
+struct vec2ui vec2ui_mul3(struct vec2ui a, struct vec2ui b, struct vec2ui c);
+struct vec2ui vec2ui_mul4(struct vec2ui a, struct vec2ui b,
+			struct vec2ui c, struct vec2ui d);
+struct vec2ui vec2ui_div(struct vec2ui a, struct vec2ui b);
+
 #if defined(VEC2_IMP) || defined(IMP)
 
 struct vec2
@@ -203,6 +219,58 @@ vec2i_div(struct vec2i a, struct vec2i b)
 }
 
 
+struct vec2ui
+vec2ui(uint32_t x, uint32_t y) {
+	return (struct vec2ui) {.x = x, .y = y};
+}
+
+struct vec2ui
+vec2uis(uint32_t x) {
+	return (struct vec2ui) {.x = x, .y = x};
+}
+
+struct vec2ui
+vec2_to_i(struct vec2 a)
+{
+	return (struct vec2ui) { .x = (uint32_t) a.x, .y = (uint32_t) a.y };
+}
+
+struct vec2ui
+vec2ui_add(struct vec2ui a, struct vec2ui b)
+{
+	return (struct vec2ui){.x = a.x + b.x, .y = a.y + b.y};
+}
+
+struct vec2ui
+vec2ui_sub(struct vec2ui a, struct vec2ui b)
+{
+	return (struct vec2ui){.x = a.x - b.x, .y = a.y - b.y};
+}
+
+struct vec2ui
+vec2ui_mul(struct vec2ui a, struct vec2ui b)
+{
+	return (struct vec2ui){.x = a.x * b.x, .y = a.y * b.y};
+}
+
+struct vec2ui
+vec2ui_mul3(struct vec2ui a, struct vec2ui b, struct vec2ui c)
+{
+	return vec2ui_mul(vec2ui_mul(a, b), c);
+}
+
+struct vec2ui
+vec2ui_mul4(struct vec2ui a, struct vec2ui b, struct vec2ui c, struct vec2ui d)
+{
+	return vec2ui_mul(vec2ui_mul3(a, b, c), d);
+}
+
+struct vec2ui
+vec2ui_div(struct vec2ui a, struct vec2ui b)
+{
+	return (struct vec2ui){.x = a.x / b.x, .y = a.y / b.y};
+}
+
 #endif /* defined(VEC2_IMP) || defined(IMP) */
 
 #endif	/* VEC2_H */