comparison libcore/core/maths.c @ 121:789b23e01f52

misc: reorganize hierarchy, closes #2490
author David Demelier <markand@malikania.fr>
date Mon, 05 Oct 2020 13:25:06 +0200
parents src/core/maths.c@ed1a6bb02a78
children eadfed7674ac
comparison
equal deleted inserted replaced
120:b3429b26d60d 121:789b23e01f52
1 /*
2 * maths.c -- basic maths
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include "maths.h"
20
21 bool
22 maths_is_boxed(int x, int y, unsigned int w, unsigned int h, int px, int py)
23 {
24 return px >= x &&
25 py >= y &&
26 px <= x + w &&
27 py <= y + h;
28 }
29
30 void
31 maths_centerize(int *x,
32 int *y,
33 unsigned int w,
34 unsigned int h,
35 int px,
36 int py,
37 unsigned int pw,
38 unsigned int ph)
39 {
40 if (x)
41 *x = px + (pw / 2) - (w / 2);
42 if (y)
43 *y = py + (ph / 2) - (h / 2);
44 }