diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-12 20:38:04 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-12 20:38:04 -0500 |
commit | 442bb01af8b9cbf88189a4d2368548f41149413f (patch) | |
tree | 690353a2f923432746af19fbdc92ac4516fe578f /math.cpp | |
parent | 0bd888b39af436ef28a6c9d4ab64e948d5ae99c7 (diff) |
evolution
Diffstat (limited to 'math.cpp')
-rw-r--r-- | math.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -82,6 +82,12 @@ static float randf(void) { return (float)rand() / (float)((ulong)RAND_MAX + 1); } +static float rand_gauss(void) { + // https://en.wikipedia.org/wiki/Normal_distribution#Generating_values_from_normal_distribution + float U = randf(), V = randf(); + return sqrtf(-2 * logf(U)) * cosf(TAUf * V); +} + static u32 rand_u32(void) { return ((u32)rand() & 0xfff) | ((u32)rand() & 0xfff) << 12 @@ -694,5 +700,13 @@ static void gl_quad(float x1, float y1, float x2, float y2) { glVertex2f(x2, y2); glVertex2f(x1, y2); } + +static float rects_intersect(Rect r1, Rect r2) { + if (r1.pos.x >= r2.pos.x + r2.size.x) return false; // r1 is to the right of r2 + if (r2.pos.x >= r1.pos.x + r1.size.x) return false; // r2 is to the right of r1 + if (r1.pos.y >= r2.pos.y + r2.size.y) return false; // r1 is above r2 + if (r2.pos.y >= r1.pos.y + r1.size.y) return false; // r2 is above r1 + return true; +} #endif |