From a8f5e3f86702bb51e61b179f2871eeab1ec6f0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Thu, 22 Oct 2015 16:55:50 +0200 Subject: [PATCH] Use the slab method to compute intersection_distance This code still relies on the types to be CGAL types. --- AABB_tree/include/CGAL/AABB_traits.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index f27782d075f..296949a7d46 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -308,7 +308,28 @@ public: template boost::optional operator()(const Ray& ray, const Bounding_box& bbox) { - return boost::none; + FT t_near = -DBL_MAX; // std::numeric_limits::lowest(); C++1903 + FT t_far = DBL_MAX; + + for(int i = 0; i < 3; i++) { + if(ray.direction().delta(i) == 0) { + if((ray.source()[i] < box.min(i)) || (ray.source()[i] > box.max(i))) { + return boost::none; + } + } else { + FT t1 = (box.min(i) - ray.source()[i]) / ray.direction().delta(i); + FT t2 = (box.max(i) - ray.source()[i]) / ray.direction().delta(i); + + t_near = std::max(t_near, std::min(t1, t2)); + t_far = std::min(t_far, std::max(t1, t2)); + } + } + + if(t_far > t_near && t_far > 0) { + return t_near; + } else { + return boost::none; + } } };