#include #include "util.h" struct timespec timespec_diff(struct timespec a, struct timespec b) { bool over = (b.tv_nsec - a.tv_nsec) < 0; struct timespec diff = { .tv_sec = b.tv_sec - a.tv_sec - over, .tv_nsec = b.tv_nsec - a.tv_nsec + over * 1000000000ul, }; return diff; } bool timespec_greater(struct timespec a, struct timespec b) { return a.tv_sec > b.tv_sec || (a.tv_sec == b.tv_sec && a.tv_nsec > b.tv_nsec); } bool in_capsule(int px, int py, int x, int y, int w, int h) { assert(w >= h); int radius = h / 2; // Trivial case if (w == h) return in_circle(px, py, x + radius, y + radius, radius); // General case return in_circle(px, py, x + radius, y + radius, radius) || in_circle(px, py, x + w - radius, y + radius, radius) || in_rect(px, py, x + radius, y, w - 2 * radius, h); }