From 644ab878cf20224d7e5f675089f009e796a9a8fe Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 22:20:50 -0700 Subject: v2f: add bi-linear interpolation: v2f_bilerp() --- v2f.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'v2f.h') diff --git a/v2f.h b/v2f.h index 4cbabd4..382b5b0 100644 --- a/v2f.h +++ b/v2f.h @@ -222,4 +222,32 @@ static inline v2f_t * v2f_nlerp(v2f_t *res, const v2f_t *a, const v2f_t *b, floa return res; } + +/* + * 1 ab-------bb + * | | | + * | | | + * | | | + * 0 aa-------ba + * t_x: 0---------1 + * ^ + * t_y + */ +static inline v2f_t _v2f_bilerp(const v2f_t *aa, const v2f_t *ab, const v2f_t *ba, const v2f_t *bb, float t_x, float t_y) +{ + v2f_t xa = _v2f_lerp(aa, ba, t_x); + v2f_t xb = _v2f_lerp(ab, bb, t_x); + + return _v2f_lerp(&xa, &xb, t_y); +} + + +static inline v2f_t * v2f_bilerp(v2f_t *res, const v2f_t *aa, const v2f_t *ab, const v2f_t *ba, const v2f_t *bb, float t_x, float t_y) +{ + if (_v2f_allocated(&res)) + *res = _v2f_bilerp(aa, ab, ba, bb, t_x, t_y); + + return res; +} + #endif -- cgit v1.2.3