#pragma once #include #ifndef SEAD_MATH_BOUND_BOX_H_ #include #endif namespace sead { template inline Vector2 BoundBox2::getCenter() const { return Vector2((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f); } template inline void BoundBox2::getCenter(Vector2* center) const { center->set((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f); } template inline bool BoundBox2::isUndef() const { return mMin.x > mMax.x || mMin.y > mMax.y; } template inline bool BoundBox2::isInside(const Vector2& p) const { return mMin.x <= p.x && p.x <= mMax.x && mMin.y <= p.y && p.y <= mMax.y; } template inline void BoundBox2::setUndef() { const T max = MathCalcCommon::maxNumber(); mMin.set(max, max); const T min = MathCalcCommon::minNumber(); mMax.set(min, min); } template inline void BoundBox2::set(T x0, T y0, T x1, T y1) { if (x0 < x1) { mMin.x = x0; mMax.x = x1; } else { mMin.x = x1; mMax.x = x0; } if (y0 < y1) { mMin.y = y0; mMax.y = y1; } else { mMin.y = y1; mMax.y = y0; } } template inline void BoundBox2::set(const Vector2& min, const Vector2& max) { mMin = min; mMax = max; } template inline void BoundBox2::setMin(const Vector2& min) { mMin = min; } template inline void BoundBox2::setMax(const Vector2& max) { mMax = max; } template inline void BoundBox2::setFromCenterAndXY(T centerX, T centerY, T sizeX, T sizeY) { mMin.set(centerX - sizeX / 2.0f, centerY - sizeY / 2.0f); mMax.set(centerX + sizeX / 2.0f, centerY + sizeY / 2.0f); } template inline void BoundBox2::setFromCornerAndXY(T cornerX, T cornerY, T sizeX, T sizeY) { mMin.set(cornerX, cornerY); mMax.set(cornerX + sizeX, cornerY + sizeY); } template inline void BoundBox2::setFromCornerAndXY(const Vector2& corner, T sizeX, T sizeY) { mMin.set(corner.x, corner.y); mMax.set(corner.x + sizeX, corner.y + sizeY); } template inline void BoundBox2::offset(T dx, T dy) { mMin.x += dx; mMin.y += dy; mMax.x += dx; mMax.y += dy; } template inline void BoundBox2::offset(const Vector2& dv) { offset(dv.x, dv.y); } template inline void BoundBox2::scaleX(T sx) { T sizeX = (mMax.x - mMin.x) * (sx / 2.0f); T centerX = (mMin.x + mMax.x) / 2.0f; mMin.x = centerX - sizeX; mMax.x = centerX + sizeX; } template inline void BoundBox2::scaleY(T sy) { T sizeY = (mMax.y - mMin.y) * (sy / 2.0f); T centerY = (mMin.y + mMax.y) / 2.0f; mMin.y = centerY - sizeY; mMax.y = centerY + sizeY; } template inline Vector3 BoundBox3::getCenter() const { return Vector3((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f, (mMin.z + mMax.z) / 2.0f); } template inline void BoundBox3::getCenter(Vector3* center) const { center->set((mMin.x + mMax.x) / 2.0f, (mMin.y + mMax.y) / 2.0f, (mMin.z + mMax.z) / 2.0f); } template inline bool BoundBox3::isUndef() const { return mMin.x > mMax.x || mMin.y > mMax.y || mMin.z > mMax.z; } template inline bool BoundBox3::isInside(const Vector3& p) const { return mMin.x <= p.x && p.x <= mMax.x && mMin.y <= p.y && p.y <= mMax.y && mMin.z <= p.z && p.z <= mMax.z; } template inline void BoundBox3::setUndef() { const T max = MathCalcCommon::maxNumber(); mMin.set(max, max, max); const T min = MathCalcCommon::minNumber(); mMax.set(min, min, min); } template inline void BoundBox3::set(T x0, T y0, T z0, T x1, T y1, T z1) { if (x0 < x1) { mMin.x = x0; mMax.x = x1; } else { mMin.x = x1; mMax.x = x0; } if (y0 < y1) { mMin.y = y0; mMax.y = y1; } else { mMin.y = y1; mMax.y = y0; } if (z0 < z1) { mMin.z = z0; mMax.z = z1; } else { mMin.z = z1; mMax.z = z0; } } template inline void BoundBox3::set(const Vector3& min, const Vector3& max) { mMin = min; mMax = max; } template inline void BoundBox3::setMin(const Vector3& min) { mMin = min; } template inline void BoundBox3::setMax(const Vector3& max) { mMax = max; } template inline void BoundBox3::offset(T dx, T dy, T dz) { mMin.x += dx; mMin.y += dy; mMin.z += dz; mMax.x += dx; mMax.y += dy; mMax.z += dz; } template inline void BoundBox3::offset(const Vector3& dv) { offset(dv.x, dv.y, dv.z); } template inline void BoundBox3::scaleX(T sx) { T sizeX = (mMax.x - mMin.x) * (sx / 2.0f); T centerX = (mMin.x + mMax.x) / 2.0f; mMin.x = centerX - sizeX; mMax.x = centerX + sizeX; } template inline void BoundBox3::scaleY(T sy) { T sizeY = (mMax.y - mMin.y) * (sy / 2.0f); T centerY = (mMin.y + mMax.y) / 2.0f; mMin.y = centerY - sizeY; mMax.y = centerY + sizeY; } template inline void BoundBox3::scaleZ(T sz) { T sizeZ = (mMax.z - mMin.z) * (sz / 2.0f); T centerZ = (mMin.z + mMax.z) / 2.0f; mMin.z = centerZ - sizeZ; mMax.z = centerZ + sizeZ; } } // namespace sead