#pragma once #include "xarray.hpp" namespace algoim::organizer { class AABB { public: uvector3 min = uvector3(std::numeric_limits::max()); uvector3 max = uvector3(std::numeric_limits::lowest()); AABB() = default; AABB(const uvector3& min_, const uvector3& max_) : min(min_), max(max_) {} void extend(const uvector3& p) { for (int i = 0; i < 3; ++i) { min(i) = std::min(min(i), p(i)); max(i) = std::max(max(i), p(i)); } } void extend(const AABB& aabb) { for (int i = 0; i < 3; ++i) { min(i) = std::min(min(i), aabb.min(i)); max(i) = std::max(max(i), aabb.max(i)); } } uvector3 center() const { return (min + max) / 2; } uvector3 size() const { return max - min; } real volume() const { return prod(size()); } bool isIntersect(const AABB& aabb) const { for (int i = 0; i < 3; ++i) { if (min(i) > aabb.max(i) || max(i) < aabb.min(i)) { return false; } } return true; } AABB transform01ToGlobal(const AABB& globalBoundary) const { AABB res; res.min = min * globalBoundary.size() + globalBoundary.min; res.max = max * globalBoundary.size() + globalBoundary.min; return res; } void intersect(const AABB& other) { for (int i = 0; i < 3; i++) { min(i) = std::max(min(i), other.min(i)); max(i) = std::min(max(i), other.max(i)); } } void normalize(const uvector3& scale, const uvector3& boundaryMin) { min = (min - boundaryMin) / scale; max = (max - boundaryMin) / scale; } void operator+=(const uvector3& offset) { for (int i = 0; i < 3; i++) { min(i) += offset(i); max(i) += offset(i); } } }; struct MinimalPrimitiveRep { tensor3 tensor; AABB aabb; }; }; // namespace algoim::organizer