diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 22:21:57 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 22:21:57 -0700 |
commit | 103d41a979132e3a541c622c1874de0781b2516f (patch) | |
tree | e18aa8c344bba8d0714c4fb879a3335ffd7722be /v2f.h | |
parent | f66c8adf48a95897f3a73132c64659cb0fc6075b (diff) |
v2f: add random vector within range: v2f_rand()
Diffstat (limited to 'v2f.h')
-rw-r--r-- | v2f.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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 |