summaryrefslogtreecommitdiff
path: root/v2f.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-05-06 22:21:57 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-05-06 22:21:57 -0700
commit103d41a979132e3a541c622c1874de0781b2516f (patch)
treee18aa8c344bba8d0714c4fb879a3335ffd7722be /v2f.h
parentf66c8adf48a95897f3a73132c64659cb0fc6075b (diff)
v2f: add random vector within range: v2f_rand()
Diffstat (limited to 'v2f.h')
-rw-r--r--v2f.h18
1 files changed, 18 insertions, 0 deletions
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
© All Rights Reserved