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
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Cuboid.h"
////////////////////////////////////////////////////////////////////////////////
// cCuboid:
void cCuboid::Assign(Vector3i a_Point1, Vector3i a_Point2)
{
p1 = a_Point1;
p2 = a_Point2;
}
void cCuboid::Sort(void)
{
if (p1.x > p2.x)
{
std::swap(p1.x, p2.x);
}
if (p1.y > p2.y)
{
std::swap(p1.y, p2.y);
}
if (p1.z > p2.z)
{
std::swap(p1.z, p2.z);
}
}
int cCuboid::GetVolume(void) const
{
int DifX = abs(p2.x - p1.x) + 1;
int DifY = abs(p2.y - p1.y) + 1;
int DifZ = abs(p2.z - p1.z) + 1;
return DifX * DifY * DifZ;
}
bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const
{
ASSERT(IsSorted());
ASSERT(a_Outer.IsSorted());
return (
(p1.x >= a_Outer.p1.x) &&
(p2.x <= a_Outer.p2.x) &&
(p1.y >= a_Outer.p1.y) &&
(p2.y <= a_Outer.p2.y) &&
(p1.z >= a_Outer.p1.z) &&
(p2.z <= a_Outer.p2.z)
);
}
void cCuboid::Move(Vector3i a_Offset)
{
p1.Move(a_Offset);
p2.Move(a_Offset);
}
void cCuboid::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ)
{
if (p1.x < p2.x)
{
p1.x -= a_SubMinX;
p2.x += a_AddMaxX;
}
else
{
p2.x -= a_SubMinX;
p1.x += a_AddMaxX;
}
if (p1.y < p2.y)
{
p1.y -= a_SubMinY;
p2.y += a_AddMaxY;
}
else
{
p2.y -= a_SubMinY;
p1.y += a_AddMaxY;
}
if (p1.z < p2.z)
{
p1.z -= a_SubMinZ;
p2.z += a_AddMaxZ;
}
else
{
p2.z -= a_SubMinZ;
p1.z += a_AddMaxZ;
}
}
void cCuboid::ClampX(int a_MinX, int a_MaxX)
{
p1.x = Clamp(p1.x, a_MinX, a_MaxX);
p2.x = Clamp(p2.x, a_MinX, a_MaxX);
}
void cCuboid::ClampY(int a_MinY, int a_MaxY)
{
p1.y = Clamp(p1.y, a_MinY, a_MaxY);
p2.y = Clamp(p2.y, a_MinY, a_MaxY);
}
void cCuboid::ClampZ(int a_MinZ, int a_MaxZ)
{
p1.z = Clamp(p1.z, a_MinZ, a_MaxZ);
p2.z = Clamp(p2.z, a_MinZ, a_MaxZ);
}
bool cCuboid::IsSorted(void) const
{
return (
(p1.x <= p2.x) &&
(p1.y <= p2.y) &&
(p1.z <= p2.z)
);
}
void cCuboid::Engulf(Vector3i a_Point)
{
if (a_Point.x < p1.x)
{
p1.x = a_Point.x;
}
else if (a_Point.x > p2.x)
{
p2.x = a_Point.x;
}
if (a_Point.y < p1.y)
{
p1.y = a_Point.y;
}
else if (a_Point.y > p2.y)
{
p2.y = a_Point.y;
}
if (a_Point.z < p1.z)
{
p1.z = a_Point.z;
}
else if (a_Point.z > p2.z)
{
p2.z = a_Point.z;
}
}
|