You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
5 months ago
|
#pragma once
|
||
|
#include "xarray.hpp"
|
||
|
|
||
|
namespace algoim::organizer
|
||
|
{
|
||
|
|
||
|
class AABB
|
||
|
{
|
||
|
public:
|
||
|
uvector3 min = uvector3(std::numeric_limits<real>::max());
|
||
|
uvector3 max = uvector3(std::numeric_limits<real>::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 intersect(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;
|
||
|
}
|
||
|
|
||
|
void normalize(const uvector3& scale, const uvector3& boundaryMin)
|
||
|
{
|
||
|
min = (min - boundaryMin) / scale;
|
||
|
max = (max - boundaryMin) / scale;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
struct MinimalPrimitiveRep {
|
||
|
tensor3 tensor;
|
||
|
AABB aabb;
|
||
|
};
|
||
|
}; // namespace algoim::organizer
|