1#pragma once
2
3#include <math/seadVector.h>
4
5namespace sead
6{
7template <typename T>
8struct BoundBox2
9{
10 using Vector2 = sead::Vector2<T>;
11
12 BoundBox2() { setUndef(); }
13 BoundBox2(T x0, T y0, T x1, T y1) { set(x0, y0, x1, y1); }
14 BoundBox2(const Vector2& min, const Vector2& max) : mMin(min), mMax(max) {}
15
16 T getSizeX() const { return mMax.x - mMin.x; }
17 T getSizeY() const { return mMax.y - mMin.y; }
18
19 T getHalfSizeX() const { return (mMax.x - mMin.x) / 2.0f; }
20 T getHalfSizeY() const { return (mMax.y - mMin.y) / 2.0f; }
21
22 const Vector2& getMin() const { return mMin; }
23 const Vector2& getMax() const { return mMax; }
24
25 Vector2 getTL() const { return mMin; }
26 Vector2 getTR() const { return Vector2(mMax.x, mMin.y); }
27 Vector2 getBL() const { return Vector2(mMin.x, mMax.y); }
28 Vector2 getBR() const { return mMax; }
29
30 Vector2 getCenter() const;
31 void getCenter(Vector2* p) const;
32 bool isUndef() const;
33 bool isInside(const Vector2& p) const;
34
35 void setUndef();
36 void set(T x0, T y0, T x1, T y1);
37 void set(const Vector2& min, const Vector2& max);
38 void setMin(const Vector2& min);
39 void setMax(const Vector2& max);
40 void setFromCenterAndXY(T centerX, T centerY, T sizeX, T sizeY);
41 void setFromCornerAndXY(T cornerX, T cornerY, T sizeX, T sizeY);
42 void setFromCenterAndXY(const Vector2& center, T sizeX, T sizeY)
43 {
44 setFromCenterAndXY(center.x, center.y, sizeX, sizeY);
45 }
46 void setFromCornerAndXY(const Vector2& corner, T sizeX, T sizeY);
47 void offset(T dx, T dy);
48 void offset(const Vector2& dv);
49 void scaleX(T sx);
50 void scaleY(T sy);
51
52private:
53 Vector2 mMin;
54 Vector2 mMax;
55
56 static const BoundBox2<T> cUndefined;
57};
58
59template <typename T>
60struct BoundBox3
61{
62 using Vector3 = sead::Vector3<T>;
63
64 BoundBox3() { setUndef(); }
65 BoundBox3(T x0, T y0, T z0, T x1, T y1, T z1) { set(x0, y0, z0, x1, y1, z1); }
66 BoundBox3(const Vector3& min, const Vector3& max) { set(min, max); }
67
68 T getSizeX() const { return mMax.x - mMin.x; }
69 T getSizeY() const { return mMax.y - mMin.y; }
70 T getSizeZ() const { return mMax.z - mMin.z; }
71
72 T getHalfSizeX() const { return (mMax.x - mMin.x) / 2.0f; }
73 T getHalfSizeY() const { return (mMax.y - mMin.y) / 2.0f; }
74 T getHalfSizeZ() const { return (mMax.z - mMin.z) / 2.0f; }
75
76 const Vector3& getMin() const { return mMin; }
77 const Vector3& getMax() const { return mMax; }
78
79 Vector3 getCenter() const;
80 void getCenter(Vector3* p) const;
81 bool isUndef() const;
82 bool isInside(const Vector3& p) const;
83
84 void setUndef();
85 void set(T x0, T y0, T z0, T x1, T y1, T z1);
86 void set(const Vector3& min, const Vector3& max);
87 void setMin(const Vector3& min);
88 void setMax(const Vector3& max);
89 void offset(T dx, T dy, T dz);
90 void offset(const Vector3& dv);
91 void scaleX(T sx);
92 void scaleY(T sy);
93 void scaleZ(T sz);
94
95private:
96 Vector3 mMin;
97 Vector3 mMax;
98
99 static const BoundBox3<T> cUndefined;
100};
101
102typedef BoundBox2<f32> BoundBox2f;
103typedef BoundBox3<f32> BoundBox3f;
104
105} // namespace sead
106
107#define SEAD_MATH_BOUND_BOX_H_
108#include <math/seadBoundBox.hpp>
109#undef SEAD_MATH_BOUND_BOX_H_
110