summaryrefslogtreecommitdiff
path: root/v2f.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-05-06 22:20:50 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-05-06 22:20:50 -0700
commit644ab878cf20224d7e5f675089f009e796a9a8fe (patch)
treea3a4f2e5d4923ba6b7c3055641c04b2d588884f0 /v2f.h
parentd5cc97b1d38ef7a54a7c1b58efd93d3d9eb371c5 (diff)
v2f: add bi-linear interpolation: v2f_bilerp()
Diffstat (limited to 'v2f.h')
-rw-r--r--v2f.h28
1 files changed, 28 insertions, 0 deletions
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
© All Rights Reserved