diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2021-07-03 00:49:03 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:20:20 +0200 |
| commit | 6b9f686913efc3725b2690033cd4f398e07076ba (patch) | |
| tree | e9aa91a6b9f617d78123ebe7ad272fc42a60d306 /src/util | |
| parent | c9e6ae44a9aeb89b3f48f3443d6baa80103f7445 (diff) | |
| download | jancity-6b9f686913efc3725b2690033cd4f398e07076ba.tar.gz | |
Add project source code
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/util/inc/util.h | 31 | ||||
| -rw-r--r-- | src/util/src/util.c | 10 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt new file mode 100644 index 0000000..9c808f5 --- /dev/null +++ b/src/util/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(util "src/util.c") +target_include_directories(util PUBLIC "inc") diff --git a/src/util/inc/util.h b/src/util/inc/util.h new file mode 100644 index 0000000..e42c5b2 --- /dev/null +++ b/src/util/inc/util.h @@ -0,0 +1,31 @@ +#ifndef UTIL_H +#define UTIL_H + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" +{ +#endif + +#if __STDC_VERSION__ >= 201112L +#define UTIL_STATIC_ASSERT(exp, msg) _Static_assert(exp, msg) +#else +#define UTIL_STATIC_ASSERT__(exp, l, msg) enum {static_assert##l##__ = 1 / !!(exp)} +#define UTIL_STATIC_ASSERT_(exp, l, msg) UTIL_STATIC_ASSERT__(exp, l, msg) +#define UTIL_STATIC_ASSERT(exp, msg) UTIL_STATIC_ASSERT_(exp, __LINE__, msg) +#endif + +struct util_rect +{ + unsigned long x, y; + short w, h; +}; + +bool util_collision(const struct util_rect *a, const struct util_rect *b); + +#ifdef __cplusplus +} +#endif + +#endif /* UTIL_H */ diff --git a/src/util/src/util.c b/src/util/src/util.c new file mode 100644 index 0000000..f87c14a --- /dev/null +++ b/src/util/src/util.c @@ -0,0 +1,10 @@ +#include <util.h> +#include <stdbool.h> + +bool util_collision(const struct util_rect *const a, const struct util_rect *const b) +{ + return !((a->x >= b->x + b->w) + || (b->x >= a->x + a->w) + || (a->y >= b->y + b->h) + || (b->y >= a->y + a->h)); +} |
