diff options
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/Makefile.am | 20 | ||||
-rw-r--r-- | src/math/boundingbox3f.cc | 53 | ||||
-rw-r--r-- | src/math/boundingbox3f.h | 113 | ||||
-rw-r--r-- | src/math/mathlib.h | 2 |
4 files changed, 185 insertions, 3 deletions
diff --git a/src/math/Makefile.am b/src/math/Makefile.am index df180dd..d032cb4 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -1,11 +1,25 @@ METASOURCES = AUTO -libmath_la_SOURCES = axis.cc color.cc functions.cc matrix4f.cc vector2f.cc \ +libmath_la_SOURCES = \ + axis.cc \ + boundingbox3f.cc \ + color.cc \ + functions.cc \ + matrix4f.cc \ + vector2f.cc \ vector3f.cc + libmath_la_LDFLAGS = -avoid-version -no-undefined -lm noinst_LTLIBRARIES = libmath.la -noinst_HEADERS = axis.h color.h functions.h mathlib.h matrix4f.h vector2f.h \ - vector3f.h +noinst_HEADERS = \ + axis.h \ + boundingbox3f.h \ + color.h \ + functions.h \ + mathlib.h \ + matrix4f.h \ + vector2f.h \ + vector3f.h INCLUDES = -I$(top_srcdir)/src diff --git a/src/math/boundingbox3f.cc b/src/math/boundingbox3f.cc new file mode 100644 index 0000000..933d783 --- /dev/null +++ b/src/math/boundingbox3f.cc @@ -0,0 +1,53 @@ +/* + math/boundingbox3f.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "math/boundingbox3f.h" + +namespace math { + +BoundingBox3f::BoundingBox3f() : + boundingbox_min(), + boundingbox_max() +{ +} + +BoundingBox3f::BoundingBox3f(const Vector3f ¢er) : + boundingbox_min(center), + boundingbox_max(center) +{ +} + +void BoundingBox3f::assign(const BoundingBox3f & other) +{ + boundingbox_min.assign(other.boundingbox_min); + boundingbox_max.assign(other.boundingbox_max); +} + +void BoundingBox3f::assign(const Vector3f ¢er) +{ + boundingbox_min.assign(center); + boundingbox_max.assign(center); +} +void BoundingBox3f::assign(const Vector3f & min, const Vector3f & max) +{ + boundingbox_min.assign(min); + boundingbox_max.assign(max); +} + +void BoundingBox3f::assign(const float min, const float max) +{ + boundingbox_min.assign(min, min, min); + boundingbox_max.assign(max, max, max); +} + +void BoundingBox3f::clear() +{ + boundingbox_min.clear(); + boundingbox_max.clear(); +} + + +} // namespace math diff --git a/src/math/boundingbox3f.h b/src/math/boundingbox3f.h new file mode 100644 index 0000000..54b846b --- /dev/null +++ b/src/math/boundingbox3f.h @@ -0,0 +1,113 @@ +/* + math/boundingbox3f.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_MATH_BOUNDINGBOX3F_H__ +#define __INCLUDED_MATH_BOUNDINGBOX3F_H__ + +#include "math/vector3f.h" + +namespace math { + +/** + * @brief a bounding box class + */ +class BoundingBox3f { +public: + BoundingBox3f(); + BoundingBox3f(const Vector3f ¢er); + + /** + * @brief returns the minimum coordinates of the bounding box + */ + inline const Vector3f & min() const { + return boundingbox_min; + } + + /** + * @brief returns the maximum coordinates of the bounding box + */ + inline const Vector3f & max() const { + return boundingbox_max; + } + + /** + * @brief test if a point is located inside the bounding box + */ + inline const bool inside(const Vector3f & point) const { + for (size_t i =0; i < 3; i++) { + if ((point[i] < boundingbox_min[i]) || (point[i] > boundingbox_max[i])) { + return false; + } + } + return true; + } + + /** + * @brief test if a point is located outside the bounding box + */ + inline const bool outside(const Vector3f & point) const { + for (size_t i =0; i < 3; i++) { + if ((point[i] < boundingbox_min[i]) || (point[i] > boundingbox_max[i])) { + return true; + } + } + return false; + } + + void assign(const BoundingBox3f & other); + + void assign(const Vector3f & min, const Vector3f & max); + + void assign(const Vector3f ¢er); + + void assign(const float min, const float max); + + void clear(); + + /** + * @brief expand the bounding box to contain a point + */ + inline void expand(const Vector3f & point) { + for (size_t i =0; i < 3; i++) { + if (point[i] < boundingbox_min[i]) { + boundingbox_min[i] = point[i]; + } + + if (point[i] > boundingbox_max[i]) { + boundingbox_max[i] = point[i]; + } + } + } + + /** + * @brief expand the bounding box to contain another bounding box + */ + inline void expand(const Vector3f & min, const Vector3f & max) { + for (size_t i =0; i < 3; i++) { + if (min[i] < boundingbox_min[i]) { + boundingbox_min[i] = min[i]; + } + + if (max[i] > boundingbox_max[i]) { + boundingbox_max[i] = max[i]; + } + } + } + + /** + * @brief expand the bounding box to contain another bounding box + */ + inline void expand(const BoundingBox3f & other) { + expand(other.boundingbox_min, other.boundingbox_max); + } + +private: + Vector3f boundingbox_min; + Vector3f boundingbox_max; +}; + +} // namespace math +#endif // __INCLUDED_MATH_BOUNDINGBOX3F_H__ diff --git a/src/math/mathlib.h b/src/math/mathlib.h index ee1e43e..b29edee 100644 --- a/src/math/mathlib.h +++ b/src/math/mathlib.h @@ -13,11 +13,13 @@ namespace math {} #include "math/axis.h" +#include "math/boundingbox3f.h" #include "math/color.h" #include "math/matrix4f.h" #include "math/functions.h" #include "math/vector2f.h" #include "math/vector3f.h" + #endif // __INCLUDED_MATH_MATHLIB_H__ |