From df997644b68352bb23ebdd43a7ab59d8cc577fb5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 13 Jan 2020 10:01:04 -0600 Subject: [PATCH] Moving bounding box back into surface. --- include/openmc/bounding_box.h | 76 ----------------------------------- include/openmc/mesh.h | 1 - include/openmc/surface.h | 67 +++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 78 deletions(-) delete mode 100644 include/openmc/bounding_box.h diff --git a/include/openmc/bounding_box.h b/include/openmc/bounding_box.h deleted file mode 100644 index a1d16cac5..000000000 --- a/include/openmc/bounding_box.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef OPENMC_BOUNDING_BOX_H -#define OPENMC_BOUNDING_BOX_H - -#include "openmc/constants.h" -#include "openmc/position.h" - -namespace openmc { - -//============================================================================== -//! Coordinates for an axis-aligned cuboid 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; - } - - // ensure bounding box contains a point - inline void update(const Position& r) { - xmin = std::min(xmin, r.x); - xmax = std::max(xmax, r.x); - ymin = std::min(ymin, r.y); - ymax = std::max(ymax, r.y); - zmin = std::min(zmin, r.z); - zmax = std::max(zmax, r.z); - } - - // check if a point is in the box - inline bool contains(const Position& r) const { - if (r.x < xmin || r.x > xmax) { return false; } - if (r.y < ymin || r.y > ymax) { return false; } - if (r.z < zmin || r.z > zmax) { return false; } - return true; - } - -}; - -} // namespace openmc -#endif // OPENMC_BOUNDING_BOX_H diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index c458caa7d..5e16c6a62 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -12,7 +12,6 @@ #include "pugixml.hpp" #include "xtensor/xtensor.hpp" -#include "openmc/bounding_box.h" #include "openmc/particle.h" #include "openmc/position.h" diff --git a/include/openmc/surface.h b/include/openmc/surface.h index c2f461030..5ef903f52 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -11,7 +11,6 @@ #include "pugixml.hpp" #include "openmc/boundary_condition.h" -#include "openmc/bounding_box.h" #include "openmc/constants.h" #include "openmc/particle.h" #include "openmc/position.h" @@ -30,6 +29,72 @@ namespace model { extern std::vector> surfaces; } // namespace model +//============================================================================== +//! Coordinates for an axis-aligned cuboid bounding 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; + } + + // ensure bounding box contains a point + inline void update(const Position& r) { + xmin = std::min(xmin, r.x); + xmax = std::max(xmax, r.x); + ymin = std::min(ymin, r.y); + ymax = std::max(ymax, r.y); + zmin = std::min(zmin, r.z); + zmax = std::max(zmax, r.z); + } + + // check if a point is in the box + inline bool contains(const Position& r) const { + if (r.x < xmin || r.x > xmax) { return false; } + if (r.y < ymin || r.y > ymax) { return false; } + if (r.z < zmin || r.z > zmax) { return false; } + return true; + } + +}; + //============================================================================== //! A geometry primitive used to define regions of 3D space. //==============================================================================