- 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)
- 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));