diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-11 23:26:33 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-11 23:26:33 +0100 |
| commit | 3f2af32442b9384d316651d42ad35945533dc39e (patch) | |
| tree | 90a163eb546b7b11de5a0341a71950f6726c4032 /src/util.h | |
| parent | 2907d743760f74a01a77dca91c4f74ac849517b5 (diff) | |
Add timespec utils
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -6,7 +6,7 @@ #include <stdbool.h> #include <stdio.h> -#define unreachable() log_panic("Unreachable code"); +#define unreachable() log_panic("The impossible happened"); // Color representation normalized to [0, 1] // @@ -25,14 +25,29 @@ static inline color_t color_rgb(int r, int g, int b) return color_rgba(r, g, b, 255); } +static inline color_t color_hex(unsigned int h) +{ + return color_rgb((h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff); +} + char *color_to_string(color_t *color); void color_print(FILE *stream, color_t *color); +const struct timespec timespec_from_ms(long ms); + +const long timespec_to_ms(struct timespec ts); + struct timespec timespec_diff(struct timespec a, struct timespec b); +struct timespec timespec_add(struct timespec a, struct timespec b); + +struct timespec timespec_div(struct timespec ts, int n); + bool timespec_greater(struct timespec a, struct timespec b); +bool timespec_zero(struct timespec ts); + void timespec_print(FILE *stream, struct timespec *ts); // Check if point (px, py) is inside a rectangle in (x, y), (x+w, y), (x, y+h) and (w+h, y+h) |
