| 1 | #pragma once |
| 2 | |
| 3 | #include <math/seadMathCalcCommon.h> |
| 4 | |
| 5 | #ifndef SEAD_MATH_BOUND_BOX_H_ |
| 6 | #include <math/seadBoundBox.h> |
| 7 | #endif |
| 8 | |
| 9 | namespace sead |
| 10 | { |
| 11 | template <typename T> |
| 12 | inline Vector2<T> BoundBox2<T>::getCenter() const |
| 13 | { |
| 14 | return Vector2((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f); |
| 15 | } |
| 16 | |
| 17 | template <typename T> |
| 18 | inline void BoundBox2<T>::getCenter(Vector2* center) const |
| 19 | { |
| 20 | center->set((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f); |
| 21 | } |
| 22 | |
| 23 | template <typename T> |
| 24 | inline bool BoundBox2<T>::isUndef() const |
| 25 | { |
| 26 | return mMin.x > mMax.x || mMin.y > mMax.y; |
| 27 | } |
| 28 | |
| 29 | template <typename T> |
| 30 | inline bool BoundBox2<T>::isInside(const Vector2& p) const |
| 31 | { |
| 32 | return mMin.x <= p.x && p.x <= mMax.x && mMin.y <= p.y && p.y <= mMax.y; |
| 33 | } |
| 34 | |
| 35 | template <typename T> |
| 36 | inline void BoundBox2<T>::setUndef() |
| 37 | { |
| 38 | const T max = MathCalcCommon<T>::maxNumber(); |
| 39 | mMin.set(max, max); |
| 40 | const T min = MathCalcCommon<T>::minNumber(); |
| 41 | mMax.set(min, min); |
| 42 | } |
| 43 | |
| 44 | template <typename T> |
| 45 | inline void BoundBox2<T>::set(T x0, T y0, T x1, T y1) |
| 46 | { |
| 47 | if (x0 < x1) |
| 48 | { |
| 49 | mMin.x = x0; |
| 50 | mMax.x = x1; |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | mMin.x = x1; |
| 55 | mMax.x = x0; |
| 56 | } |
| 57 | |
| 58 | if (y0 < y1) |
| 59 | { |
| 60 | mMin.y = y0; |
| 61 | mMax.y = y1; |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | mMin.y = y1; |
| 66 | mMax.y = y0; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | template <typename T> |
| 71 | inline void BoundBox2<T>::set(const Vector2& min, const Vector2& max) |
| 72 | { |
| 73 | mMin = min; |
| 74 | mMax = max; |
| 75 | } |
| 76 | |
| 77 | template <typename T> |
| 78 | inline void BoundBox2<T>::setMin(const Vector2& min) |
| 79 | { |
| 80 | mMin = min; |
| 81 | } |
| 82 | |
| 83 | template <typename T> |
| 84 | inline void BoundBox2<T>::setMax(const Vector2& max) |
| 85 | { |
| 86 | mMax = max; |
| 87 | } |
| 88 | |
| 89 | template <typename T> |
| 90 | inline void BoundBox2<T>::setFromCenterAndXY(T centerX, T centerY, T sizeX, T sizeY) |
| 91 | { |
| 92 | mMin.set(centerX - sizeX / 2.0f, centerY - sizeY / 2.0f); |
| 93 | mMax.set(centerX + sizeX / 2.0f, centerY + sizeY / 2.0f); |
| 94 | } |
| 95 | |
| 96 | template <typename T> |
| 97 | inline void BoundBox2<T>::setFromCornerAndXY(T cornerX, T cornerY, T sizeX, T sizeY) |
| 98 | { |
| 99 | mMin.set(cornerX, cornerY); |
| 100 | mMax.set(cornerX + sizeX, cornerY + sizeY); |
| 101 | } |
| 102 | |
| 103 | template <typename T> |
| 104 | inline void BoundBox2<T>::setFromCornerAndXY(const Vector2& corner, T sizeX, T sizeY) |
| 105 | { |
| 106 | mMin.set(corner.x, corner.y); |
| 107 | mMax.set(corner.x + sizeX, corner.y + sizeY); |
| 108 | } |
| 109 | |
| 110 | template <typename T> |
| 111 | inline void BoundBox2<T>::offset(T dx, T dy) |
| 112 | { |
| 113 | mMin.x += dx; |
| 114 | mMin.y += dy; |
| 115 | mMax.x += dx; |
| 116 | mMax.y += dy; |
| 117 | } |
| 118 | |
| 119 | template <typename T> |
| 120 | inline void BoundBox2<T>::offset(const Vector2& dv) |
| 121 | { |
| 122 | offset(dv.x, dv.y); |
| 123 | } |
| 124 | |
| 125 | template <typename T> |
| 126 | inline void BoundBox2<T>::scaleX(T sx) |
| 127 | { |
| 128 | T sizeX = (mMax.x - mMin.x) * (sx / 2.0f); |
| 129 | T centerX = (mMin.x + mMax.x) / 2.0f; |
| 130 | |
| 131 | mMin.x = centerX - sizeX; |
| 132 | mMax.x = centerX + sizeX; |
| 133 | } |
| 134 | |
| 135 | template <typename T> |
| 136 | inline void BoundBox2<T>::scaleY(T sy) |
| 137 | { |
| 138 | T sizeY = (mMax.y - mMin.y) * (sy / 2.0f); |
| 139 | T centerY = (mMin.y + mMax.y) / 2.0f; |
| 140 | |
| 141 | mMin.y = centerY - sizeY; |
| 142 | mMax.y = centerY + sizeY; |
| 143 | } |
| 144 | |
| 145 | template <typename T> |
| 146 | inline Vector3<T> BoundBox3<T>::getCenter() const |
| 147 | { |
| 148 | return Vector3((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f, (mMin.z + mMax.z) / 2.0f); |
| 149 | } |
| 150 | |
| 151 | template <typename T> |
| 152 | inline void BoundBox3<T>::getCenter(Vector3* center) const |
| 153 | { |
| 154 | center->set((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f, (mMin.z + mMax.z) / 2.0f); |
| 155 | } |
| 156 | |
| 157 | template <typename T> |
| 158 | inline bool BoundBox3<T>::isUndef() const |
| 159 | { |
| 160 | return mMin.x > mMax.x || mMin.y > mMax.y || mMin.z > mMax.z; |
| 161 | } |
| 162 | |
| 163 | template <typename T> |
| 164 | inline bool BoundBox3<T>::isInside(const Vector3& p) const |
| 165 | { |
| 166 | return mMin.x <= p.x && p.x <= mMax.x && mMin.y <= p.y && p.y <= mMax.y && mMin.z <= p.z && |
| 167 | p.z <= mMax.z; |
| 168 | } |
| 169 | |
| 170 | template <typename T> |
| 171 | inline void BoundBox3<T>::setUndef() |
| 172 | { |
| 173 | const T max = MathCalcCommon<T>::maxNumber(); |
| 174 | mMin.set(max, max, max); |
| 175 | const T min = MathCalcCommon<T>::minNumber(); |
| 176 | mMax.set(min, min, min); |
| 177 | } |
| 178 | |
| 179 | template <typename T> |
| 180 | inline void BoundBox3<T>::set(T x0, T y0, T z0, T x1, T y1, T z1) |
| 181 | { |
| 182 | if (x0 < x1) |
| 183 | { |
| 184 | mMin.x = x0; |
| 185 | mMax.x = x1; |
| 186 | } |
| 187 | else |
| 188 | { |
| 189 | mMin.x = x1; |
| 190 | mMax.x = x0; |
| 191 | } |
| 192 | |
| 193 | if (y0 < y1) |
| 194 | { |
| 195 | mMin.y = y0; |
| 196 | mMax.y = y1; |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | mMin.y = y1; |
| 201 | mMax.y = y0; |
| 202 | } |
| 203 | |
| 204 | if (z0 < z1) |
| 205 | { |
| 206 | mMin.z = z0; |
| 207 | mMax.z = z1; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | mMin.z = z1; |
| 212 | mMax.z = z0; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | template <typename T> |
| 217 | inline void BoundBox3<T>::set(const Vector3& min, const Vector3& max) |
| 218 | { |
| 219 | mMin = min; |
| 220 | mMax = max; |
| 221 | } |
| 222 | |
| 223 | template <typename T> |
| 224 | inline void BoundBox3<T>::setMin(const Vector3& min) |
| 225 | { |
| 226 | mMin = min; |
| 227 | } |
| 228 | |
| 229 | template <typename T> |
| 230 | inline void BoundBox3<T>::setMax(const Vector3& max) |
| 231 | { |
| 232 | mMax = max; |
| 233 | } |
| 234 | |
| 235 | template <typename T> |
| 236 | inline void BoundBox3<T>::offset(T dx, T dy, T dz) |
| 237 | { |
| 238 | mMin.x += dx; |
| 239 | mMin.y += dy; |
| 240 | mMin.z += dz; |
| 241 | mMax.x += dx; |
| 242 | mMax.y += dy; |
| 243 | mMax.z += dz; |
| 244 | } |
| 245 | |
| 246 | template <typename T> |
| 247 | inline void BoundBox3<T>::offset(const Vector3& dv) |
| 248 | { |
| 249 | offset(dv.x, dv.y, dv.z); |
| 250 | } |
| 251 | |
| 252 | template <typename T> |
| 253 | inline void BoundBox3<T>::scaleX(T sx) |
| 254 | { |
| 255 | T sizeX = (mMax.x - mMin.x) * (sx / 2.0f); |
| 256 | T centerX = (mMin.x + mMax.x) / 2.0f; |
| 257 | |
| 258 | mMin.x = centerX - sizeX; |
| 259 | mMax.x = centerX + sizeX; |
| 260 | } |
| 261 | |
| 262 | template <typename T> |
| 263 | inline void BoundBox3<T>::scaleY(T sy) |
| 264 | { |
| 265 | T sizeY = (mMax.y - mMin.y) * (sy / 2.0f); |
| 266 | T centerY = (mMin.y + mMax.y) / 2.0f; |
| 267 | |
| 268 | mMin.y = centerY - sizeY; |
| 269 | mMax.y = centerY + sizeY; |
| 270 | } |
| 271 | |
| 272 | template <typename T> |
| 273 | inline void BoundBox3<T>::scaleZ(T sz) |
| 274 | { |
| 275 | T sizeZ = (mMax.z - mMin.z) * (sz / 2.0f); |
| 276 | T centerZ = (mMin.z + mMax.z) / 2.0f; |
| 277 | |
| 278 | mMin.z = centerZ - sizeZ; |
| 279 | mMax.z = centerZ + sizeZ; |
| 280 | } |
| 281 | |
| 282 | } // namespace sead |
| 283 | |