diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h index 580e53b68b4..9348981dccf 100644 --- a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h @@ -57,10 +57,9 @@ namespace internal { dmin = px - qx; } - if ( dmin == FT(0) && (tmin > FT(0) || tmax < FT(0)) ) - { - return false; - } + //if px is not in the x-slab + if ( dmin == FT(0) && (tmin > FT(0) || tmax < FT(0)) ) return false; + FT dmax = dmin; // ----------------------------------- @@ -79,6 +78,9 @@ namespace internal { tmax_ = py - bymin; d_ = py - qy; } + + //if py is not in the y-slab + if ( d_ == FT(0) && (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) return false; @@ -110,6 +112,9 @@ namespace internal { tmax_ = pz - bzmin; d_ = pz - qz; } + + //if pz is not in the z-slab + if ( d_ == FT(0) && (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); } diff --git a/Intersections_3/test/Intersections_3/test_intersections_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_3.cpp index e0a35cb39a4..82034b818f3 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_3.cpp @@ -58,6 +58,7 @@ struct Test { typedef CGAL::Triangle_3< K > Tr; typedef CGAL::Ray_3< K > R; typedef CGAL::Iso_cuboid_3< K > Cub; + typedef CGAL::Bbox_3 Bbox; template < typename Type > @@ -380,6 +381,53 @@ struct Test { check_no_intersection (R(P(0,0,0),P(1,0,0)),R(P(0,1,0),P(0,2,0))); } + void Bbox_L(){ + std::cout << "Bbox - Line\n"; + Bbox box(-1,-1,-1,1,1,1); + + //not in x,y,z slab + check_no_intersection (box,L(P(2,0,0),P(2,0,0.5))); + check_no_intersection (box,L(P(0,2,0),P(0,2,0.5))); + check_no_intersection (box,L(P(0,0,2),P(0.5,0,2))); + //not in x,y,z slab + check_no_intersection (box,L(P(2,0,0.5),P(2,0,0))); + check_no_intersection (box,L(P(0,2,0.5),P(0,2,0))); + check_no_intersection (box,L(P(0.5,0,2),P(0,0,2))); + //in each slab, time not matching + //xz + check_no_intersection (box,L(P(-8,0,0),P(0,0, 8))); + check_no_intersection (box,L(P( 8,0,0),P(0,0, 8))); + check_no_intersection (box,L(P(-8,0,0),P(0,0,-8))); + check_no_intersection (box,L(P( 8,0,0),P(0,0,-8))); + //yz + check_no_intersection (box,L(P(0,-8,0),P(0,0, 8))); + check_no_intersection (box,L(P(0, 8,0),P(0,0, 8))); + check_no_intersection (box,L(P(0,-8,0),P(0,0,-8))); + check_no_intersection (box,L(P(0, 8,0),P(0,0,-8))); + //xy + check_no_intersection (box,L(P(0,-8,0),P(8,0,0))); + check_no_intersection (box,L(P(0, 8,0),P(8,0,0))); + check_no_intersection (box,L(P(0,-8,0),P(-8,0,0))); + check_no_intersection (box,L(P(0, 8,0),P(-8,0,0))); + //Intersecting + //xz + check_intersection (box,L(P(-0.5,0,0),P(0,0, 0.5))); + check_intersection (box,L(P( 0.5,0,0),P(0,0, 0.5))); + check_intersection (box,L(P(-0.5,0,0),P(0,0,-0.5))); + check_intersection (box,L(P( 0.5,0,0),P(0,0,-0.5))); + //yz + check_intersection (box,L(P(0,-0.5,0),P(0,0, 0.5))); + check_intersection (box,L(P(0, 0.5,0),P(0,0, 0.5))); + check_intersection (box,L(P(0,-0.5,0),P(0,0,-0.5))); + check_intersection (box,L(P(0, 0.5,0),P(0,0,-0.5))); + //xy + check_intersection (box,L(P(0,-0.5,0),P(0.5,0,0))); + check_intersection (box,L(P(0, 0.5,0),P(0.5,0,0))); + check_intersection (box,L(P(0,-0.5,0),P(-0.5,0,0))); + check_intersection (box,L(P(0, 0.5,0),P(-0.5,0,0))); + + + } void run() { @@ -398,6 +446,7 @@ struct Test { R_L(); R_S(); R_R(); + Bbox_L(); } };