namespace Msp {
namespace Geometry {
+/**
+A shape bounded by planar faces at right angles to each other. Two- and three-
+dimensional cases are Rectangle and Box, respectively.
+*/
template<typename T, unsigned D>
class HyperBox: public Shape<T, D>
{
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;
LinAl::Vector<T, D> half_dim = dimensions/T(2);
unsigned n = 0;
- T first_depth = T();
for(unsigned i=0; i<D; ++i)
{
if(!ray.get_direction()[i])
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;
points[n].position = p;
points[n].normal = LinAl::Vector<T, D>();
points[n].normal[i] = j;
- if(n==0)
- first_depth = x;
- else if(n==1 && x<first_depth)
+ points[n].distance = x;
+
+ if(n==1 && x<points[0].distance)
std::swap(points[0], points[1]);
}