-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrect.c.v
325 lines (281 loc) · 11.3 KB
/
rect.c.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// Copyright(C) 2021 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module sdl
//
// SDL_rect.h
//
// Point is the structure that defines a point (integer)
//
// See also: SDL_EnclosePoints
// See also: SDL_PointInRect
// Point is C.SDL_Point
@[typedef]
pub struct C.SDL_Point {
pub mut:
x int
y int
}
pub type Point = C.SDL_Point
// FPoint is the structure that defines a point (floating point)
//
// See also: SDL_EncloseFPoints
// See also: SDL_PointInFRect
// FPoint is C.SDL_FPoint
@[typedef]
pub struct C.SDL_FPoint {
pub mut:
x f32
y f32
}
pub type FPoint = C.SDL_FPoint
// Rect is a rectangle, with the origin at the upper left (integer).
//
// See also: SDL_RectEmpty
// See also: SDL_RectEquals
// See also: SDL_HasIntersection
// See also: SDL_IntersectRect
// See also: SDL_IntersectRectAndLine
// See also: SDL_UnionRect
// See also: SDL_EnclosePoints
// Rect is C.SDL_Rect
@[typedef]
pub struct C.SDL_Rect {
pub mut:
x int
y int
w int
h int
}
pub type Rect = C.SDL_Rect
// FRect is a rectangle, with the origin at the upper left (floating point).
//
// See also: SDL_FRectEmpty
// See also: SDL_FRectEquals
// See also: SDL_FRectEqualsEpsilon
// See also: SDL_HasIntersectionF
// See also: SDL_IntersectFRect
// See also: SDL_IntersectFRectAndLine
// See also: SDL_UnionFRect
// See also: SDL_EncloseFPoints
// See also: SDL_PointInFRect
//
// FRect is C.SDL_FRect
@[typedef]
pub struct C.SDL_FRect {
pub mut:
x f32
y f32
w f32
h f32
}
pub type FRect = C.SDL_FRect
fn C.SDL_PointInRect(const_p &C.SDL_Point, const_r &C.SDL_Rect) bool
// point_in_rect returns true if point resides inside a rectangle.
pub fn point_in_rect(const_p &Point, const_r &Rect) bool {
return C.SDL_PointInRect(const_p, const_r)
}
fn C.SDL_RectEmpty(r &C.SDL_Rect) bool
// rect_empty returns true if the rectangle has no area.
pub fn rect_empty(r &Rect) bool {
return C.SDL_RectEmpty(r)
}
fn C.SDL_RectEquals(const_a &C.SDL_Rect, const_b &C.SDL_Rect) bool
// rect_equals returns true if the two rectangles are equal.
pub fn rect_equals(const_a &Rect, const_b &Rect) bool {
return C.SDL_RectEquals(const_a, const_b)
}
fn C.SDL_HasIntersection(const_a &C.SDL_Rect, const_b &C.SDL_Rect) bool
// has_intersection determines whether two rectangles intersect.
//
// If either pointer is NULL the function will return SDL_FALSE.
//
// `A` an SDL_Rect structure representing the first rectangle
// `B` an SDL_Rect structure representing the second rectangle
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.0.
//
// See also: SDL_IntersectRect
@[inline]
pub fn has_intersection(const_a &Rect, const_b &Rect) bool {
return C.SDL_HasIntersection(const_a, const_b)
}
fn C.SDL_IntersectRect(const_a &C.SDL_Rect, const_b &C.SDL_Rect, result &C.SDL_Rect) bool
// intersect_rect calculates the intersection of two rectangles.
//
// If `result` is NULL then this function will return SDL_FALSE.
//
// `A` an SDL_Rect structure representing the first rectangle
// `B` an SDL_Rect structure representing the second rectangle
// `result` an SDL_Rect structure filled in with the intersection of
// rectangles `A` and `B`
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.0.
//
// See also: SDL_HasIntersection
pub fn intersect_rect(const_a &Rect, const_b &Rect, result &Rect) bool {
return C.SDL_IntersectRect(const_a, const_b, result)
}
fn C.SDL_UnionRect(const_a &C.SDL_Rect, const_b &C.SDL_Rect, result &C.SDL_Rect)
// union_rect calculates the union of two rectangles.
//
// `A` an SDL_Rect structure representing the first rectangle
// `B` an SDL_Rect structure representing the second rectangle
// `result` an SDL_Rect structure filled in with the union of rectangles
// `A` and `B`
//
// NOTE This function is available since SDL 2.0.0.
pub fn union_rect(const_a &Rect, const_b &Rect, result &Rect) {
C.SDL_UnionRect(const_a, const_b, result)
}
fn C.SDL_EnclosePoints(const_points &C.SDL_Point, count int, const_clip &C.SDL_Rect, result &C.SDL_Rect) bool
// enclose_points calculates a minimal rectangle enclosing a set of points.
//
// If `clip` is not NULL then only points inside of the clipping rectangle are
// considered.
//
// `points` an array of SDL_Point structures representing points to be
// enclosed
// `count` the number of structures in the `points` array
// `clip` an SDL_Rect used for clipping or NULL to enclose all points
// `result` an SDL_Rect structure filled in with the minimal enclosing
// rectangle
// returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the
// points were outside of the clipping rectangle.
//
// NOTE This function is available since SDL 2.0.0.
pub fn enclose_points(const_points &Point, count int, const_clip &Rect, result &Rect) bool {
return C.SDL_EnclosePoints(const_points, count, const_clip, result)
}
fn C.SDL_IntersectRectAndLine(rect &C.SDL_Rect, x1 &int, y1 &int, x2 &int, y2 &int) bool
// intersect_rect_and_line calculates the intersection of a rectangle and line segment.
//
// This function is used to clip a line segment to a rectangle. A line segment
// contained entirely within the rectangle or that does not intersect will
// remain unchanged. A line segment that crosses the rectangle at either or
// both ends will be clipped to the boundary of the rectangle and the new
// coordinates saved in `X1`, `Y1`, `X2`, and/or `Y2` as necessary.
//
// `rect` an SDL_Rect structure representing the rectangle to intersect
// `X1` a pointer to the starting X-coordinate of the line
// `Y1` a pointer to the starting Y-coordinate of the line
// `X2` a pointer to the ending X-coordinate of the line
// `Y2` a pointer to the ending Y-coordinate of the line
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.0.
pub fn intersect_rect_and_line(rect &Rect, x1 &int, y1 &int, x2 &int, y2 &int) bool {
return C.SDL_IntersectRectAndLine(rect, x1, y1, x2, y2)
}
// SDL_FRect versions...
fn C.SDL_PointInFRect(const_p &C.SDL_FPoint, const_r &C.SDL_FRect) bool
// point_in_frect returns true if point resides inside a rectangle.
pub fn point_in_frect(const_p &FPoint, const_r &FRect) bool {
return C.SDL_PointInFRect(const_p, const_r)
}
fn C.SDL_FRectEmpty(const_r &C.SDL_FRect) bool
// frect_empty returns true if the rectangle has no area.
pub fn frect_empty(const_r &FRect) bool {
return C.SDL_FRectEmpty(const_r)
}
fn C.SDL_FRectEqualsEpsilon(const_a &C.SDL_FRect, const_b &C.SDL_FRect, const_epsilon f32) bool
// frect_equals_epsilon returns true if the two rectangles are equal, within some given epsilon.
//
// NOTE This function is available since SDL 2.0.22.
pub fn frect_equals_epsilon(const_a &FRect, const_b &FRect, const_epsilon f32) bool {
return C.SDL_FRectEqualsEpsilon(const_a, const_b, const_epsilon)
}
fn C.SDL_FRectEquals(const_a &C.SDL_FRect, const_b &C.SDL_FRect) bool
// frect_equals returns true if the two rectangles are equal, using a default epsilon.
//
// NOTE This function is available since SDL 2.0.22.
pub fn frect_equals(const_a &FRect, const_b &FRect) bool {
return C.SDL_FRectEquals(const_a, const_b)
}
fn C.SDL_HasIntersectionF(const_a &C.SDL_FRect, const_b &C.SDL_FRect) bool
// has_intersection_f determines whether two rectangles intersect with float precision.
//
// If either pointer is NULL the function will return SDL_FALSE.
//
// `A` an SDL_FRect structure representing the first rectangle
// `B` an SDL_FRect structure representing the second rectangle
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.22.
//
// See also: SDL_IntersectRect
pub fn has_intersection_f(const_a &FRect, const_b &FRect) bool {
return C.SDL_HasIntersectionF(const_a, const_b)
}
fn C.SDL_IntersectFRect(const_a &C.SDL_FRect, const_b &C.SDL_FRect, result &C.SDL_FRect) bool
// intersect_frect calculates the intersection of two rectangles with float precision.
//
// If `result` is NULL then this function will return SDL_FALSE.
//
// `A` an SDL_FRect structure representing the first rectangle
// `B` an SDL_FRect structure representing the second rectangle
// `result` an SDL_FRect structure filled in with the intersection of
// rectangles `A` and `B`
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.22.
//
// See also: SDL_HasIntersectionF
pub fn intersect_frect(const_a &FRect, const_b &FRect, result &FRect) bool {
return C.SDL_IntersectFRect(const_a, const_b, result)
}
fn C.SDL_UnionFRect(const_a &C.SDL_FRect, const_b &C.SDL_FRect, result &C.SDL_FRect)
// union_frect calculates the union of two rectangles with float precision.
//
// `A` an SDL_FRect structure representing the first rectangle
// `B` an SDL_FRect structure representing the second rectangle
// `result` an SDL_FRect structure filled in with the union of rectangles
// `A` and `B`
//
// NOTE This function is available since SDL 2.0.22.
pub fn union_frect(const_a &FRect, const_b &FRect, result &FRect) {
C.SDL_UnionFRect(const_a, const_b, result)
}
fn C.SDL_EncloseFPoints(const_points &C.SDL_FPoint, count int, const_clip &C.SDL_FRect, result &C.SDL_FRect) bool
// enclose_f_points calculates a minimal rectangle enclosing a set of points with float
// precision.
//
// If `clip` is not NULL then only points inside of the clipping rectangle are
// considered.
//
// `points` an array of SDL_FPoint structures representing points to be
// enclosed
// `count` the number of structures in the `points` array
// `clip` an SDL_FRect used for clipping or NULL to enclose all points
// `result` an SDL_FRect structure filled in with the minimal enclosing
// rectangle
// returns SDL_TRUE if any points were enclosed or SDL_FALSE if all the
// points were outside of the clipping rectangle.
//
// NOTE This function is available since SDL 2.0.22.
pub fn enclose_f_points(const_points &FPoint, count int, const_clip &FRect, result &FRect) bool {
return C.SDL_EncloseFPoints(const_points, count, const_clip, result)
}
fn C.SDL_IntersectFRectAndLine(const_rect &C.SDL_FRect, x1 &f32, y1 &f32, x2 &f32, y2 &f32) bool
// intersect_frect_and_line calculates the intersection of a rectangle and line segment with float
// precision.
//
// This function is used to clip a line segment to a rectangle. A line segment
// contained entirely within the rectangle or that does not intersect will
// remain unchanged. A line segment that crosses the rectangle at either or
// both ends will be clipped to the boundary of the rectangle and the new
// coordinates saved in `X1`, `Y1`, `X2`, and/or `Y2` as necessary.
//
// `rect` an SDL_FRect structure representing the rectangle to intersect
// `X1` a pointer to the starting X-coordinate of the line
// `Y1` a pointer to the starting Y-coordinate of the line
// `X2` a pointer to the ending X-coordinate of the line
// `Y2` a pointer to the ending Y-coordinate of the line
// returns SDL_TRUE if there is an intersection, SDL_FALSE otherwise.
//
// NOTE This function is available since SDL 2.0.22.
pub fn intersect_frect_and_line(const_rect &FRect, x1 &f32, y1 &f32, x2 &f32, y2 &f32) bool {
return C.SDL_IntersectFRectAndLine(const_rect, x1, y1, x2, y2)
}