mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-21 14:35:27 -04:00
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#ifndef OPENMC_BOUNDING_BOX_H
|
|
#define OPENMC_BOUNDING_BOX_H
|
|
|
|
#include <algorithm> // for min, max
|
|
|
|
#include "openmc/constants.h"
|
|
|
|
namespace openmc {
|
|
|
|
//==============================================================================
|
|
//! Coordinates for an axis-aligned cuboid that bounds a geometric object.
|
|
//==============================================================================
|
|
|
|
struct BoundingBox {
|
|
double xmin = -INFTY;
|
|
double xmax = INFTY;
|
|
double ymin = -INFTY;
|
|
double ymax = INFTY;
|
|
double zmin = -INFTY;
|
|
double zmax = INFTY;
|
|
|
|
inline BoundingBox operator&(const BoundingBox& other)
|
|
{
|
|
BoundingBox result = *this;
|
|
return result &= other;
|
|
}
|
|
|
|
inline BoundingBox operator|(const BoundingBox& other)
|
|
{
|
|
BoundingBox result = *this;
|
|
return result |= other;
|
|
}
|
|
|
|
// intersect operator
|
|
inline BoundingBox& operator&=(const BoundingBox& other)
|
|
{
|
|
xmin = std::max(xmin, other.xmin);
|
|
xmax = std::min(xmax, other.xmax);
|
|
ymin = std::max(ymin, other.ymin);
|
|
ymax = std::min(ymax, other.ymax);
|
|
zmin = std::max(zmin, other.zmin);
|
|
zmax = std::min(zmax, other.zmax);
|
|
return *this;
|
|
}
|
|
|
|
// union operator
|
|
inline BoundingBox& operator|=(const BoundingBox& other)
|
|
{
|
|
xmin = std::min(xmin, other.xmin);
|
|
xmax = std::max(xmax, other.xmax);
|
|
ymin = std::min(ymin, other.ymin);
|
|
ymax = std::max(ymax, other.ymax);
|
|
zmin = std::min(zmin, other.zmin);
|
|
zmax = std::max(zmax, other.zmax);
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
} // namespace openmc
|
|
|
|
#endif
|