]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/hyperbox.h
Verify that parameters make sense
[libs/math.git] / source / geometry / hyperbox.h
index 845ca346eaffedf3aad1a4899b54c281c9593ff9..0e4efd81995508de416d37cffd6ad12e3bbf2184 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <algorithm>
 #include <cmath>
+#include <stdexcept>
 #include <msp/linal/vector.h>
 #include "ray.h"
 #include "shape.h"
@@ -47,7 +48,11 @@ inline HyperBox<T, D>::HyperBox()
 template<typename T, unsigned D>
 inline HyperBox<T, D>::HyperBox(const LinAl::Vector<T, D> &d):
        dimensions(d)
-{ }
+{
+       for(unsigned i=0; i<D; ++i)
+               if(dimensions[i]<=T(0))
+                       throw std::invalid_argument("HyperBox::HyperBox");
+}
 
 template<typename T, unsigned D>
 inline HyperBox<T, D> *HyperBox<T, D>::clone() const
@@ -64,6 +69,8 @@ inline T HyperBox<T, D>::get_dimension(unsigned i) const
 template<typename T, unsigned D>
 inline bool HyperBox<T, D>::contains(const LinAl::Vector<T, D> &point) const
 {
+       using std::abs;
+
        for(unsigned i=0; i<D; ++i)
                if(abs(point[i])>dimensions[i]/2)
                        return false;