A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2022 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _RECTANGLE_H_
22#define _RECTANGLE_H_
23
24#include <stdbool.h>
25
26struct rectangle
27{
28 int x, y, w, h;
29};
30
31/** Returns true if the rectangle is non-degenerate (positive width/height). */
32static inline bool rect_valid(const struct rectangle *r)
33{
34 return r->w > 0 && r->h > 0;
35}
36
37/** Returns true if ra contains rb. */
38bool rect_contains(const struct rectangle *ra, const struct rectangle *rb);
39
40/** Returns true if ra and rb overlap. */
41bool rect_overlap(const struct rectangle *ra, const struct rectangle *rb);
42
43/**
44 * Computes the biggest rectangle contained in ra and rb.
45 * Returns true if the intersection exists, and writes it to r_out.
46 *
47 * Returns false if there is no intersection, or either input
48 * rectangle is degenerate. In this case r_out may be uninitialized.
49 */
50bool rect_intersect(const struct rectangle *ra, const struct rectangle *rb,
51 struct rectangle *r_out);
52
53/**
54 * Computes the smallest rectangle containing both ra and rb.
55 *
56 * If one input is degenerate, and the other is not, the output is a
57 * copy of the non-degenerate input. If both inputs are degenerate,
58 * then the output is degenerate but is otherwise unspecified.
59 */
60void rect_union(const struct rectangle *ra, const struct rectangle *rb,
61 struct rectangle *r_out);
62
63/**
64 * Computes the result of subtracting 'rsub' from 'rect'. Up to four
65 * non-overlapping output rectangles will written to 'rects_out'; the
66 * return value is the number of rectangles written.
67 *
68 * If 'rsub' does not overlap 'rect', or if either of the inputs are
69 * degenerate, the output is a single rectangle: a copy of 'rect'.
70 */
71int rect_difference(const struct rectangle *rect,
72 const struct rectangle *rsub,
73 struct rectangle rects_out[4]);
74
75#endif /* _RECTANGLE_H_ */