|
@@ -1,275 +1,94 @@
|
|
|
#ifndef VEC2_H
|
|
#ifndef VEC2_H
|
|
|
#define VEC2_H
|
|
#define VEC2_H
|
|
|
|
|
|
|
|
-struct vec2 {
|
|
|
|
|
- double x, y;
|
|
|
|
|
-};
|
|
|
|
|
|
|
|
|
|
-struct vec2 vec2(double x, double y);
|
|
|
|
|
-struct vec2 vec2s(double x);
|
|
|
|
|
-
|
|
|
|
|
-struct vec2 vec2_add(struct vec2 a, struct vec2 b);
|
|
|
|
|
-struct vec2 vec2_sub(struct vec2 a, struct vec2 b);
|
|
|
|
|
-struct vec2 vec2_mul(struct vec2 a, struct vec2 b);
|
|
|
|
|
-struct vec2 vec2_mul3(struct vec2 a, struct vec2 b, struct vec2 c);
|
|
|
|
|
-struct vec2 vec2_mul4(struct vec2 a, struct vec2 b,
|
|
|
|
|
- struct vec2 c, struct vec2 d);
|
|
|
|
|
-struct vec2 vec2_div(struct vec2 a, struct vec2 b);
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f {
|
|
|
|
|
- float x, y;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f vec2f(float x, float y);
|
|
|
|
|
-struct vec2f vec2fs(float x);
|
|
|
|
|
|
|
+#define _CREATE_DECLARATION(_NAME, _TYPE) \
|
|
|
|
|
+struct _NAME { \
|
|
|
|
|
+ _TYPE x, y; \
|
|
|
|
|
+}; \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME _NAME(_TYPE x, _TYPE y); \
|
|
|
|
|
+struct _NAME _NAME##s(_TYPE x); \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME _NAME##_add(struct _NAME a, struct _NAME b); \
|
|
|
|
|
+struct _NAME _NAME##_sub(struct _NAME a, struct _NAME b); \
|
|
|
|
|
+struct _NAME _NAME##_mul(struct _NAME a, struct _NAME b); \
|
|
|
|
|
+struct _NAME _NAME##_mul3(struct _NAME a, struct _NAME b, struct _NAME c); \
|
|
|
|
|
+struct _NAME _NAME##_mul4(struct _NAME a, struct _NAME b, \
|
|
|
|
|
+ struct _NAME c, struct _NAME d); \
|
|
|
|
|
+struct _NAME _NAME##_div(struct _NAME a, struct _NAME b);
|
|
|
|
|
+
|
|
|
|
|
+_CREATE_DECLARATION(vec2, double)
|
|
|
|
|
+_CREATE_DECLARATION(vec2f, float)
|
|
|
struct vec2f vec2_to_f(struct vec2 a);
|
|
struct vec2f vec2_to_f(struct vec2 a);
|
|
|
|
|
|
|
|
-struct vec2f vec2f_add(struct vec2f a, struct vec2f b);
|
|
|
|
|
-struct vec2f vec2f_sub(struct vec2f a, struct vec2f b);
|
|
|
|
|
-struct vec2f vec2f_mul(struct vec2f a, struct vec2f b);
|
|
|
|
|
-struct vec2f vec2f_mul3(struct vec2f a, struct vec2f b, struct vec2f c);
|
|
|
|
|
-struct vec2f vec2f_mul4(struct vec2f a, struct vec2f b,
|
|
|
|
|
- struct vec2f c, struct vec2f d);
|
|
|
|
|
-struct vec2f vec2f_div(struct vec2f a, struct vec2f b);
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i {
|
|
|
|
|
- int32_t x, y;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i vec2i(int32_t x, int32_t y);
|
|
|
|
|
-struct vec2i vec2is(int32_t x);
|
|
|
|
|
-struct vec2i vec2_to_i(struct vec2 a);
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i vec2i_add(struct vec2i a, struct vec2i b);
|
|
|
|
|
-struct vec2i vec2i_sub(struct vec2i a, struct vec2i b);
|
|
|
|
|
-struct vec2i vec2i_mul(struct vec2i a, struct vec2i b);
|
|
|
|
|
-struct vec2i vec2i_mul3(struct vec2i a, struct vec2i b, struct vec2i c);
|
|
|
|
|
-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;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+_CREATE_DECLARATION(vec2i, int32_t)
|
|
|
|
|
+_CREATE_DECLARATION(vec2ui, uint32_t)
|
|
|
|
|
|
|
|
-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);
|
|
|
|
|
|
|
+#undef _CREATE_DECLARATION
|
|
|
|
|
|
|
|
#if defined(VEC2_IMP) || defined(IMP)
|
|
#if defined(VEC2_IMP) || defined(IMP)
|
|
|
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2(double x, double y) {
|
|
|
|
|
- return (struct vec2) {.x = x, .y = y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2s(double x) {
|
|
|
|
|
- return (struct vec2) {.x = x, .y = x};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_add(struct vec2 a, struct vec2 b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2){.x = a.x + b.x, .y = a.y + b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_sub(struct vec2 a, struct vec2 b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2){.x = a.x - b.x, .y = a.y - b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_mul(struct vec2 a, struct vec2 b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2){.x = a.x * b.x, .y = a.y * b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_mul3(struct vec2 a, struct vec2 b, struct vec2 c)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2_mul(vec2_mul(a, b), c);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_mul4(struct vec2 a, struct vec2 b, struct vec2 c, struct vec2 d)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2_mul(vec2_mul3(a, b, c), d);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2
|
|
|
|
|
-vec2_div(struct vec2 a, struct vec2 b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2){.x = a.x / b.x, .y = a.y / b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f(float x, float y) {
|
|
|
|
|
- return (struct vec2f) {.x = x, .y = y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2fs(float x) {
|
|
|
|
|
- return (struct vec2f) {.x = x, .y = x};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
|
|
+#define _CREATE_DEFINITION(_NAME, _TYPE) \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME(_TYPE x, _TYPE y) { \
|
|
|
|
|
+ return (struct _NAME) {.x = x, .y = y}; \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##s(_TYPE x) { \
|
|
|
|
|
+ return (struct _NAME) {.x = x, .y = x}; \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_add(struct _NAME a, struct _NAME b) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return (struct _NAME){.x = a.x + b.x, .y = a.y + b.y}; \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_sub(struct _NAME a, struct _NAME b) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return (struct _NAME){.x = a.x - b.x, .y = a.y - b.y}; \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_mul(struct _NAME a, struct _NAME b) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return (struct _NAME){.x = a.x * b.x, .y = a.y * b.y}; \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_mul3(struct _NAME a, struct _NAME b, struct _NAME c) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return _NAME##_mul(_NAME##_mul(a, b), c); \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_mul4(struct _NAME a, struct _NAME b, struct _NAME c, struct _NAME d) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return _NAME##_mul(_NAME##_mul3(a, b, c), d); \
|
|
|
|
|
+} \
|
|
|
|
|
+ \
|
|
|
|
|
+struct _NAME \
|
|
|
|
|
+_NAME##_div(struct _NAME a, struct _NAME b) \
|
|
|
|
|
+{ \
|
|
|
|
|
+ return (struct _NAME){.x = a.x / b.x, .y = a.y / b.y}; \
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+_CREATE_DEFINITION(vec2, double)
|
|
|
|
|
+_CREATE_DEFINITION(vec2f, float)
|
|
|
struct vec2f
|
|
struct vec2f
|
|
|
vec2_to_f(struct vec2 a)
|
|
vec2_to_f(struct vec2 a)
|
|
|
{
|
|
{
|
|
|
- return (struct vec2f) { .x = (float) a.x, .y = (float) a.y };
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_add(struct vec2f a, struct vec2f b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2f){.x = a.x + b.x, .y = a.y + b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_sub(struct vec2f a, struct vec2f b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2f){.x = a.x - b.x, .y = a.y - b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_mul(struct vec2f a, struct vec2f b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2f){.x = a.x * b.x, .y = a.y * b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_mul3(struct vec2f a, struct vec2f b, struct vec2f c)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2f_mul(vec2f_mul(a, b), c);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_mul4(struct vec2f a, struct vec2f b, struct vec2f c, struct vec2f d)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2f_mul(vec2f_mul3(a, b, c), d);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2f
|
|
|
|
|
-vec2f_div(struct vec2f a, struct vec2f b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2f){.x = a.x / b.x, .y = a.y / b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i(int32_t x, int32_t y) {
|
|
|
|
|
- return (struct vec2i) {.x = x, .y = y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2is(int32_t x) {
|
|
|
|
|
- return (struct vec2i) {.x = x, .y = x};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2_to_i(struct vec2 a)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2i) { .x = (int32_t) a.x, .y = (int32_t) a.y };
|
|
|
|
|
|
|
+ return (struct vec2f) { .x= (float) a.x, .y= (float) a.y };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_add(struct vec2i a, struct vec2i b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2i){.x = a.x + b.x, .y = a.y + b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_sub(struct vec2i a, struct vec2i b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2i){.x = a.x - b.x, .y = a.y - b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_mul(struct vec2i a, struct vec2i b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2i){.x = a.x * b.x, .y = a.y * b.y};
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_mul3(struct vec2i a, struct vec2i b, struct vec2i c)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2i_mul(vec2i_mul(a, b), c);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+_CREATE_DEFINITION(vec2i, int32_t)
|
|
|
|
|
+_CREATE_DEFINITION(vec2ui, uint32_t)
|
|
|
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_mul4(struct vec2i a, struct vec2i b, struct vec2i c, struct vec2i d)
|
|
|
|
|
-{
|
|
|
|
|
- return vec2i_mul(vec2i_mul3(a, b, c), d);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-struct vec2i
|
|
|
|
|
-vec2i_div(struct vec2i a, struct vec2i b)
|
|
|
|
|
-{
|
|
|
|
|
- return (struct vec2i){.x = a.x / b.x, .y = a.y / b.y};
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-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};
|
|
|
|
|
-}
|
|
|
|
|
|
|
+#undef _CREATE_DEFINITION
|
|
|
|
|
|
|
|
#endif /* defined(VEC2_IMP) || defined(IMP) */
|
|
#endif /* defined(VEC2_IMP) || defined(IMP) */
|
|
|
|
|
|