-
-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathRect.h
More file actions
61 lines (49 loc) · 1.31 KB
/
Copy pathRect.h
File metadata and controls
61 lines (49 loc) · 1.31 KB
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
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project Mojoc, which is a pure C Game Engine hosted on GitHub.
* The Mojoc Game Engine is licensed under the MIT License, and will continue to be iterated with coding passion.
*
* License : https://github.com/scottcgi/Mojoc/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/Mojoc
* CodeStyle: https://github.com/scottcgi/Mojoc/blob/master/Docs/CodeStyle.md
*
* Since : 2013-2-1
* Update : 2019-1-8
* Author : scott.cgi
*/
#ifndef RECT_H
#define RECT_H
#include <stdbool.h>
/**
* A rectangle made up of two diagonal vertices,
* and which are top-left and bottom-right.
*/
typedef struct
{
float left;
float top;
float right;
float bottom;
}
Rect;
/**
* Test whether one point inside rect.
*/
static inline bool ARect_TestPoint(Rect* rect, float x, float y)
{
return (x >= rect->left && x <= rect->right && y >= rect->bottom && y <= rect->top);
}
/**
* Test whether one rect intersects another rect.
*/
static inline bool ARect_TestRect(Rect* rectA, Rect* rectB)
{
return !(
rectA->right < rectB->left ||
rectA->left > rectB->right ||
rectA->top < rectB->bottom ||
rectA->bottom > rectB->top
);
}
#endif