diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Bbox_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Bbox_3_do_intersect.h index 9df27cb4958..e811010e1f0 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Bbox_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Bbox_3_do_intersect.h @@ -14,7 +14,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Laurent Rineau, Camille Wormser, Jane Tournois, Pierre Alliez @@ -26,11 +26,13 @@ #pragma warning ( disable : 4003 ) #endif +#include + CGAL_BEGIN_NAMESPACE -bool +bool inline -do_intersect(const CGAL::Bbox_3& c, +do_intersect(const CGAL::Bbox_3& c, const CGAL::Bbox_3& bbox) { return CGAL::do_overlap(c, bbox); diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h index 11efc89560a..d7f8a4d601c 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h @@ -13,7 +13,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez, Stephane Tayeb @@ -32,7 +32,7 @@ namespace internal { template inline - bool + bool bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, const FT& qx, const FT& qy, const FT& qz, const FT& bxmin, const FT& bymin, const FT& bzmin, @@ -48,7 +48,7 @@ namespace internal { tmax = bxmax - px; dmin = qx - px; } - else + else { tmin = px - bxmax; tmax = px - bxmin; @@ -60,7 +60,6 @@ namespace internal { return false; } FT dmax = dmin; - // ----------------------------------- // treat y coord @@ -78,23 +77,22 @@ namespace internal { tmax_ = py - bymin; d_ = py - qy; } - + if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) return false; - + if( (dmin*tmin_) > (d_*tmin) ) - { + { tmin = tmin_; dmin = d_; } - + if( (dmax*tmax_) < (d_*tmax) ) - { + { tmax = tmax_; dmax = d_; } - - + // ----------------------------------- // treat z coord // ----------------------------------- @@ -110,24 +108,24 @@ namespace internal { tmax_ = pz - bzmin; d_ = pz - qz; } - + return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); } - + template - bool do_intersect(const typename K::Line_3& line, + bool do_intersect(const typename K::Line_3& line, const CGAL::Bbox_3& bbox, const K&) { typedef typename K::FT FT; typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; - - const Point_3 point = line.point(); - const Vector_3 v = line.to_vector(); - + + const Point_3& point = line.point(); + const Vector_3& v = line.to_vector(); + return bbox_line_do_intersect_aux( - point.x(), point.y(), point.z(), + point.x(), point.y(), point.z(), point.x()+v.x(), point.y()+v.y(), point.z()+v.z(), FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax()) ); @@ -136,14 +134,14 @@ namespace internal { } // namespace internal template -bool do_intersect(const CGAL::Line_3& line, +bool do_intersect(const CGAL::Line_3& line, const CGAL::Bbox_3& bbox) { return typename K::Do_intersect_3()(line, bbox); } template -bool do_intersect(const CGAL::Bbox_3& bbox, +bool do_intersect(const CGAL::Bbox_3& bbox, const CGAL::Line_3& line) { return typename K::Do_intersect_3()(line, bbox); @@ -152,5 +150,3 @@ bool do_intersect(const CGAL::Bbox_3& bbox, CGAL_END_NAMESPACE #endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H - - diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Plane_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Plane_3_do_intersect.h index 444bd9ae9bf..549f1aac558 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Plane_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Plane_3_do_intersect.h @@ -13,7 +13,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez @@ -33,61 +33,61 @@ namespace internal { template void get_min_max(const typename K::Vector_3& p, const CGAL::Bbox_3& bbox, - typename K::Point_3& p_min, + typename K::Point_3& p_min, typename K::Point_3& p_max) { if(p.x() > 0) { if(p.y() > 0) { - if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); + if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax());} - else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); + else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin());} } else { - if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); + if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax());} - else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); + else { p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin());} } } else { if(p.y() > 0) { - if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); + if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax());} - else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); + else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin());} } else { - if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); + if(p.z() > 0) { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax());} - else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); + else { p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin());} } } } template - bool do_intersect(const typename K::Plane_3& plane, + bool do_intersect(const typename K::Plane_3& plane, const CGAL::Bbox_3& bbox, const K&) { typename K::Point_3 p_max, p_min; get_min_max(plane.orthogonal_vector(), bbox, p_min, p_max); - return ! (plane.oriented_side(p_max) == ON_NEGATIVE_SIDE || + return ! (plane.oriented_side(p_max) == ON_NEGATIVE_SIDE || plane.oriented_side(p_min) == ON_POSITIVE_SIDE); } } // namespace internal template -bool do_intersect(const CGAL::Plane_3& plane, +bool do_intersect(const CGAL::Plane_3& plane, const CGAL::Bbox_3& bbox) { return typename K::Do_intersect_3()(plane, bbox); } template -bool do_intersect(const CGAL::Bbox_3& bbox, +bool do_intersect(const CGAL::Bbox_3& bbox, const CGAL::Plane_3& plane) { return typename K::Do_intersect_3()(plane, bbox); diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h index c50a8307d7b..8d6f69f8920 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h @@ -13,7 +13,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez, Stephane Tayeb @@ -31,7 +31,7 @@ namespace internal { template inline - bool + bool bbox_ray_do_intersect_aux(const FT& px, const FT& py, const FT& pz, const FT& qx, const FT& qy, const FT& qz, const FT& bxmin, const FT& bymin, const FT& bzmin, @@ -50,7 +50,7 @@ namespace internal { if ( tmax < FT(0) ) return false; } - else + else { tmin = px - bxmax; tmax = px - bxmin; @@ -58,7 +58,7 @@ namespace internal { if ( tmax < FT(0) ) return false; } - + FT dmax = dmin; if ( tmin > FT(0) ) { @@ -66,11 +66,11 @@ namespace internal { return false; } else - { + { tmin = FT(0); dmin = FT(1); } - + // ----------------------------------- // treat y coord // ----------------------------------- @@ -87,23 +87,22 @@ namespace internal { tmax_ = py - bymin; d_ = py - qy; } - + if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) return false; - + if( (dmin*tmin_) > (d_*tmin) ) - { + { tmin = tmin_; dmin = d_; } - + if( (dmax*tmax_) < (d_*tmax) ) - { + { tmax = tmax_; dmax = d_; } - - + // ----------------------------------- // treat z coord // ----------------------------------- @@ -119,23 +118,23 @@ namespace internal { tmax_ = pz - bzmin; d_ = pz - qz; } - + return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); } - + template - bool do_intersect(const typename K::Ray_3& ray, + bool do_intersect(const typename K::Ray_3& ray, const CGAL::Bbox_3& bbox, const K&) { typedef typename K::FT FT; typedef typename K::Point_3 Point_3; - - const Point_3 source = ray.source(); - const Point_3 point_on_ray = ray.point(1); - + + const Point_3& source = ray.source(); + const Point_3& point_on_ray = ray.point(1); + return bbox_ray_do_intersect_aux( - source.x(), source.y(), source.z(), + 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()), FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax()) ); @@ -144,14 +143,14 @@ namespace internal { } // namespace internal template -bool do_intersect(const CGAL::Ray_3& ray, +bool do_intersect(const CGAL::Ray_3& ray, const CGAL::Bbox_3& bbox) { return typename K::Do_intersect_3()(ray, bbox); } template -bool do_intersect(const CGAL::Bbox_3& bbox, +bool do_intersect(const CGAL::Bbox_3& bbox, const CGAL::Ray_3& ray) { return typename K::Do_intersect_3()(ray, bbox); @@ -160,5 +159,3 @@ bool do_intersect(const CGAL::Bbox_3& bbox, CGAL_END_NAMESPACE #endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H - - diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h index 2ac4d561b5b..555bfcd42cf 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h @@ -13,7 +13,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez, Stephane Tayeb @@ -30,9 +30,9 @@ CGAL_BEGIN_NAMESPACE namespace internal { - template + template inline - bool + bool do_intersect_bbox_segment_aux( const FT& px, const FT& py, const FT& pz, const FT& qx, const FT& qy, const FT& qz, @@ -49,29 +49,29 @@ namespace internal { tmax = bxmax - px; dmin = qx - px; } - else + else { tmin = px - bxmax; tmax = px - bxmin; dmin = px - qx; } - + if ( tmax < FT(0) || tmin > dmin ) return false; - + FT dmax = dmin; if ( tmin < FT(0) ) - { + { tmin = FT(0); dmin = FT(1); } - + if ( tmax > dmax ) - { + { tmax = FT(1); dmax = FT(1); } - + // ----------------------------------- // treat y coord // ----------------------------------- @@ -88,23 +88,22 @@ namespace internal { tmax_ = py - bymin; d_ = py - qy; } - + if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) return false; - + if( (dmin*tmin_) > (d_*tmin) ) - { + { tmin = tmin_; dmin = d_; } - + if( (dmax*tmax_) < (d_*tmax) ) - { + { tmax = tmax_; dmax = d_; } - - + // ----------------------------------- // treat z coord // ----------------------------------- @@ -123,20 +122,20 @@ namespace internal { return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); } - + template - bool do_intersect(const typename K::Segment_3& segment, + bool do_intersect(const typename K::Segment_3& segment, const CGAL::Bbox_3& bbox, const K&) { typedef typename K::FT FT; typedef typename K::Point_3 Point_3; - - const Point_3 source = segment.source(); - const Point_3 target = segment.target(); - + + const Point_3& source = segment.source(); + const Point_3& target = segment.target(); + return do_intersect_bbox_segment_aux( - source.x(), source.y(), source.z(), + source.x(), source.y(), source.z(), target.x(), target.y(), target.z(), FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax()) ); @@ -144,7 +143,7 @@ namespace internal { template bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Segment_3& segment, + const typename K::Segment_3& segment, const K& k) { return do_intersect(segment, bbox, k); @@ -153,14 +152,14 @@ namespace internal { } // namespace internal template -bool do_intersect(const CGAL::Segment_3& segment, +bool do_intersect(const CGAL::Segment_3& segment, const CGAL::Bbox_3& bbox) { return typename K::Do_intersect_3()(segment, bbox); } template -bool do_intersect(const CGAL::Bbox_3& bbox, +bool do_intersect(const CGAL::Bbox_3& bbox, const CGAL::Segment_3& segment) { return typename K::Do_intersect_3()(segment, bbox); diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Sphere_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Sphere_3_do_intersect.h index 40866c787b1..d7f4ecb83e6 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Sphere_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Sphere_3_do_intersect.h @@ -13,7 +13,7 @@ // // $URL$ // $Id$ -// +// // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez @@ -32,7 +32,7 @@ CGAL_BEGIN_NAMESPACE namespace internal { template - bool do_intersect(const typename K::Sphere_3& sphere, + bool do_intersect(const typename K::Sphere_3& sphere, const CGAL::Bbox_3& bbox, const K&) { @@ -98,14 +98,14 @@ namespace internal { } // namespace internal template -bool do_intersect(const CGAL::Sphere_3& sphere, +bool do_intersect(const CGAL::Sphere_3& sphere, const CGAL::Bbox_3& bbox) { return typename K::Do_intersect_3()(sphere, bbox); } template -bool do_intersect(const CGAL::Bbox_3& bbox, +bool do_intersect(const CGAL::Bbox_3& bbox, const CGAL::Sphere_3& sphere) { return typename K::Do_intersect_3()(sphere, bbox); diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Triangle_3_do_intersect.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Triangle_3_do_intersect.h index 4f1b7c692ac..a756e69aebf 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Triangle_3_do_intersect.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Bbox_3_Triangle_3_do_intersect.h @@ -43,7 +43,7 @@ namespace internal { const typename K::Point_3& p = triangle.vertex(0); const typename K::Point_3& q = triangle.vertex(1); const typename K::Point_3& r = triangle.vertex(2); - + for(int i = 0; i < 3; ++i) { if(p[i] <= q[i]) { if(q[i] <= r[i]) { // pqr @@ -100,17 +100,17 @@ namespace internal { p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); } - else { + else { p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); } } else { - if(AXE == 2 || pz > 0) { + if(AXE == 2 || pz > 0) { p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); } - else { + else { p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); } @@ -118,29 +118,29 @@ namespace internal { } else { if(AXE == 1 || py > 0) { - if(AXE == 2 || pz > 0) { + if(AXE == 2 || pz > 0) { p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); } - else { + else { p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); } } else { - if(AXE == 2 || pz > 0) { + if(AXE == 2 || pz > 0) { p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); } - else { + else { p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); } } } } - - + + template inline typename K::FT @@ -157,12 +157,12 @@ namespace internal { case 2: return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta; default: - CGAL_kernel_assertion(false); + CGAL_error(); return typename K::FT(0.); } } - - + + template inline bool do_axis_intersect(const typename K::Triangle_3& triangle, @@ -171,25 +171,25 @@ namespace internal { { const typename K::Point_3& j = triangle.vertex(SIDE); const typename K::Point_3& k = triangle.vertex((SIDE+2)%3); - + typename K::Point_3 p_min, p_max; get_min_max(AXE==0? 0: AXE==1? sides[SIDE].z(): -sides[SIDE].y(), AXE==0? -sides[SIDE].z(): AXE==1? 0: sides[SIDE].x(), AXE==0? sides[SIDE].y(): AXE==1? -sides[SIDE].x(): 0, bbox, p_min, p_max); - + switch ( AXE ) { case 0: // t_max >= t_min if ( do_axis_intersect_aux(k.y()-j.y(), k.z()-j.z(), sides) >= 0 ) { - return ( do_axis_intersect_aux(p_min.y()-k.y(), p_min.z()-k.z(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.y()-k.y(), p_min.z()-k.z(), sides) <= 0 || do_axis_intersect_aux(p_max.y()-j.y(), p_max.z()-j.z(), sides) >= 0 ); } else { - return ( do_axis_intersect_aux(p_min.y()-j.y(), p_min.z()-j.z(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.y()-j.y(), p_min.z()-j.z(), sides) <= 0 || do_axis_intersect_aux(p_max.y()-k.y(), p_max.z()-k.z(), sides) >= 0 ); } break; @@ -197,12 +197,12 @@ namespace internal { // t_max >= t_min if ( do_axis_intersect_aux(k.x()-j.x(), k.z()-j.z(), sides) >= 0 ) { - return ( do_axis_intersect_aux(p_min.x()-k.x(), p_min.z()-k.z(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.x()-k.x(), p_min.z()-k.z(), sides) <= 0 || do_axis_intersect_aux(p_max.x()-j.x(), p_max.z()-j.z(), sides) >= 0 ); } else { - return ( do_axis_intersect_aux(p_min.x()-j.x(), p_min.z()-j.z(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.x()-j.x(), p_min.z()-j.z(), sides) <= 0 || do_axis_intersect_aux(p_max.x()-k.x(), p_max.z()-k.z(), sides) >= 0 ); } break; @@ -210,18 +210,18 @@ namespace internal { // t_max >= t_min if ( do_axis_intersect_aux(k.x()-j.x(), k.y()-j.y(), sides) >= 0 ) { - return ( do_axis_intersect_aux(p_min.x()-k.x(), p_min.y()-k.y(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.x()-k.x(), p_min.y()-k.y(), sides) <= 0 || do_axis_intersect_aux(p_max.x()-j.x(), p_max.y()-j.y(), sides) >= 0 ); } else { - return ( do_axis_intersect_aux(p_min.x()-j.x(), p_min.y()-j.y(), sides) <= 0 + return ( do_axis_intersect_aux(p_min.x()-j.x(), p_min.y()-j.y(), sides) <= 0 || do_axis_intersect_aux(p_max.x()-k.x(), p_max.y()-k.y(), sides) >= 0 ); } break; default: // Should not happen - CGAL_kernel_assertion(false); + CGAL_error(); return false; } } diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Line_3_intersection.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Line_3_intersection.h index 405e039c8e7..32c6dc8b9f3 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Line_3_intersection.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Line_3_intersection.h @@ -16,12 +16,12 @@ // // // Author(s) : Stéphane Tayeb -// //****************************************************************************** -// File Description : -// +// File Description : Implements triangle_3 line_3 intersection construction. +// This implementation is adapted from Triangle_3_Line_3_do_intersect.h. //****************************************************************************** + #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H #define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H @@ -37,42 +37,42 @@ t3l3_intersection_coplanar_aux(const typename K::Line_3& l, const typename K::Point_3& a, const typename K::Point_3& b, const K& k) -{ +{ // Returns the intersection point between line l and segment [a,b] // // preconditions: // + l,a,b are coplanar - + typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; typedef typename K::FT FT; - - typename K::Construct_vector_3 vector = + + typename K::Construct_vector_3 vector = k.construct_vector_3_object(); - - typename K::Construct_cross_product_vector_3 cross_product = + + typename K::Construct_cross_product_vector_3 cross_product = k.construct_cross_product_vector_3_object(); - - typename K::Compute_scalar_product_3 scalar_product = + + typename K::Compute_scalar_product_3 scalar_product = k.compute_scalar_product_3_object(); - - typename K::Compute_squared_length_3 sq_length = + + typename K::Compute_squared_length_3 sq_length = k.compute_squared_length_3_object(); - - const Point_3 p = l.point(); - const Vector_3 v = l.to_vector(); + + const Point_3& p = l.point(); + const Vector_3& v = l.to_vector(); const Vector_3 ab = vector(a,b); const Vector_3 pa = vector(p,a); - + const Vector_3 pa_ab = cross_product(pa,ab); const Vector_3 v_ab = cross_product(v,ab); - + const FT t = scalar_product(pa_ab,v_ab) / sq_length(v_ab); - + return ( p + t*v ); } - - + + template Object t3l3_intersection_coplanar_aux(const typename K::Point_3& a, @@ -93,69 +93,66 @@ t3l3_intersection_coplanar_aux(const typename K::Point_3& a, // | l // // We know that c is isolated on the negative side of pq - + typedef typename K::Point_3 Point_3; - + typename K::Intersect_3 intersection = k.intersect_3_object(); - + typename K::Construct_line_3 line = k.construct_line_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - + // Let's get the intersection points const Point_3 l_bc = t3l3_intersection_coplanar_aux(l,b,c,k); const Point_3 l_ca = t3l3_intersection_coplanar_aux(l,c,a,k); - + if ( negative_side ) return make_object(segment(l_bc, l_ca)); else - return make_object(segment(l_ca, l_bc)); + return make_object(segment(l_ca, l_bc)); } - - + + template Object -intersection_coplanar(const typename K::Triangle_3 &t, +intersection_coplanar(const typename K::Triangle_3 &t, const typename K::Line_3 &l, const K & k ) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; - + typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Construct_line_3 line = k.construct_line_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - - + const Point_3 & p = point_on(l,0); const Point_3 & q = point_on(l,1); - + const Point_3 & A = vertex_on(t,0); const Point_3 & B = vertex_on(t,1); const Point_3 & C = vertex_on(t,2); - + int k0 = 0; int k1 = 1; int k2 = 2; - + // Determine the orientation of the triangle in the common plane if (coplanar_orientation(A,B,C) != POSITIVE) { @@ -163,20 +160,20 @@ intersection_coplanar(const typename K::Triangle_3 &t, // swap two vertices. std::swap(k1,k2); } - + const Point_3& a = vertex_on(t,k0); const Point_3& b = vertex_on(t,k1); const Point_3& c = vertex_on(t,k2); - + // Test whether the line intersects the triangle in the common plane const Orientation pqa = coplanar_orientation(p,q,a); const Orientation pqb = coplanar_orientation(p,q,b); const Orientation pqc = coplanar_orientation(p,q,c); - + switch ( pqa ) { // ----------------------------------- // pqa POSITIVE - // ----------------------------------- + // ----------------------------------- case POSITIVE: switch ( pqb ) { case POSITIVE: @@ -191,7 +188,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, case COLLINEAR: return make_object(c); } - + case NEGATIVE: if ( POSITIVE == pqc ) // b is isolated on the negative side @@ -200,7 +197,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a is isolated on the positive side (here mb c could be use as // an endpoint instead of computing an intersection is some cases) return t3l3_intersection_coplanar_aux(b,c,a,l,false,k); - + case COLLINEAR: switch ( pqc ) { case POSITIVE: @@ -213,15 +210,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, // b,c,p,q are aligned, [p,q]&[b,c] have the same direction return make_object(segment(b,c)); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa NEGATIVE - // ----------------------------------- + // ----------------------------------- case NEGATIVE: switch ( pqb ) { case POSITIVE: @@ -232,7 +229,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // b is isolated on the positive side (here mb c could be use as // an endpoint instead of computing an intersection, in some cases) return t3l3_intersection_coplanar_aux(c,a,b,l,false,k); - + case NEGATIVE: switch ( pqc ) { case POSITIVE: @@ -245,28 +242,28 @@ intersection_coplanar(const typename K::Triangle_3 &t, case COLLINEAR: return make_object(c); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: // a is isolated on the negative side (here mb b could be use as // an endpoint instead of computing an intersection) - return t3l3_intersection_coplanar_aux(b,c,a,l,true,k); + return t3l3_intersection_coplanar_aux(b,c,a,l,true,k); case NEGATIVE: return make_object(b); case COLLINEAR: // b,c,p,q are aligned, [p,q]&[c,b] have the same direction return make_object(segment(c,b)); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa COLLINEAR - // ----------------------------------- + // ----------------------------------- case COLLINEAR: switch ( pqb ) { case POSITIVE: @@ -281,7 +278,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a,c,p,q are aligned, [p,q]&[c,a] have the same direction return make_object(segment(c,a)); } - + case NEGATIVE: switch ( pqc ) { case POSITIVE: @@ -294,7 +291,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a,c,p,q are aligned, [p,q]&[a,c] have the same direction return make_object(segment(a,c)); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: @@ -306,45 +303,42 @@ intersection_coplanar(const typename K::Triangle_3 &t, case COLLINEAR: // case pqc == COLLINEAR is impossible since the triangle is // assumed to be non flat - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - } - + default:// should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - } } - - + + template inline -Object +Object t3l3_intersection_aux(const typename K::Triangle_3 &t, const typename K::Line_3 &l, const K& k) { typename K::Intersect_3 intersection = k.intersect_3_object(); - + Object obj = intersection(l,t.supporting_plane()); - + // Intersection should be a point (because of orientation test done before) - if ( NULL == object_cast(&obj) ) - return obj; - else + if ( obj.is() ) return Object(); + else + return obj; } - - - + + template Object intersection(const typename K::Triangle_3 &t, @@ -353,78 +347,76 @@ intersection(const typename K::Triangle_3 &t, { CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; - + typedef typename K::Point_3 Point_3; - - typename K::Construct_point_on_3 point_on = + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = + + typename K::Orientation_3 orientation = k.orientation_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Intersect_3 intersection = k.intersect_3_object(); - + const Point_3 & a = vertex_on(t,0); const Point_3 & b = vertex_on(t,1); const Point_3 & c = vertex_on(t,2); const Point_3 & p = point_on(l,0); const Point_3 & q = point_on(l,1); - - if ( ( orientation(a,b,c,p) != COPLANAR ) || ( orientation(a,b,c,q) != COPLANAR ) ) { const Orientation pqab = orientation(p,q,a,b); const Orientation pqbc = orientation(p,q,b,c); switch ( pqab ) { - case POSITIVE: + case POSITIVE: if ( pqbc != NEGATIVE && orientation(p,q,c,a) != NEGATIVE ) return t3l3_intersection_aux(t,l,k); else return Object(); - + case NEGATIVE: if ( pqbc != POSITIVE && orientation(p,q,c,a) != POSITIVE ) return t3l3_intersection_aux(t,l,k); else return Object(); - + case COPLANAR: switch ( pqbc ) { - case POSITIVE: + case POSITIVE: if ( orientation(p,q,c,a) != NEGATIVE ) return t3l3_intersection_aux(t,l,k); else return Object(); - + case NEGATIVE: if ( orientation(p,q,c,a) != POSITIVE ) return t3l3_intersection_aux(t,l,k); else return Object(); - + case COPLANAR: // pqa or pqb or pqc are collinear return t3l3_intersection_aux(t,l,k); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } } - + // Coplanar case return intersection_coplanar(t,l,k); } @@ -433,12 +425,12 @@ template Object intersection(const typename K::Line_3 &l, const typename K::Triangle_3 &t, - const K& k) + const K& k) { return internal::intersection(t,l,k); } - - + + } // end namespace internal template diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Plane_3_intersection.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Plane_3_intersection.h index 2a6d39a2c1d..32fc0d4562d 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Plane_3_intersection.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Plane_3_intersection.h @@ -15,7 +15,7 @@ // // $URL$ // $Id$ -// +// // // Adapted from // @@ -32,11 +32,11 @@ namespace CGAL { namespace internal { template -inline +inline typename K::Point_3 -inter_plane_triangle_3_aux(const typename K::Point_3 &p1, +inter_plane_triangle_3_aux(const typename K::Point_3 &p1, const typename K::RT & f1, - const typename K::Point_3 &p2, + const typename K::Point_3 &p2, const typename K::RT & f2) { return typename K::Point_3(f2 * p1.x() - f1 * p2.x(), @@ -47,8 +47,8 @@ inter_plane_triangle_3_aux(const typename K::Point_3 &p1, template Object -intersection(const typename K::Plane_3 &plane, - const typename K::Triangle_3 &triangle, +intersection(const typename K::Plane_3 &plane, + const typename K::Triangle_3 &triangle, const K& k) { CGAL_kernel_precondition( ! k.is_degenerate_3_object()(triangle)) ; @@ -59,17 +59,17 @@ intersection(const typename K::Plane_3 &plane, typedef typename K::Object_3 Object_3; typedef typename K::RT RT; typedef typename Sgn::result_type SignRT; - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - + //typename K::Oriented_side_3 oriented_side = //k.oriented_side_3_object(); // PA: never used typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - typename K::Construct_object_3 make_object = + typename K::Construct_object_3 make_object = k.construct_object_3_object(); const Point_3& t0 = vertex_on(triangle,0); @@ -157,8 +157,8 @@ intersection(const typename K::Plane_3 &plane, template inline Object -intersection(const typename K::Triangle_3 &triangle, - const typename K::Plane_3 &plane, +intersection(const typename K::Triangle_3 &triangle, + const typename K::Plane_3 &plane, const K& k) { return intersection(plane, triangle, k); @@ -168,7 +168,7 @@ intersection(const typename K::Triangle_3 &triangle, template inline -Object +Object intersection(const Plane_3 &plane, const Triangle_3 &triangle) { return typename K::Intersect_3()(plane, triangle); @@ -176,7 +176,7 @@ intersection(const Plane_3 &plane, const Triangle_3 &triangle) template inline -Object +Object intersection(const Triangle_3 &triangle, const Plane_3 &plane) { return typename K::Intersect_3()(plane, triangle); diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Ray_3_intersection.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Ray_3_intersection.h index 100a79b167d..99915fa0d0a 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Ray_3_intersection.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Ray_3_intersection.h @@ -19,7 +19,6 @@ // //****************************************************************************** // File Description : Implements triangle_3 ray_3 intersection construction. -// // This implementation is adapted from Triangle_3_Ray_3_do_intersect.h. //****************************************************************************** @@ -32,7 +31,7 @@ namespace CGAL { namespace internal { - + template typename K::Point_3 t3r3_intersection_coplanar_aux(const typename K::Point_3& p, @@ -40,40 +39,40 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& p, const typename K::Point_3& a, const typename K::Point_3& b, const K& k) -{ +{ // Returns the intersection point between line (p,v) and line (a,b) // // preconditions: // + p,v,a,b are coplanar - + typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; typedef typename K::FT FT; - - typename K::Construct_vector_3 vector = - k.construct_vector_3_object(); - - typename K::Construct_cross_product_vector_3 cross_product = - k.construct_cross_product_vector_3_object(); - - typename K::Compute_scalar_product_3 scalar_product = - k.compute_scalar_product_3_object(); - - typename K::Compute_squared_length_3 sq_length = - k.compute_squared_length_3_object(); - + + typename K::Construct_vector_3 vector = + k.construct_vector_3_object(); + + typename K::Construct_cross_product_vector_3 cross_product = + k.construct_cross_product_vector_3_object(); + + typename K::Compute_scalar_product_3 scalar_product = + k.compute_scalar_product_3_object(); + + typename K::Compute_squared_length_3 sq_length = + k.compute_squared_length_3_object(); + const Vector_3 ab = vector(a,b); const Vector_3 pa = vector(p,a); - + const Vector_3 pa_ab = cross_product(pa,ab); const Vector_3 v_ab = cross_product(v,ab); - + const FT t = scalar_product(pa_ab,v_ab) / sq_length(v_ab); - + return ( p + t*v ); } - - + + template Object t3r3_intersection_coplanar_aux(const typename K::Point_3& a, @@ -86,61 +85,58 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a, // This function is designed to clip r into the triangle abc. // Point configuration should be as follows // - // + // // p+ +b // | // +c | +a - // | + // | // |r // // We know that c is isolated on the negative side of r // but we don't know p position wrt [bc]&[ca] - + typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - typename K::Construct_point_on_3 point_on = + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + const Point_3& p = point_on(r,0); - + // A ray is not symetric, 2 cases depending on isolated side of c - Orientation cap; - if ( negative_side ) - cap = coplanar_orientation(c,a,p); - else - cap = coplanar_orientation(b,c,p); - + Orientation cap = negative_side ? coplanar_orientation(c,a,p) + : coplanar_orientation(b,c,p); + switch ( cap ) { - + case NEGATIVE: // p is bellow [c,a] return Object(); - + case COLLINEAR: return make_object(p); - + case POSITIVE: { // Compute the intersection points between ray and [b,c],[c,a] Vector_3 v = r.to_vector(); - + // Get intersection point at p side Point_3 p_side_end_point(p); Point_3 q_side_end_point; - + // A ray is not symetric, 2 cases depending on isolated side of c if ( negative_side ) { if ( NEGATIVE == coplanar_orientation(b,c,p) ) p_side_end_point = t3r3_intersection_coplanar_aux(p,v,b,c,k); - + // Get other end point (always intersection computation on the unbounded // side of the ray) q_side_end_point = t3r3_intersection_coplanar_aux(p,v,c,a,k); @@ -149,73 +145,67 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a, { if ( NEGATIVE == coplanar_orientation(c,a,p) ) p_side_end_point = t3r3_intersection_coplanar_aux(p,v,c,a,k); - + // Get other end point (always intersection computation on the unbounded // side of the ray) q_side_end_point = t3r3_intersection_coplanar_aux(p,v,b,c,k); } - + // Build result return make_object(segment(p_side_end_point, q_side_end_point)); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - - CGAL_kernel_assertion(false); + + CGAL_error(); return Object(); } - - - - - - - + + template Object -intersection_coplanar(const typename K::Triangle_3 &t, +intersection_coplanar(const typename K::Triangle_3 &t, const typename K::Ray_3 &r, const K & k ) { CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; - + typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Construct_line_3 line = k.construct_line_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); - - + + const Point_3 & p = point_on(r,0); const Point_3 & q = point_on(r,1); - + const Point_3 & A = vertex_on(t,0); const Point_3 & B = vertex_on(t,1); const Point_3 & C = vertex_on(t,2); - + int k0 = 0; int k1 = 1; int k2 = 2; - + // Determine the orientation of the triangle in the common plane if (coplanar_orientation(A,B,C) != POSITIVE) { @@ -223,21 +213,21 @@ intersection_coplanar(const typename K::Triangle_3 &t, // swap two vertices. std::swap(k1,k2); } - + const Point_3& a = vertex_on(t,k0); const Point_3& b = vertex_on(t,k1); const Point_3& c = vertex_on(t,k2); - + // Test whether the ray's supporting line intersects the // triangle in the common plane const Orientation pqa = coplanar_orientation(p,q,a); const Orientation pqb = coplanar_orientation(p,q,b); const Orientation pqc = coplanar_orientation(p,q,c); - + switch ( pqa ) { // ----------------------------------- // pqa POSITIVE - // ----------------------------------- + // ----------------------------------- case POSITIVE: switch ( pqb ) { case POSITIVE: @@ -246,11 +236,11 @@ intersection_coplanar(const typename K::Triangle_3 &t, // the triangle lies in the positive halfspace // defined by the segment's supporting line. return Object(); - + case NEGATIVE: // c is isolated on the negative side return t3r3_intersection_coplanar_aux(a,b,c,r,true,k); - + case COLLINEAR: // p,q,c are collinear if ( collinear_ordered(p,c,q) || collinear_ordered(p,q,c) ) @@ -258,7 +248,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return Object(); } - + case NEGATIVE: if ( POSITIVE == pqc ) // b is isolated on the negative side @@ -267,7 +257,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a is isolated on the positive side (here mb c could be use as // an endpoint instead of computing an intersection is some cases) return t3r3_intersection_coplanar_aux(b,c,a,r,false,k); - + case COLLINEAR: switch ( pqc ) { case POSITIVE: @@ -276,12 +266,12 @@ intersection_coplanar(const typename K::Triangle_3 &t, return make_object(b); else return Object(); - + case NEGATIVE: // a is isolated on the positive side (here mb b could be use as // an endpoint instead of computing an intersection) return t3r3_intersection_coplanar_aux(b,c,a,r,false,k); - + case COLLINEAR: // b,c,p,q are aligned, [p,q]&[b,c] have the same direction if ( collinear_ordered(p,b,c) ) @@ -289,15 +279,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return make_object(segment(p,c)); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa NEGATIVE - // ----------------------------------- + // ----------------------------------- case NEGATIVE: switch ( pqb ) { case POSITIVE: @@ -308,18 +298,18 @@ intersection_coplanar(const typename K::Triangle_3 &t, // b is isolated on the positive side (here mb c could be use as // an endpoint instead of computing an intersection, in some cases) return t3r3_intersection_coplanar_aux(c,a,b,r,false,k); - + case NEGATIVE: switch ( pqc ) { case POSITIVE: // c is isolated on the positive side return t3r3_intersection_coplanar_aux(a,b,c,r,false,k); - + case NEGATIVE: // the triangle lies in the negative halfspace // defined by the segment's supporting line. return Object(); - + case COLLINEAR: // p,q,c are collinear if ( collinear_ordered(p,c,q) || collinear_ordered(p,q,c) ) @@ -327,21 +317,21 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return Object(); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: // a is isolated on the negative side (here mb b could be use as // an endpoint instead of computing an intersection) - return t3r3_intersection_coplanar_aux(b,c,a,r,true,k); - + return t3r3_intersection_coplanar_aux(b,c,a,r,true,k); + case NEGATIVE: // p,q,b are collinear if ( collinear_ordered(p,b,q) || collinear_ordered(p,q,b) ) return make_object(b); else return Object(); - + case COLLINEAR: // b,c,p,q are aligned, [p,q]&[c,b] have the same direction if ( collinear_ordered(p,c,b) ) @@ -349,15 +339,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return make_object(segment(p,b)); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa COLLINEAR - // ----------------------------------- + // ----------------------------------- case COLLINEAR: switch ( pqb ) { case POSITIVE: @@ -368,12 +358,12 @@ intersection_coplanar(const typename K::Triangle_3 &t, return make_object(a); else return Object(); - + case NEGATIVE: // b is isolated on the positive side (here mb a could be use as // an endpoint instead of computing an intersection) return t3r3_intersection_coplanar_aux(c,a,b,r,false,k); - + case COLLINEAR: // a,c,p,q are aligned, [p,q]&[c,a] have the same direction if ( collinear_ordered(p,c,a) ) @@ -381,21 +371,21 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return make_object(segment(p,a)); } - + case NEGATIVE: switch ( pqc ) { case POSITIVE: // b is isolated on the negative side (here mb a could be use as // an endpoint instead of computing an intersection) return t3r3_intersection_coplanar_aux(c,a,b,r,true,k); - + case NEGATIVE: // p,q,a are collinear if ( collinear_ordered(p,a,q) || collinear_ordered(p,q,a) ) return make_object(a); else return Object(); - + case COLLINEAR: // a,c,p,q are aligned, [p,q]&[a,c] have the same direction if ( collinear_ordered(p,a,c) ) @@ -403,7 +393,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return make_object(segment(p,c)); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: @@ -412,55 +402,55 @@ intersection_coplanar(const typename K::Triangle_3 &t, return make_object(segment(a,b)); else return make_object(segment(p,b)); - + case NEGATIVE: // a,b,p,q are aligned, [p,q]&[b,a] have the same direction if ( collinear_ordered(p,b,a) ) return make_object(segment(b,a)); else return make_object(segment(p,a)); - + case COLLINEAR: // case pqc == COLLINEAR is impossible since the triangle is // assumed to be non flat - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - + } - + default:// should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - + } } - - - + + template inline -Object +Object t3r3_intersection_aux(const typename K::Triangle_3 &t, const typename K::Ray_3 &r, const K& k) { typename K::Intersect_3 intersection = k.intersect_3_object(); - + Object obj = intersection(r.supporting_line(),t.supporting_plane()); - + // Intersection should be a point (because of orientation test done before) - if ( NULL == object_cast(&obj) ) - return obj; - else + if ( obj.is() ) return Object(); + else + return obj; } + template Object intersection(const typename K::Triangle_3 &t, @@ -469,22 +459,22 @@ intersection(const typename K::Triangle_3 &t, { CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; - + typedef typename K::Point_3 Point_3; - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = + + typename K::Orientation_3 orientation = k.orientation_3_object(); - - typename K::Construct_ray_3 ray = + + typename K::Construct_ray_3 ray = k.construct_ray_3_object(); - - typename K::Construct_point_on_3 point_on = + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + const Point_3& a = vertex_on(t,0); const Point_3& b = vertex_on(t,1); const Point_3& c = vertex_on(t,2); @@ -492,18 +482,18 @@ intersection(const typename K::Triangle_3 &t, const Point_3& q = point_on(r,1); Point_3 d = point_on(ray(a,r.to_vector()),1); - + const Orientation ray_direction = orientation(a,b,c,d); const Orientation abcp = orientation(a,b,c,p); switch ( abcp ) { - case POSITIVE: + case POSITIVE: switch ( ray_direction ) { - case POSITIVE: + case POSITIVE: // the ray lies in the positive open halfspaces defined by the // triangle's supporting plane return Object(); - + case NEGATIVE: // The ray straddles the triangle's plane // p sees the triangle in counterclockwise order @@ -513,46 +503,46 @@ intersection(const typename K::Triangle_3 &t, return t3r3_intersection_aux(t,r,k); else return Object(); - + case COPLANAR: // The ray lie in a plane parallel to a,b,c support plane return Object(); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + case NEGATIVE: switch ( ray_direction ) { - case POSITIVE: + case POSITIVE: // The ray straddles the triangle's plane // q sees the triangle in counterclockwise order - + if ( orientation(q,p,a,b) != POSITIVE && orientation(q,p,b,c) != POSITIVE && orientation(q,p,c,a) != POSITIVE ) return t3r3_intersection_aux(t,r,k); else return Object(); - + case NEGATIVE: // the ray lies in the negative open halfspaces defined by the // triangle's supporting plane return Object(); - + case COPLANAR: // The ray lie in a plane parallel to a,b,c support plane return Object(); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + case COPLANAR: // p belongs to the triangle's supporting plane switch ( ray_direction ) { - case POSITIVE: + case POSITIVE: // q sees the triangle in counterclockwise order if ( orientation(q,p,a,b) != POSITIVE && orientation(q,p,b,c) != POSITIVE @@ -560,7 +550,7 @@ intersection(const typename K::Triangle_3 &t, return t3r3_intersection_aux(t,r,k); else return Object(); - + case NEGATIVE: // q sees the triangle in clockwise order if ( orientation(p,q,a,b) != POSITIVE @@ -569,23 +559,22 @@ intersection(const typename K::Triangle_3 &t, return t3r3_intersection_aux(t,r,k); else return Object(); - - case COPLANAR: + + case COPLANAR: // The ray lie in triangle supporting plane return intersection_coplanar(t,r,k); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - - } - - CGAL_kernel_assertion(false); + } + + CGAL_error(); return Object(); } diff --git a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Segment_3_intersection.h b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Segment_3_intersection.h index 0ceb450287a..c918aa18777 100644 --- a/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Segment_3_intersection.h +++ b/AABB_tree/include/CGAL/internal/AABB_Intersections_3/Triangle_3_Segment_3_intersection.h @@ -40,41 +40,41 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& p, const typename K::Point_3& a, const typename K::Point_3& b, const K& k) -{ +{ // Returns the intersection point between segment [p,q] and [a,b] // // preconditions: // + p,q,a,b are coplanar - + typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; typedef typename K::FT FT; - - typename K::Construct_vector_3 vector = + + typename K::Construct_vector_3 vector = k.construct_vector_3_object(); - - typename K::Construct_cross_product_vector_3 cross_product = + + typename K::Construct_cross_product_vector_3 cross_product = k.construct_cross_product_vector_3_object(); - - typename K::Compute_scalar_product_3 scalar_product = + + typename K::Compute_scalar_product_3 scalar_product = k.compute_scalar_product_3_object(); - - typename K::Compute_squared_length_3 sq_length = + + typename K::Compute_squared_length_3 sq_length = k.compute_squared_length_3_object(); - + const Vector_3 pq = vector(p,q); const Vector_3 ab = vector(a,b); const Vector_3 pa = vector(p,a); - + const Vector_3 pa_ab = cross_product(pa,ab); const Vector_3 pq_ab = cross_product(pq,ab); - + const FT t = scalar_product(pa_ab,pq_ab) / sq_length(pq_ab); - + return ( p + t*pq ); } - - + + template Object t3s3_intersection_coplanar_aux(const typename K::Point_3& a, @@ -97,18 +97,18 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& a, // // We know that c is isolated on the negative side of pq, but we don't know // p position wrt [bc]&[ca] and q position wrt [bc]&[ca] - + typedef typename K::Point_3 Point_3; - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - + const Orientation bcq = coplanar_orientation(b,c,q); const Orientation cap = coplanar_orientation(c,a,p); - + if ( NEGATIVE == bcq || NEGATIVE == cap ) return Object(); else if ( COLLINEAR == bcq ) @@ -126,7 +126,7 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& a, { p_side_end_point = t3s3_intersection_coplanar_aux(p,q,b,c,k); } - + Point_3 q_side_end_point(q); if ( NEGATIVE == coplanar_orientation(c,a,q) ) { @@ -137,27 +137,27 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& a, return make_object(segment(p_side_end_point, q_side_end_point)); else return make_object(segment(q_side_end_point, p_side_end_point)); - } + } } - - + + template Object t3s3_intersection_collinear_aux(const typename K::Point_3& a, const typename K::Point_3& b, const typename K::Point_3& p, const typename K::Point_3& q, - const K& k) + const K& k) { // Builds resulting segment of intersection of [a,b] and [p,q] // Precondition: [a,b] and [p,q] have the same direction - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); - + // possible orders: [p,a,b,q], [p,a,q,b], [a,p,b,q], [a,p,q,b] if ( collinear_ordered(p,a,q) ) { @@ -175,52 +175,52 @@ t3s3_intersection_collinear_aux(const typename K::Point_3& a, else return make_object(segment(p,q)); } - } - + + template Object -intersection_coplanar(const typename K::Triangle_3 &t, +intersection_coplanar(const typename K::Triangle_3 &t, const typename K::Segment_3 &s, const K & k ) { - + CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; - + typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = + + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = + + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); - + typename K::Construct_line_3 line = k.construct_line_3_object(); - + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - - + + const Point_3 & p = point_on(s,0); const Point_3 & q = point_on(s,1); - + const Point_3 & A = vertex_on(t,0); const Point_3 & B = vertex_on(t,1); const Point_3 & C = vertex_on(t,2); - + int k0 = 0; int k1 = 1; int k2 = 2; - + // Determine the orientation of the triangle in the common plane if (coplanar_orientation(A,B,C) != POSITIVE) { @@ -228,21 +228,21 @@ intersection_coplanar(const typename K::Triangle_3 &t, // swap two vertices. std::swap(k1,k2); } - + const Point_3& a = vertex_on(t,k0); const Point_3& b = vertex_on(t,k1); const Point_3& c = vertex_on(t,k2); - + // Test whether the segment's supporting line intersects the // triangle in the common plane const Orientation pqa = coplanar_orientation(p,q,a); const Orientation pqb = coplanar_orientation(p,q,b); const Orientation pqc = coplanar_orientation(p,q,c); - + switch ( pqa ) { // ----------------------------------- // pqa POSITIVE - // ----------------------------------- + // ----------------------------------- case POSITIVE: switch ( pqb ) { case POSITIVE: @@ -260,7 +260,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return Object(); } - + case NEGATIVE: if ( POSITIVE == pqc ) // b is isolated on the negative side @@ -283,15 +283,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, // b,c,p,q are aligned, [p,q]&[b,c] have the same direction return t3s3_intersection_collinear_aux(b,c,p,q,k); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa NEGATIVE - // ----------------------------------- + // ----------------------------------- case NEGATIVE: switch ( pqb ) { case POSITIVE: @@ -301,7 +301,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, else // b is isolated on the positive side return t3s3_intersection_coplanar_aux(c,a,b,q,p,false,k); - + case NEGATIVE: switch ( pqc ) { case POSITIVE: @@ -317,12 +317,12 @@ intersection_coplanar(const typename K::Triangle_3 &t, else return Object(); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: // a is isolated on the negative side - return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k); + return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k); case NEGATIVE: if ( collinear_ordered(p,b,q) ) // b is inside [p,q] return make_object(b); @@ -332,15 +332,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, // b,c,p,q are aligned, [p,q]&[c,b] have the same direction return t3s3_intersection_collinear_aux(c,b,p,q,k); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + // ----------------------------------- // pqa COLLINEAR - // ----------------------------------- + // ----------------------------------- case COLLINEAR: switch ( pqb ) { case POSITIVE: @@ -357,7 +357,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a,c,p,q are aligned, [p,q]&[c,a] have the same direction return t3s3_intersection_collinear_aux(c,a,p,q,k); } - + case NEGATIVE: switch ( pqc ) { case POSITIVE: @@ -372,7 +372,7 @@ intersection_coplanar(const typename K::Triangle_3 &t, // a,c,p,q are aligned, [p,q]&[a,c] have the same direction return t3s3_intersection_collinear_aux(a,c,p,q,k); } - + case COLLINEAR: switch ( pqc ) { case POSITIVE: @@ -384,59 +384,54 @@ intersection_coplanar(const typename K::Triangle_3 &t, case COLLINEAR: // case pqc == COLLINEAR is impossible since the triangle is // assumed to be non flat - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - } - + default:// should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); - } } template Object -intersection(const typename K::Triangle_3 &t, +intersection(const typename K::Triangle_3 &t, const typename K::Segment_3 &s, const K & k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; - + typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = + + typename K::Orientation_3 orientation = k.orientation_3_object(); - + typename K::Intersect_3 intersection = k.intersect_3_object(); - + const Point_3 & a = vertex_on(t,0); const Point_3 & b = vertex_on(t,1); const Point_3 & c = vertex_on(t,2); const Point_3 & p = point_on(s,0); const Point_3 & q = point_on(s,1); - - + const Orientation abcp = orientation(a,b,c,p); const Orientation abcq = orientation(a,b,c,q); - + switch ( abcp ) { case POSITIVE: switch ( abcq ) { @@ -444,23 +439,23 @@ intersection(const typename K::Triangle_3 &t, // the segment lies in the positive open halfspaces defined by the // triangle's supporting plane return Object(); - + case NEGATIVE: // p sees the triangle in counterclockwise order if ( orientation(p,q,a,b) != POSITIVE && orientation(p,q,b,c) != POSITIVE && orientation(p,q,c,a) != POSITIVE ) - { + { // The intersection should be a point - Object obj = intersection(s.supporting_line(),t.supporting_plane()); - if ( NULL == object_cast(&obj) ) - return obj; - else + Object obj = intersection(s.supporting_line(),t.supporting_plane()); + if ( obj.is() ) return Object(); + else + return obj; } else return Object(); - + case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in counterclockwise order @@ -470,9 +465,9 @@ intersection(const typename K::Triangle_3 &t, return make_object(q); else return Object(); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } case NEGATIVE: @@ -482,21 +477,21 @@ intersection(const typename K::Triangle_3 &t, if ( orientation(q,p,a,b) != POSITIVE && orientation(q,p,b,c) != POSITIVE && orientation(q,p,c,a) != POSITIVE ) - { - Object obj = intersection(s.supporting_line(),t.supporting_plane()); - if ( NULL == object_cast(&obj) ) - return obj; - else + { + Object obj = intersection(s.supporting_line(),t.supporting_plane()); + if ( obj.is() ) return Object(); + else + return obj; } else return Object(); - + case NEGATIVE: // the segment lies in the negative open halfspaces defined by the // triangle's supporting plane return Object(); - + case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in clockwise order @@ -506,9 +501,9 @@ intersection(const typename K::Triangle_3 &t, return make_object(q); else return Object(); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } case COPLANAR: // p belongs to the triangle's supporting plane @@ -521,7 +516,7 @@ intersection(const typename K::Triangle_3 &t, return make_object(p); else return Object(); - + case NEGATIVE: // q sees the triangle in clockwise order if ( orientation(p,q,a,b) != POSITIVE @@ -530,34 +525,34 @@ intersection(const typename K::Triangle_3 &t, return make_object(p); else return Object(); - + case COPLANAR: // the segment is coplanar with the triangle's supporting plane - // we test whether the segment intersects the triangle in the common + // we test whether the segment intersects the triangle in the common // supporting plane return intersection_coplanar(t,s,k); - + default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } default: // should not happen. - CGAL_kernel_assertion(false); + CGAL_error(); return Object(); } } - + template inline Object intersection(const typename K::Segment_3 &s, const typename K::Triangle_3 &t, const K & k) -{ +{ return internal::intersection(t,s,k); } - - + + } // end namespace internal template @@ -579,4 +574,3 @@ intersection(const Segment_3 &s, const Triangle_3 &t) } // end namespace CGAL #endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H - diff --git a/AABB_tree/test/AABB_tree/bbox_other_do_intersect_test.cpp b/AABB_tree/test/AABB_tree/bbox_other_do_intersect_test.cpp index 833454449a8..b3bf30cfa1e 100644 --- a/AABB_tree/test/AABB_tree/bbox_other_do_intersect_test.cpp +++ b/AABB_tree/test/AABB_tree/bbox_other_do_intersect_test.cpp @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -271,6 +272,9 @@ bool test() test_aux(line2, "line2", bbox2, false); test_aux(line3, "line3", bbox3, true); test_aux(line4, "line4", bbox4, false); + + // Use do_intersect(bbox,bbox) + CGAL::do_intersect(bbox2,bbox4); return b; }