#include <cmath>
#include <stdexcept>
#include <msp/linal/vector.h>
-#include "boundingbox.h"
-#include "ray.h"
#include "shape.h"
-#include "surfacepoint.h"
namespace Msp {
namespace Geometry {
{
if(points)
{
- points[n].position = p;
- points[n].normal = LinAl::Vector<T, D>();
- points[n].normal[i] = j;
- points[n].distance = x;
-
- if(n==1 && x<points[0].distance)
- std::swap(points[0], points[1]);
+ bool entry = (T(j)*ray.get_direction()[i]<T(0));
+ unsigned k = 0;
+ if(n>0 && entry!=points[0].entry)
+ {
+ if(entry)
+ points[1] = points[0];
+ else
+ ++k;
+ }
+ if(k<n && entry==points[k].entry)
+ --n;
+
+ points[k].position = p;
+ points[k].normal = LinAl::Vector<T, D>();
+ points[k].normal[i] = j;
+ points[k].distance = x;
+ points[k].entry = (T(j)*ray.get_direction()[i]<T(0));
}
++n;