From 0018bb69e154aa326dc09f343a50ceee1e267f99 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 22:22:24 -0700 Subject: v2f: add nearest integrals: v2f_ceil()/v2f_floor() --- v2f.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'v2f.h') diff --git a/v2f.h b/v2f.h index 44a4985..5d1cbbc 100644 --- a/v2f.h +++ b/v2f.h @@ -295,4 +295,40 @@ static inline v2f_t * v2f_rand(v2f_t *res, const v2f_t *min, const v2f_t *max) return res; } + +static inline v2f_t _v2f_ceil(const v2f_t *v) +{ + return (v2f_t){ + .x = ceilf(v->x), + .y = ceilf(v->y), + }; +} + + +static inline v2f_t * v2f_ceil(v2f_t *res, const v2f_t *v) +{ + if (_v2f_allocated(&res)) + *res = _v2f_ceil(v); + + return res; +} + + +static inline v2f_t _v2f_floor(const v2f_t *v) +{ + return (v2f_t){ + .x = floorf(v->x), + .y = floorf(v->y), + }; +} + + +static inline v2f_t * v2f_floor(v2f_t *res, const v2f_t *v) +{ + if (_v2f_allocated(&res)) + *res = _v2f_floor(v); + + return res; +} + #endif -- cgit v1.2.3