Factorize the _aux function for do_intersect(BBox_3, Ray_3|Segment_3)

This commit is contained in:
Laurent Rineau 2012-03-19 12:07:20 +00:00
parent b5703e9cf8
commit 1aa69b5a8b
2 changed files with 19 additions and 13 deletions

View File

@ -24,6 +24,7 @@
#include <CGAL/Ray_3.h>
#include <CGAL/Bbox_3.h>
#include <CGAL/internal/Intersections_3/Bbox_3_Segment_3_do_intersect.h>
// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf
@ -135,7 +136,7 @@ namespace internal {
const Point_3& source = ray.source();
const Point_3& point_on_ray = ray.second_point();
return bbox_ray_do_intersect_aux(
return do_intersect_bbox_segment_aux<FT, true, false>(
source.x(), source.y(), source.z(),
point_on_ray.x(), point_on_ray.y(), point_on_ray.z(),
FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()),

View File

@ -41,7 +41,9 @@ namespace CGAL {
namespace internal {
template <typename FT>
template <typename FT,
bool bounded_0,
bool bounded_1>
inline
bool
do_intersect_bbox_segment_aux(
@ -72,15 +74,16 @@ namespace internal {
dmin = px - qx;
}
if ( tmax < FT(0) ) // test t2 < 0, for a segment or a ray
if ( bounded_0 && tmax < FT(0) ) // test t2 < 0, for a segment or a ray
return false;
if ( tmin > dmin ) // test t1 > 1, for a segment
if ( bounded_1 && tmin > dmin ) // test t1 > 1, for a segment
return false;
// If the query is vertical for x, then check its x-coordinate is in
// the x-slab.
if( (px == qx) && // <=> (dmin == 0)
( CGAL::sign(tmin) * CGAL::sign(tmax) ) > 0 ) return false;
( CGAL::sign(tmin) * CGAL::sign(tmax) ) > 0 )
return false;
// Note: for a segment the condition sign(tmin)*sign(tmax) > 0 has
// already been tested by the two previous tests tmax<0 || tmin>dmin
// (with dmin==0).
@ -92,14 +95,14 @@ namespace internal {
FT dmax = dmin;
// set t1=max(t1, 0), for a segment or a ray
if ( tmin < FT(0) )
if ( bounded_0 && tmin < FT(0) )
{
tmin = FT(0);
dmin = FT(1);
}
// set t2=min(t2, 1), for a segment
if ( tmax > dmax )
if ( bounded_1 && tmax > dmax )
{
tmax = FT(1);
dmax = FT(1);
@ -148,8 +151,8 @@ namespace internal {
{
tmin = tmin_;
dmin = d_;
if(tmin > dmin) return false; // if t1 > 1, for a segment
if(tmin < FT(0)) {
if(bounded_1 && tmin > dmin) return false; // if t1 > 1, for a segment
if(bounded_0 && tmin < FT(0)) {
// set t1=max(t1, 0), for a ray or a segment
tmin = FT(0);
dmin = FT(1);
@ -162,8 +165,8 @@ namespace internal {
{
tmax = tmax_;
dmax = d_;
if(tmax < FT(0)) return false; // if t2 < 0, for a segment or a ray
if ( tmax > dmax )
if( bounded_0 && tmax < FT(0)) return false; // if t2 < 0, for a segment or a ray
if( bounded_1 && tmax > dmax )
{
// set t2=min(t2, 1), for a segment
tmax = FT(1);
@ -207,7 +210,9 @@ namespace internal {
if( (dmax*tmin_) > (d_*tmax) ) return false;
}
return ( d_ == 0 || tmin_ <= d_ && tmax_ >= FT(0) ); // t1 <= 1 && t2 >= 0
return ( d_ == 0 ||
(!bounded_1 || tmin_ <= d_) &&
(!bounded_0 || tmax_ >= FT(0)) ); // t1 <= 1 && t2 >= 0
}
template <class K>
@ -221,7 +226,7 @@ namespace internal {
const Point_3& source = segment.source();
const Point_3& target = segment.target();
return do_intersect_bbox_segment_aux(
return do_intersect_bbox_segment_aux<FT, true, true>(
source.x(), source.y(), source.z(),
target.x(), target.y(), target.z(),
FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()),