Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_Rect2D.c
Go to the documentation of this file.
1/*
2Class for generic rectangle operations.
3*/
4
6{
7 /*
8 Y axis
9 ^
10 | x---------p1
11 | | |
12 | | |
13 | | |
14 | p0--------x
15 |
16 --X--------------------> X Axis
17 |
18 */
19
20 vector p0; // lowest point
21 vector p1; // highest point, p1[0] > p0[0], p1[1] > p0[1]
22
23
24 //-------------------------------------------------------------------------------------
25 static SCR_Rect2D FromPoints(vector lowerPoint, vector higherPoint)
26 {
27 SCR_Rect2D r = new SCR_Rect2D();
28 r.p0 = lowerPoint;
29 r.p1 = higherPoint;
30 return r;
31 }
32
33
34 //-------------------------------------------------------------------------------------
35 static SCR_Rect2D FromPosAndSize(vector pos, vector size)
36 {
37 SCR_Rect2D r = new SCR_Rect2D();
38
39 r.p0[0] = pos[0];
40 r.p0[1] = pos[1];
41 r.p1[0] = pos[0] + size[0];
42 r.p1[1] = pos[1] + size[1];
43
44 return r;
45 }
46
47 //-------------------------------------------------------------------------------------
48 static SCR_Rect2D FromRect(SCR_Rect2D other)
49 {
50 SCR_Rect2D r = new SCR_Rect2D();
51
52 r.p0 = other.p0;
53 r.p1 = other.p1;
54
55 return r;
56 }
57
58
59 //-------------------------------------------------------------------------------------
60 // True when other Rect is fully inside this rect or it at its edge
61 bool HasInside(SCR_Rect2D other)
62 {
63 return (other.p0[0] >= p0[0]) &&
64 (other.p0[1] >= p0[1]) &&
65 (other.p1[0] <= p1[0]) &&
66 (other.p1[1] <= p1[1]);
67 }
68
69 //-------------------------------------------------------------------------------------
70 // True when a point is inside this rectangle or is at its edge
71 bool HasInside(vector point)
72 {
73 float x = point[0];
74 float y = point[1];
75 return (x >= p0[0]) && (x <= p1[0]) && (y >= p0[1]) && (y <= p1[1]);
76 }
77
78 //-------------------------------------------------------------------------------------
79 // True when this and the other rects overlap
80 bool Overlaps(SCR_Rect2D other)
81 {
82 return CheckIntervalIntersection(p0[0], p1[0], other.p0[0], other.p1[0]) &&
83 CheckIntervalIntersection(p0[1], p1[1], other.p0[1], other.p1[1]);
84 }
85
86
87 //-------------------------------------------------------------------------------------
88 // Returns pos of center of rectangle
89 vector GetCenter()
90 {
91 vector v;
92
93 v[0] = 0.5 * (p0[0] + p1[0]);
94 v[1] = 0.5 * (p0[1] + p1[1]);
95
96 return v;
97 }
98
99 //-------------------------------------------------------------------------------------
100 float GetWidth()
101 {
102 return p1[0] - p0[0];
103 }
104
105 //-------------------------------------------------------------------------------------
106 float GetHeight()
107 {
108 return p1[1] - p0[1];
109 }
110
111 //-------------------------------------------------------------------------------------
112 // True when intervals [aMin, aMax] and [bMin, bMax] intersect
113 protected static bool CheckIntervalIntersection(float aMin, float aMax, float bMin, float bMax)
114 {
115 if ((bMin > aMax) || (bMax < aMin))
116 return false;
117 else
118 return true;
119 }
120
121
122 //-------------------------------------------------------------------------------------
125 {
126 p0[0] = p0[0] - delta;
127 p0[1] = p0[1] - delta;
128 p1[0] = p1[0] + delta;
129 p1[1] = p1[1] + delta;
130 return this;
131 }
132
133};
int size
float GetHeight()
SCR_Rect2D ExpandAllDirections(float delta)
This rect will be expanded in all directions by given value.
Definition SCR_Rect2D.c:124
static bool CheckIntervalIntersection(float aMin, float aMax, float bMin, float bMax)
Definition SCR_Rect2D.c:113