From 86f26e03952d306c3b971a7919a7e1f89883ce47 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 21:08:40 -0700 Subject: v3f: add nearest integrals: v3f_ceil()/v3f_floor() --- v3f.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'v3f.h') diff --git a/v3f.h b/v3f.h index d169e76..9c1d6e4 100644 --- a/v3f.h +++ b/v3f.h @@ -316,4 +316,41 @@ static inline v3f_t * v3f_rand(v3f_t *res, const v3f_t *min, const v3f_t *max) } +static inline v3f_t _v3f_ceil(const v3f_t *v) +{ + return (v3f_t){ + .x = ceilf(v->x), + .y = ceilf(v->y), + .z = ceilf(v->z), + }; +} + + +static inline v3f_t * v3f_ceil(v3f_t *res, const v3f_t *v) +{ + if (_v3f_allocated(&res)) + *res = _v3f_ceil(v); + + return res; +} + + +static inline v3f_t _v3f_floor(const v3f_t *v) +{ + return (v3f_t){ + .x = floorf(v->x), + .y = floorf(v->y), + .z = floorf(v->z), + }; +} + + +static inline v3f_t * v3f_floor(v3f_t *res, const v3f_t *v) +{ + if (_v3f_allocated(&res)) + *res = _v3f_floor(v); + + return res; +} + #endif -- cgit v1.2.3