]> git.tdb.fi Git - libs/math.git/commitdiff
Verify that parameters make sense
authorMikko Rasa <tdb@tdb.fi>
Tue, 21 May 2013 13:35:40 +0000 (16:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 21 May 2013 13:38:17 +0000 (16:38 +0300)
source/geometry/hyperbox.h
source/geometry/hypersphere.h

index 865b968902f078b25297138786f3602fbafa9260..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
index 01aee0e57b22e2791763077aecb3e3193ea35843..de028fa580d627ed06d1cb811f43b104a450ed7a 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_GEOMETRY_HYPERSPHERE_H_
 
 #include <cmath>
+#include <stdexcept>
 #include <msp/linal/vector.h>
 #include "hyperbox.h"
 #include "ray.h"
@@ -44,7 +45,10 @@ inline HyperSphere<T, D>::HyperSphere():
 template<typename T, unsigned D>
 inline HyperSphere<T, D>::HyperSphere(T r):
        radius(r)
-{ }
+{
+       if(r<=T(0))
+               throw std::invalid_argument("HyperSphere::HyperShpere");
+}
 
 template<typename T, unsigned D>
 inline HyperSphere<T, D> *HyperSphere<T, D>::clone() const