From 103d41a979132e3a541c622c1874de0781b2516f Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 22:21:57 -0700 Subject: v2f: add random vector within range: v2f_rand() --- v2f.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'v2f.h') diff --git a/v2f.h b/v2f.h index 93175a2..44a4985 100644 --- a/v2f.h +++ b/v2f.h @@ -277,4 +277,22 @@ static inline v2f_t * v2f_trilerp(v2f_t *res, const v2f_t *aaa, const v2f_t *aba return res; } + +static inline v2f_t _v2f_rand(const v2f_t *min, const v2f_t *max) +{ + return (v2f_t){ + .x = min->x + (float)rand() * (1.f/RAND_MAX) * (max->x - min->x), + .y = min->y + (float)rand() * (1.f/RAND_MAX) * (max->y - min->y), + }; +} + + +static inline v2f_t * v2f_rand(v2f_t *res, const v2f_t *min, const v2f_t *max) +{ + if (_v2f_allocated(&res)) + *res = _v2f_rand(min, max); + + return res; +} + #endif -- cgit v1.2.3