Debian Codegraph @

src/rect.cpp

raw
1 /**
2 * Rectangle structure to make hardness maths
3
4 * Copyright (C) 2007, 2009 Sylvain Beucler
5
6 * This file is part of GNU FreeDink
7
8 * GNU FreeDink is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
12
13 * GNU FreeDink is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "rect.h"
28
29 /* For NULL: */
30 #include "stdlib.h"
31
32 int
33 rect_set(rect *rect, int left, int top, int right, int bottom)
34 {
35 if (rect == NULL)
36 return 0;
37 rect->left = left;
38 rect->top = top;
39 rect->right = right;
40 rect->bottom = bottom;
41 return 1;
42 }
43
44 int
45 rect_offset(rect *rect, int tx, int ty)
46 {
47 if (rect == NULL)
48 return 0;
49 rect->left += tx;
50 rect->top += ty;
51 rect->right += tx;
52 rect->bottom += ty;
53 return 1;
54 }
55
56 int
57 rect_copy(rect *dst, rect *src)
58 {
59 if (src == NULL || dst == NULL)
60 return 0;
61 dst->left = src->left;
62 dst->top = src->top;
63 dst->right = src->right;
64 dst->bottom = src->bottom;
65 return 1;
66 }
67
68 int
69 rect_inflate(rect *rect, int dw, int dh)
70 {
71 if (rect == NULL)
72 return 0;
73 rect->left -= dw;
74 rect->top -= dh;
75 rect->right += dw;
76 rect->bottom += dh;
77 return 1;
78 }
79
80
81 /*bool*/int inside_box(int x1, int y1, rect box)
82 {
83
84 if (x1 > box.right) return(/*false*/0);
85 if (x1 < box.left) return(/*false*/0);
86
87 if (y1 > box.bottom) return(/*false*/0);
88 if (y1 < box.top) return(/*false*/0);
89
90 return(/*true*/1);
91
92 }