From: Elias Fleckenstein Date: Fri, 24 Sep 2021 11:54:37 +0000 (+0200) Subject: Add vectors with 4 elements X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8bf138e90e5bacfb07853df5b17cf35bfeedf352;p=dragonstd.git Add vectors with 4 elements --- diff --git a/number.c b/number.c index 5835e9a..54a4f9f 100644 --- a/number.c +++ b/number.c @@ -76,6 +76,28 @@ bool read_full(int fd, char *buffer, size_t size) v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b) \ { \ return (v3 ## type) {a.x + b.x, a.y + b.y, a.z + b.z}; \ + } \ + bool read_v4 ## type(int fd, v4 ## type *ptr) \ + { \ + READVEC(type, 4) \ + ptr->x = buf[0]; \ + ptr->y = buf[1]; \ + ptr->z = buf[2]; \ + ptr->w = buf[3]; \ + return true; \ + } \ + bool write_v4 ## type(int fd, v4 ## type val) \ + { \ + type vec[4] = {val.x, val.y, val.z, val.w}; \ + WRITEVEC(type, 4) \ + } \ + bool v4 ## type ## _equals(v4 ## type a, v4 ## type b) \ + { \ + return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; \ + } \ + v4 ## type v4 ## type ## _add(v4 ## type a, v4 ## type b) \ + { \ + return (v4 ## type) {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; \ } #define DEFTYP(type, bits) \ diff --git a/number.h b/number.h index 57a000b..4bca576 100644 --- a/number.h +++ b/number.h @@ -24,7 +24,12 @@ bool read_full(int fd, char *buffer, size_t size); DEFRW(v3 ## type) \ DEFBOX(3 ## type) \ bool v3 ## type ## _equals(v3 ## type a, v3 ## type b); \ - v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b); + v3 ## type v3 ## type ## _add(v3 ## type a, v3 ## type b); \ + typedef struct {type x, y, z, w;} v4 ## type; \ + DEFRW(v4 ## type) \ + DEFBOX(4 ## type) \ + bool v4 ## type ## _equals(v4 ## type a, v4 ## type b); \ + v4 ## type v4 ## type ## _add(v4 ## type a, v4 ## type b); #define DEFTYP(from, to) \ typedef from to; \