sead
Loading...
Searching...
No Matches
seadBoundBox.h
Go to the documentation of this file.
1#ifndef SEAD_BOUNDBOX_H_
2#define SEAD_BOUNDBOX_H_
3
4#include <math/seadVector.h>
5
6namespace sead {
7
8template <typename T>
10{
11public:
12 typedef sead::Vector2<T> Vector2;
13
14public:
16 {
18 }
19
20 BoundBox2(T x0, T y0, T x1, T y1)
21 {
22 set(x0, y0, x1, y1);
23 }
24
25 BoundBox2(const Vector2& min, const Vector2& max)
26 {
27 set(min, max);
28 }
29
30 T getSizeX() const
31 {
32 return mMax.x - mMin.x;
33 }
34
35 T getSizeY() const
36 {
37 return mMax.y - mMin.y;
38 }
39
40 T getHalfSizeX() const
41 {
42 return (mMax.x - mMin.x) / 2.0f;
43 }
44
45 T getHalfSizeY() const
46 {
47 return (mMax.y - mMin.y) / 2.0f;
48 }
49
50 const Vector2& getMin() const
51 {
52 return mMin;
53 }
54
55 const Vector2& getMax() const
56 {
57 return mMax;
58 }
59
60 Vector2 getBL() const
61 {
62 return mMin;
63 }
64
65 Vector2 getBR() const
66 {
67 return Vector2(mMax.x, mMin.y);
68 }
69
70 Vector2 getTL() const
71 {
72 return Vector2(mMin.x, mMax.y);
73 }
74
75 Vector2 getTR() const
76 {
77 return mMax;
78 }
79
80 Vector2 getCenter() const;
81 void getCenter(Vector2* p) const;
82 bool isUndef() const;
83 bool isInside(const Vector2& p) const;
84
85 void setUndef();
86 void set(T x0, T y0, T x1, T y1);
87 void set(const Vector2& min, const Vector2& max);
88 void setMin(const Vector2& min);
89 void setMax(const Vector2& max);
90 void setFromCenterAndXY(T centerX, T centerY, T sizeX, T sizeY);
91 void setFromCornerAndXY(T cornerX, T cornerY, T sizeX, T sizeY);
92 void setFromCenterAndXY(const Vector2& center, T sizeX, T sizeY) { setFromCenterAndXY(center.x, center.y, sizeX, sizeY); } // No idea why this is in the header,
93 void setFromCornerAndXY(const Vector2& corner, T sizeX, T sizeY); // but this is not.
94 void offset(T dx, T dy);
95 void offset(const Vector2& dv);
96 void scaleX(T sx);
97 void scaleY(T sy);
98
99private:
100 Vector2 mMin;
101 Vector2 mMax;
102};
103
104template <typename T>
106{
107public:
108 typedef sead::Vector3<T> Vector3;
109
110public:
112 {
114 }
115
116 BoundBox3(T x0, T y0, T z0, T x1, T y1, T z1)
117 {
118 set(x0, y0, z0, x1, y1, z1);
119 }
120
121 BoundBox3(const Vector3& min, const Vector3& max)
122 {
123 set(min, max);
124 }
125
126 T getSizeX() const
127 {
128 return mMax.x - mMin.x;
129 }
130
131 T getSizeY() const
132 {
133 return mMax.y - mMin.y;
134 }
135
136 T getSizeZ() const
137 {
138 return mMax.z - mMin.z;
139 }
140
141 T getHalfSizeX() const
142 {
143 return (mMax.x - mMin.x) / 2.0f;
144 }
145
146 T getHalfSizeY() const
147 {
148 return (mMax.y - mMin.y) / 2.0f;
149 }
150
151 T getHalfSizeZ() const
152 {
153 return (mMax.z - mMin.z) / 2.0f;
154 }
155
156 const Vector3& getMin() const
157 {
158 return mMin;
159 }
160
161 const Vector3& getMax() const
162 {
163 return mMax;
164 }
165
166 Vector3 getCenter() const;
167 void getCenter(Vector3* p) const;
168 bool isUndef() const;
169 bool isInside(const Vector3& p) const;
170
171 void setUndef();
172 void set(T x0, T y0, T z0, T x1, T y1, T z1);
173 void set(const Vector3& min, const Vector3& max);
174 void setMin(const Vector3& min);
175 void setMax(const Vector3& max);
176 void offset(T dx, T dy, T dz);
177 void offset(const Vector3& dv);
178 void scaleX(T sx);
179 void scaleY(T sy);
180 void scaleZ(T sz);
181
182private:
183 Vector3 mMin;
184 Vector3 mMax;
185};
186
189
190#ifdef cafe
191static_assert(sizeof(BoundBox2f) == 0x10, "sead::BoundBox2<T> size mismatch");
192static_assert(sizeof(BoundBox3f) == 0x18, "sead::BoundBox3<T> size mismatch");
193#endif // cafe
194
195} // namespace sead
196
197#ifdef __cplusplus
198
199#include <math/seadBoundBox.hpp>
200
201#endif // __cplusplus
202
203#endif // SEAD_BOUNDBOX_H_
Definition seadBoundBox.h:10
void setFromCenterAndXY(const Vector2 &center, T sizeX, T sizeY)
Definition seadBoundBox.h:92
Vector2 getTR() const
Definition seadBoundBox.h:75
T getSizeY() const
Definition seadBoundBox.h:35
const Vector2 & getMax() const
Definition seadBoundBox.h:55
void setFromCornerAndXY(T cornerX, T cornerY, T sizeX, T sizeY)
Definition seadBoundBox.hpp:104
void offset(const Vector2 &dv)
Definition seadBoundBox.hpp:130
Vector2 getBL() const
Definition seadBoundBox.h:60
void setUndef()
Definition seadBoundBox.hpp:39
const Vector2 & getMin() const
Definition seadBoundBox.h:50
void offset(T dx, T dy)
Definition seadBoundBox.hpp:120
T getHalfSizeX() const
Definition seadBoundBox.h:40
void set(const Vector2 &min, const Vector2 &max)
Definition seadBoundBox.hpp:74
void setFromCenterAndXY(T centerX, T centerY, T sizeX, T sizeY)
Definition seadBoundBox.hpp:96
BoundBox2()
Definition seadBoundBox.h:15
T getHalfSizeY() const
Definition seadBoundBox.h:45
Vector2 mMax
Definition seadBoundBox.h:101
bool isInside(const Vector2 &p) const
Definition seadBoundBox.hpp:32
BoundBox2(T x0, T y0, T x1, T y1)
Definition seadBoundBox.h:20
void setMin(const Vector2 &min)
Definition seadBoundBox.hpp:82
Vector2 getBR() const
Definition seadBoundBox.h:65
void setMax(const Vector2 &max)
Definition seadBoundBox.hpp:89
Vector2 getCenter() const
Definition seadBoundBox.hpp:9
void scaleY(T sy)
Definition seadBoundBox.hpp:148
void setFromCornerAndXY(const Vector2 &corner, T sizeX, T sizeY)
Definition seadBoundBox.hpp:112
void set(T x0, T y0, T x1, T y1)
Definition seadBoundBox.hpp:47
void getCenter(Vector2 *p) const
Definition seadBoundBox.hpp:17
Vector2 mMin
Definition seadBoundBox.h:100
void scaleX(T sx)
Definition seadBoundBox.hpp:137
T getSizeX() const
Definition seadBoundBox.h:30
Vector2 getTL() const
Definition seadBoundBox.h:70
BoundBox2(const Vector2 &min, const Vector2 &max)
Definition seadBoundBox.h:25
bool isUndef() const
Definition seadBoundBox.hpp:25
Definition seadBoundBox.h:106
void setMax(const Vector3 &max)
Definition seadBoundBox.hpp:252
const Vector3 & getMax() const
Definition seadBoundBox.h:161
BoundBox3(T x0, T y0, T z0, T x1, T y1, T z1)
Definition seadBoundBox.h:116
T getHalfSizeY() const
Definition seadBoundBox.h:146
T getHalfSizeX() const
Definition seadBoundBox.h:141
T getSizeX() const
Definition seadBoundBox.h:126
void scaleX(T sx)
Definition seadBoundBox.hpp:278
T getHalfSizeZ() const
Definition seadBoundBox.h:151
T getSizeY() const
Definition seadBoundBox.h:131
bool isUndef() const
Definition seadBoundBox.hpp:177
const Vector3 & getMin() const
Definition seadBoundBox.h:156
void getCenter(Vector3 *p) const
Definition seadBoundBox.hpp:168
BoundBox3(const Vector3 &min, const Vector3 &max)
Definition seadBoundBox.h:121
Vector3 mMin
Definition seadBoundBox.h:183
void scaleZ(T sz)
Definition seadBoundBox.hpp:300
void setMin(const Vector3 &min)
Definition seadBoundBox.hpp:245
Vector3 mMax
Definition seadBoundBox.h:184
bool isInside(const Vector3 &p) const
Definition seadBoundBox.hpp:184
void scaleY(T sy)
Definition seadBoundBox.hpp:289
void set(const Vector3 &min, const Vector3 &max)
Definition seadBoundBox.hpp:237
void offset(const Vector3 &dv)
Definition seadBoundBox.hpp:271
Vector3 getCenter() const
Definition seadBoundBox.hpp:159
void offset(T dx, T dy, T dz)
Definition seadBoundBox.hpp:259
BoundBox3()
Definition seadBoundBox.h:111
void set(T x0, T y0, T z0, T x1, T y1, T z1)
Definition seadBoundBox.hpp:199
T getSizeZ() const
Definition seadBoundBox.h:136
void setUndef()
Definition seadBoundBox.hpp:191
Definition seadVector.h:11
Definition seadVector.h:87
Definition seadAssert.h:44
BoundBox2< f32 > BoundBox2f
Definition seadBoundBox.h:187
BoundBox3< f32 > BoundBox3f
Definition seadBoundBox.h:188