#include <algorithm>
#include <cmath>
+#include <stdexcept>
#include <msp/linal/vector.h>
#include "ray.h"
#include "shape.h"
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
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)
+ if(abs(point[i])>dimensions[i]/T(2))
return false;
return true;
}
for(int j=-1; j<=1; j+=2)
{
T x = (T(j)*half_dim[i]-ray.get_start()[i])/ray.get_direction()[i];
- if(x<0)
+ if(!ray.check_limits(x))
continue;
LinAl::Vector<T, D> p = ray.get_start()+ray.get_direction()*x;