summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h131
1 files changed, 66 insertions, 65 deletions
diff --git a/util.h b/util.h
index 4cfcc04..adf71e0 100644
--- a/util.h
+++ b/util.h
@@ -1,6 +1,7 @@
#ifndef UTIL_H_
#define UTIL_H_
+#include "base.h"
// like snprintf, but not screwed up on windows
#define str_printf(str, size, ...) (str)[(size) - 1] = '\0', snprintf((str), (size) - 1, __VA_ARGS__)
@@ -26,16 +27,16 @@
typedef struct {
float x, y;
-} v2;
+} vec2;
typedef struct {
float x, y, z, w;
-} v4;
+} vec4;
typedef struct {
double x, y;
-} v2d;
+} vec2d;
typedef struct {
- v2 pos, size;
+ vec2 pos, size;
} Rect;
// UTF-32 string
@@ -158,46 +159,46 @@ u32 rand_u32(void);
float rand_uniform(float from, float to);
float sigmoidf(float x);
i32 ceildivi32(i32 x, i32 y);
-v2 V2(float x, float y);
-v2 v2_add(v2 a, v2 b);
-v2 v2_add_const(v2 a, float c);
-v2 v2_sub(v2 a, v2 b);
-v2 v2_scale(v2 v, float s);
-v2 v2_mul(v2 a, v2 b);
-v2 v2_clamp(v2 x, v2 a, v2 b);
-float v2_dot(v2 a, v2 b);
-float v2_len(v2 v);
-v2 v2_lerp(float x, v2 a, v2 b);
-v2 v2_rotate(v2 v, float theta);
-v2 v2_normalize(v2 v);
-float v2_dist(v2 a, v2 b);
-float v2_dist_squared(v2 a, v2 b);
-void v2_print(v2 v);
-v2 v2_rand_unit(void);
-v2 v2_polar(float r, float theta);
-v4 V4(float x, float y, float z, float w);
+vec2 Vec2(float x, float y);
+vec2 vec2_add(vec2 a, vec2 b);
+vec2 vec2_add_const(vec2 a, float c);
+vec2 vec2_sub(vec2 a, vec2 b);
+vec2 vec2_scale(vec2 v, float s);
+vec2 vec2_mul(vec2 a, vec2 b);
+vec2 vec2_clamp(vec2 x, vec2 a, vec2 b);
+float vec2_dot(vec2 a, vec2 b);
+float vec2_len(vec2 v);
+vec2 vec2_lerp(float x, vec2 a, vec2 b);
+vec2 vec2_rotate(vec2 v, float theta);
+vec2 vec2_normalize(vec2 v);
+float vec2_dist(vec2 a, vec2 b);
+float vec2_dist_squared(vec2 a, vec2 b);
+void vec2_print(vec2 v);
+vec2 vec2_rand_unit(void);
+vec2 vec2_polar(float r, float theta);
+vec4 Vec4(float x, float y, float z, float w);
void rgba_u32_to_floats(u32 rgba, float floats[4]);
-v4 rgba_u32_to_v4(u32 rgba);
-u32 rgba_v4_to_u32(v4 color);
+vec4 rgba_u32_to_vec4(u32 rgba);
+u32 rgba_vec4_to_u32(vec4 color);
float rgba_brightness(u32 color);
-bool rect_contains_point_v2(v2 pos, v2 size, v2 point);
-bool centered_rect_contains_point(v2 center, v2 size, v2 point);
-Rect rect(v2 pos, v2 size);
-Rect rect_endpoints(v2 e1, v2 e2);
+bool rect_contains_point_v2(vec2 pos, vec2 size, vec2 point);
+bool centered_rect_contains_point(vec2 center, vec2 size, vec2 point);
+Rect rect(vec2 pos, vec2 size);
+Rect rect_endpoints(vec2 e1, vec2 e2);
Rect rect4(float x1, float y1, float x2, float y2);
Rect rect_xywh(float x, float y, float w, float h);
-Rect rect_centered(v2 center, v2 size);
-v2 rect_center(Rect r);
-bool rect_contains_point(Rect r, v2 point);
-Rect rect_translate(Rect r, v2 by);
+Rect rect_centered(vec2 center, vec2 size);
+vec2 rect_center(Rect r);
+bool rect_contains_point(Rect r, vec2 point);
+Rect rect_translate(Rect r, vec2 by);
void rect_coords(Rect r, float *x1, float *y1, float *x2, float *y2);
void rect_print(Rect r);
float rects_intersect(Rect r1, Rect r2);
bool rect_clip_to_rect(Rect *clipped, Rect clipper);
Rect rect_shrink(Rect r, float amount);
Rect rect_grow(Rect r, float amount);
-v4 color_rgba_to_hsva(v4 rgba);
-v4 color_hsva_to_rgba(v4 hsva);
+vec4 color_rgba_to_hsva(vec4 rgba);
+vec4 color_hsva_to_rgba(vec4 hsva);
u32 color_interpolate(float x, u32 color1, u32 color2);
int timespec_cmp(struct timespec a, struct timespec b);
bool timespec_eq(struct timespec a, struct timespec b);
@@ -278,53 +279,53 @@ u32 rand_u32(void);
float rand_uniform(float from, float to);
float sigmoidf(float x);
i32 ceildivi32(i32 x, i32 y);
-v2 V2(float x, float y);
-v2 v2_add(v2 a, v2 b);
-v2 v2_add_const(v2 a, float c);
-v2 v2_sub(v2 a, v2 b);
-v2 v2_scale(v2 v, float s);
-v2 v2_mul(v2 a, v2 b);
-v2 v2_clamp(v2 x, v2 a, v2 b);
-float v2_dot(v2 a, v2 b);
-float v2_len(v2 v);
-v2 v2_lerp(float x, v2 a, v2 b);
-v2 v2_rotate(v2 v, float theta);
-v2 v2_normalize(v2 v);
-float v2_dist(v2 a, v2 b);
-float v2_dist_squared(v2 a, v2 b);
-void v2_print(v2 v);
-v2 v2_rand_unit(void);
-v2 v2_polar(float r, float theta);
-v4 V4(float x, float y, float z, float w);
-v2d V2D(double x, double y);
+vec2 Vec2(float x, float y);
+vec2 vec2_add(vec2 a, vec2 b);
+vec2 vec2_add_const(vec2 a, float c);
+vec2 vec2_sub(vec2 a, vec2 b);
+vec2 vec2_scale(vec2 v, float s);
+vec2 vec2_mul(vec2 a, vec2 b);
+vec2 vec2_clamp(vec2 x, vec2 a, vec2 b);
+float vec2_dot(vec2 a, vec2 b);
+float vec2_len(vec2 v);
+vec2 vec2_lerp(float x, vec2 a, vec2 b);
+vec2 vec2_rotate(vec2 v, float theta);
+vec2 vec2_normalize(vec2 v);
+float vec2_dist(vec2 a, vec2 b);
+float vec2_dist_squared(vec2 a, vec2 b);
+void vec2_print(vec2 v);
+vec2 vec2_rand_unit(void);
+vec2 vec2_polar(float r, float theta);
+vec4 Vec4(float x, float y, float z, float w);
+vec2d Vec2d(double x, double y);
void rgba_u32_to_floats(u32 rgba, float floats[4]);
-v4 rgba_u32_to_v4(u32 rgba);
-u32 rgba_v4_to_u32(v4 color);
+vec4 rgba_u32_to_vec4(u32 rgba);
+u32 rgba_vec4_to_u32(vec4 color);
float rgba_brightness(u32 color);
-bool rect_contains_point_v2(v2 pos, v2 size, v2 point);
-bool centered_rect_contains_point(v2 center, v2 size, v2 point);
-Rect rect(v2 pos, v2 size);
-Rect rect_endpoints(v2 e1, v2 e2);
+bool rect_contains_point_v2(vec2 pos, vec2 size, vec2 point);
+bool centered_rect_contains_point(vec2 center, vec2 size, vec2 point);
+Rect rect(vec2 pos, vec2 size);
+Rect rect_endpoints(vec2 e1, vec2 e2);
Rect rect4(float x1, float y1, float x2, float y2);
Rect rect_xywh(float x, float y, float w, float h);
-Rect rect_centered(v2 center, v2 size);
+Rect rect_centered(vec2 center, vec2 size);
float rect_x1(Rect r);
float rect_y1(Rect r);
float rect_x2(Rect r);
float rect_y2(Rect r);
float rect_xmid(Rect r);
float rect_ymid(Rect r);
-v2 rect_center(Rect r);
-bool rect_contains_point(Rect r, v2 point);
-Rect rect_translate(Rect r, v2 by);
+vec2 rect_center(Rect r);
+bool rect_contains_point(Rect r, vec2 point);
+Rect rect_translate(Rect r, vec2 by);
void rect_coords(Rect r, float *x1, float *y1, float *x2, float *y2);
void rect_print(Rect r);
float rects_intersect(Rect r1, Rect r2);
bool rect_clip_to_rect(Rect *clipped, Rect clipper);
Rect rect_shrink(Rect r, float amount);
Rect rect_grow(Rect r, float amount);
-v4 color_rgba_to_hsva(v4 rgba);
-v4 color_hsva_to_rgba(v4 hsva);
+vec4 color_rgba_to_hsva(vec4 rgba);
+vec4 color_hsva_to_rgba(vec4 hsva);
u32 color_interpolate(float x, u32 color1, u32 color2);
int timespec_cmp(struct timespec a, struct timespec b);
bool timespec_eq(struct timespec a, struct timespec b);