From b3c245ba9b111462f2fff6178b08b486cd553f1b Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 19 Jan 2022 22:55:20 +0100 Subject: [PATCH] Float mixing --- number.c | 18 +++++++++++++++++- number.h | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/number.c b/number.c index 6785042..e6eecd1 100644 --- a/number.c +++ b/number.c @@ -144,7 +144,23 @@ DEFTYPES(64) } \ return true; \ } \ - DEFVEC(type) + DEFVEC(type) \ + type type ## _mix(type a, type b, type f) \ + { \ + return (1.0 - f) * a + b * f; \ + } \ + v2 ## type v2 ## type ## _mix(v2 ## type a, v2 ## type b, type f) \ + { \ + return (v2 ## type) {type ## _mix(a.x, b.x, f), type ## _mix(a.y, b.y, f)}; \ + } \ + v3 ## type v3 ## type ## _mix(v3 ## type a, v3 ## type b, type f) \ + { \ + return (v3 ## type) {type ## _mix(a.x, b.x, f), type ## _mix(a.y, b.y, f), type ## _mix(a.z, b.z, f)}; \ + } \ + v4 ## type v4 ## type ## _mix(v4 ## type a, v4 ## type b, type f) \ + { \ + return (v4 ## type) {type ## _mix(a.x, b.x, f), type ## _mix(a.y, b.y, f), type ## _mix(a.z, b.z, f), type ## _mix(a.w, b.w, f)}; \ + } DEFFLOAT(f32) DEFFLOAT(f64) diff --git a/number.h b/number.h index 4bca576..22676b7 100644 --- a/number.h +++ b/number.h @@ -40,6 +40,12 @@ bool read_full(int fd, char *buffer, size_t size); DEFTYP(int ## bits ## _t, s ## bits) \ DEFTYP(uint ## bits ## _t, u ## bits) +#define DEFMIX(bits) \ + f ## bits f ## bits ## _mix(f ## bits a, f ## bits b, f ## bits f); \ + v2f ## bits v2f ## bits ## _mix(v2f ## bits a, v2f ## bits b, f ## bits f); \ + v3f ## bits v3f ## bits ## _mix(v3f ## bits a, v3f ## bits b, f ## bits f); \ + v4f ## bits v4f ## bits ## _mix(v4f ## bits a, v4f ## bits b, f ## bits f); + DEFTYPES(8) DEFTYPES(16) DEFTYPES(32) @@ -51,6 +57,9 @@ typedef double f64; DEFTYP(float, f32) DEFTYP(double, f64) +DEFMIX(32) +DEFMIX(64) + #undef DEFRW #undef DEFBOX #undef DEFVEC -- 2.44.0