1 | /* graphene-rect.h: Rectangular type |
2 | * |
3 | * SPDX-License-Identifier: MIT |
4 | * |
5 | * Copyright 2014 Emmanuele Bassi |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
8 | * of this software and associated documentation files (the "Software"), to deal |
9 | * in the Software without restriction, including without limitation the rights |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11 | * copies of the Software, and to permit persons to whom the Software is |
12 | * furnished to do so, subject to the following conditions: |
13 | * |
14 | * The above copyright notice and this permission notice shall be included in |
15 | * all copies or substantial portions of the Software. |
16 | * |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23 | * THE SOFTWARE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if !defined(GRAPHENE_H_INSIDE) && !defined(GRAPHENE_COMPILATION) |
29 | #error "Only graphene.h can be included directly." |
30 | #endif |
31 | |
32 | #include "graphene-types.h" |
33 | #include "graphene-point.h" |
34 | #include "graphene-size.h" |
35 | #include "graphene-vec2.h" |
36 | |
37 | GRAPHENE_BEGIN_DECLS |
38 | |
39 | /** |
40 | * GRAPHENE_RECT_INIT: |
41 | * @_x: the X coordinate of the origin |
42 | * @_y: the Y coordinate of the origin |
43 | * @_w: the width |
44 | * @_h: the height |
45 | * |
46 | * Initializes a #graphene_rect_t when declaring it. |
47 | * |
48 | * Since: 1.0 |
49 | */ |
50 | #define GRAPHENE_RECT_INIT(_x,_y,_w,_h) \ |
51 | (graphene_rect_t) { .origin = { .x = (_x), .y = (_y) }, .size = { .width = (_w), .height = (_h) } } |
52 | |
53 | /** |
54 | * GRAPHENE_RECT_INIT_ZERO: |
55 | * |
56 | * Initializes a #graphene_rect_t to a degenerate rectangle with an origin |
57 | * in (0, 0) and a size of 0. |
58 | * |
59 | * Since: 1.10 |
60 | */ |
61 | #define GRAPHENE_RECT_INIT_ZERO GRAPHENE_RECT_INIT (0.f, 0.f, 0.f, 0.f) |
62 | |
63 | /** |
64 | * graphene_rect_t: |
65 | * @origin: the coordinates of the origin of the rectangle |
66 | * @size: the size of the rectangle |
67 | * |
68 | * The location and size of a rectangle region. |
69 | * |
70 | * The width and height of a #graphene_rect_t can be negative; for instance, |
71 | * a #graphene_rect_t with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is |
72 | * equivalent to a #graphene_rect_t with an origin of [ 10, 10 ] and a size |
73 | * of [ -10, -10 ]. |
74 | * |
75 | * Application code can normalize rectangles using graphene_rect_normalize(); |
76 | * this function will ensure that the width and height of a rectangle are |
77 | * positive values. All functions taking a #graphene_rect_t as an argument |
78 | * will internally operate on a normalized copy; all functions returning a |
79 | * #graphene_rect_t will always return a normalized rectangle. |
80 | * |
81 | * Since: 1.0 |
82 | */ |
83 | struct _graphene_rect_t |
84 | { |
85 | graphene_point_t origin; |
86 | graphene_size_t size; |
87 | }; |
88 | |
89 | GRAPHENE_AVAILABLE_IN_1_0 |
90 | graphene_rect_t * graphene_rect_alloc (void); |
91 | GRAPHENE_AVAILABLE_IN_1_0 |
92 | void graphene_rect_free (graphene_rect_t *r); |
93 | GRAPHENE_AVAILABLE_IN_1_0 |
94 | graphene_rect_t * graphene_rect_init (graphene_rect_t *r, |
95 | float x, |
96 | float y, |
97 | float width, |
98 | float height); |
99 | GRAPHENE_AVAILABLE_IN_1_0 |
100 | graphene_rect_t * graphene_rect_init_from_rect (graphene_rect_t *r, |
101 | const graphene_rect_t *src); |
102 | |
103 | GRAPHENE_AVAILABLE_IN_1_0 |
104 | bool graphene_rect_equal (const graphene_rect_t *a, |
105 | const graphene_rect_t *b); |
106 | GRAPHENE_AVAILABLE_IN_1_0 |
107 | graphene_rect_t * graphene_rect_normalize (graphene_rect_t *r); |
108 | GRAPHENE_AVAILABLE_IN_1_4 |
109 | void graphene_rect_normalize_r (const graphene_rect_t *r, |
110 | graphene_rect_t *res); |
111 | GRAPHENE_AVAILABLE_IN_1_0 |
112 | void graphene_rect_get_center (const graphene_rect_t *r, |
113 | graphene_point_t *p); |
114 | GRAPHENE_AVAILABLE_IN_1_0 |
115 | void graphene_rect_get_top_left (const graphene_rect_t *r, |
116 | graphene_point_t *p); |
117 | GRAPHENE_AVAILABLE_IN_1_0 |
118 | void graphene_rect_get_top_right (const graphene_rect_t *r, |
119 | graphene_point_t *p); |
120 | GRAPHENE_AVAILABLE_IN_1_0 |
121 | void graphene_rect_get_bottom_right (const graphene_rect_t *r, |
122 | graphene_point_t *p); |
123 | GRAPHENE_AVAILABLE_IN_1_0 |
124 | void graphene_rect_get_bottom_left (const graphene_rect_t *r, |
125 | graphene_point_t *p); |
126 | GRAPHENE_AVAILABLE_IN_1_4 |
127 | void graphene_rect_get_vertices (const graphene_rect_t *r, |
128 | graphene_vec2_t vertices[]); |
129 | GRAPHENE_AVAILABLE_IN_1_0 |
130 | float graphene_rect_get_x (const graphene_rect_t *r); |
131 | GRAPHENE_AVAILABLE_IN_1_0 |
132 | float graphene_rect_get_y (const graphene_rect_t *r); |
133 | GRAPHENE_AVAILABLE_IN_1_0 |
134 | float graphene_rect_get_width (const graphene_rect_t *r); |
135 | GRAPHENE_AVAILABLE_IN_1_0 |
136 | float graphene_rect_get_height (const graphene_rect_t *r); |
137 | GRAPHENE_AVAILABLE_IN_1_10 |
138 | float graphene_rect_get_area (const graphene_rect_t *r); |
139 | |
140 | GRAPHENE_AVAILABLE_IN_1_0 |
141 | void graphene_rect_union (const graphene_rect_t *a, |
142 | const graphene_rect_t *b, |
143 | graphene_rect_t *res); |
144 | GRAPHENE_AVAILABLE_IN_1_0 |
145 | bool graphene_rect_intersection (const graphene_rect_t *a, |
146 | const graphene_rect_t *b, |
147 | graphene_rect_t *res); |
148 | GRAPHENE_AVAILABLE_IN_1_0 |
149 | bool graphene_rect_contains_point (const graphene_rect_t *r, |
150 | const graphene_point_t *p); |
151 | GRAPHENE_AVAILABLE_IN_1_0 |
152 | bool graphene_rect_contains_rect (const graphene_rect_t *a, |
153 | const graphene_rect_t *b); |
154 | GRAPHENE_AVAILABLE_IN_1_0 |
155 | graphene_rect_t * graphene_rect_offset (graphene_rect_t *r, |
156 | float d_x, |
157 | float d_y); |
158 | GRAPHENE_AVAILABLE_IN_1_4 |
159 | void graphene_rect_offset_r (const graphene_rect_t *r, |
160 | float d_x, |
161 | float d_y, |
162 | graphene_rect_t *res); |
163 | GRAPHENE_AVAILABLE_IN_1_0 |
164 | graphene_rect_t * graphene_rect_inset (graphene_rect_t *r, |
165 | float d_x, |
166 | float d_y); |
167 | GRAPHENE_AVAILABLE_IN_1_4 |
168 | void graphene_rect_inset_r (const graphene_rect_t *r, |
169 | float d_x, |
170 | float d_y, |
171 | graphene_rect_t *res); |
172 | GRAPHENE_DEPRECATED_IN_1_4_FOR (graphene_rect_round) |
173 | graphene_rect_t * graphene_rect_round_to_pixel (graphene_rect_t *r); |
174 | GRAPHENE_DEPRECATED_IN_1_10_FOR (graphene_rect_round_extents) |
175 | void graphene_rect_round (const graphene_rect_t *r, |
176 | graphene_rect_t *res); |
177 | GRAPHENE_AVAILABLE_IN_1_10 |
178 | void graphene_rect_round_extents (const graphene_rect_t *r, |
179 | graphene_rect_t *res); |
180 | GRAPHENE_AVAILABLE_IN_1_0 |
181 | void graphene_rect_interpolate (const graphene_rect_t *a, |
182 | const graphene_rect_t *b, |
183 | double factor, |
184 | graphene_rect_t *res); |
185 | |
186 | GRAPHENE_AVAILABLE_IN_1_4 |
187 | void graphene_rect_expand (const graphene_rect_t *r, |
188 | const graphene_point_t *p, |
189 | graphene_rect_t *res); |
190 | |
191 | GRAPHENE_AVAILABLE_IN_1_4 |
192 | const graphene_rect_t * graphene_rect_zero (void); |
193 | |
194 | GRAPHENE_AVAILABLE_IN_1_10 |
195 | void graphene_rect_scale (const graphene_rect_t *r, |
196 | float s_h, |
197 | float s_v, |
198 | graphene_rect_t *res); |
199 | |
200 | GRAPHENE_END_DECLS |
201 | |