]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/hypersphere.h
Verify that parameters make sense
[libs/math.git] / source / geometry / hypersphere.h
index ce424e141cb32bbd9e5b8ed1b59cf9aee05ed617..de028fa580d627ed06d1cb811f43b104a450ed7a 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef MSP_GEOMETRY_HYPERSPHERE_H_
 #define MSP_GEOMETRY_HYPERSPHERE_H_
 
+#include <cmath>
+#include <stdexcept>
 #include <msp/linal/vector.h>
 #include "hyperbox.h"
 #include "ray.h"
@@ -43,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
@@ -79,6 +84,8 @@ inline bool HyperSphere<T, D>::check_intersection(const Ray<T, D> &ray) const
 template<typename T, unsigned D>
 inline unsigned HyperSphere<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
 {
+       using std::sqrt;
+
        T mid = -inner_product(ray.get_direction(), ray.get_start());
        LinAl::Vector<T, D> nearest = ray.get_start()+ray.get_direction()*mid;
        T offset_sq = radius*radius-inner_product(nearest, nearest);