mirror of https://github.com/CGAL/cgal
Use branchless min/max
This commit is contained in:
parent
a408a08ae7
commit
3f4d185b1d
|
|
@ -122,17 +122,16 @@ struct AABB_traits_base_2<GeomTraits,true>{
|
||||||
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903
|
FT t_near = -DBL_MAX; // std::numeric_limits<FT>::lowest(); C++1903
|
||||||
FT t_far = DBL_MAX;
|
FT t_far = DBL_MAX;
|
||||||
|
|
||||||
Construct_cartesian_const_iterator_3 construct_cartesian_const_iterator_3
|
const Construct_cartesian_const_iterator_3 construct_cartesian_const_iterator_3
|
||||||
= GeomTraits().construct_cartesian_const_iterator_3_object();
|
= GeomTraits().construct_cartesian_const_iterator_3_object();
|
||||||
Construct_source_3 construct_source_3 = GeomTraits().construct_source_3_object();
|
const Construct_source_3 construct_source_3 = GeomTraits().construct_source_3_object();
|
||||||
Construct_vector_3 construct_vector_3 = GeomTraits().construct_vector_3_object();
|
const Construct_vector_3 construct_vector_3 = GeomTraits().construct_vector_3_object();
|
||||||
const Point_3 source = construct_source_3(ray);
|
const Point_3 source = construct_source_3(ray);
|
||||||
const Vector_3 direction = construct_vector_3(ray);
|
const Vector_3 direction = construct_vector_3(ray);
|
||||||
Cartesian_const_iterator_3 source_iter = construct_cartesian_const_iterator_3(source);
|
Cartesian_const_iterator_3 source_iter = construct_cartesian_const_iterator_3(source);
|
||||||
Cartesian_const_iterator_3 direction_iter = construct_cartesian_const_iterator_3(direction);
|
Cartesian_const_iterator_3 direction_iter = construct_cartesian_const_iterator_3(direction);
|
||||||
|
|
||||||
for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) {
|
for(int i = 0; i < 3; ++i, ++source_iter, ++direction_iter) {
|
||||||
// we only use i as invariant to safe some checks
|
|
||||||
if(*direction_iter == 0) {
|
if(*direction_iter == 0) {
|
||||||
if((*source_iter < bbox.min(i)) || (*source_iter > bbox.max(i))) {
|
if((*source_iter < bbox.min(i)) || (*source_iter > bbox.max(i))) {
|
||||||
return boost::none;
|
return boost::none;
|
||||||
|
|
@ -141,17 +140,17 @@ struct AABB_traits_base_2<GeomTraits,true>{
|
||||||
FT t1 = (bbox.min(i) - *source_iter) / *direction_iter;
|
FT t1 = (bbox.min(i) - *source_iter) / *direction_iter;
|
||||||
FT t2 = (bbox.max(i) - *source_iter) / *direction_iter;
|
FT t2 = (bbox.max(i) - *source_iter) / *direction_iter;
|
||||||
|
|
||||||
|
t_near = (std::max)(t_near, (std::min)(t1, t2));
|
||||||
|
t_far = (std::min)(t_far, (std::max)(t1, t2));
|
||||||
|
|
||||||
if(t1 > t2)
|
// if(t1 > t2)
|
||||||
std::swap(t1, t2);
|
// std::swap(t1, t2);
|
||||||
if(t1 > t_near)
|
// if(t1 > t_near)
|
||||||
t_near = t1;
|
// t_near = t1;
|
||||||
if(t2 < t_far)
|
// if(t2 < t_far)
|
||||||
t_far = t2;
|
// t_far = t2;
|
||||||
|
|
||||||
if(t_near > t_far)
|
if(t_near > t_far || t_far < FT(0.))
|
||||||
return boost::none;
|
|
||||||
if(t_far < 0)
|
|
||||||
return boost::none;
|
return boost::none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,10 +152,10 @@ private:
|
||||||
|
|
||||||
struct Node_ptr_with_ft {
|
struct Node_ptr_with_ft {
|
||||||
Node_ptr_with_ft(const Node* node, const FT& value, size_type nb_primitives)
|
Node_ptr_with_ft(const Node* node, const FT& value, size_type nb_primitives)
|
||||||
: node(node), value(value), nb_primitives(nb_primitives) {}
|
: node(node), nb_primitives(nb_primitives), value(value) {}
|
||||||
const Node* node;
|
const Node* node;
|
||||||
FT value;
|
|
||||||
size_type nb_primitives;
|
size_type nb_primitives;
|
||||||
|
FT value;
|
||||||
bool operator<(const Node_ptr_with_ft& other) const { return value < other.value; }
|
bool operator<(const Node_ptr_with_ft& other) const { return value < other.value; }
|
||||||
bool operator>(const Node_ptr_with_ft& other) const { return value > other.value; }
|
bool operator>(const Node_ptr_with_ft& other) const { return value > other.value; }
|
||||||
};
|
};
|
||||||
|
|
@ -171,14 +171,13 @@ private:
|
||||||
FT operator()(const Point& point) {
|
FT operator()(const Point& point) {
|
||||||
typename AABB_traits::Geom_traits::Vector_3 x(ray->source(), point);
|
typename AABB_traits::Geom_traits::Vector_3 x(ray->source(), point);
|
||||||
typename AABB_traits::Geom_traits::Vector_3 v = ray->to_vector();
|
typename AABB_traits::Geom_traits::Vector_3 v = ray->to_vector();
|
||||||
FT dist = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < 3; ++i) {
|
for(int i = 0; i < 3; ++i) {
|
||||||
if(v[0] != 0) {
|
if(v[0] != FT(0.)) {
|
||||||
dist = std::max(dist, x[0] / v[0]);
|
return x[0] / v[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dist;
|
return FT(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Ray* ray;
|
const Ray* ray;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue