Implement Sylvain's comments:

+ add missing includes
  + avoid object copies
  + replace CGAL_kernel_assertion(false) by CGAL_error()
  + use is() function of CGAL::Object
  + improve style (remove spaces, white lines...)
This commit is contained in:
Stéphane Tayeb 2009-12-16 17:03:17 +00:00
parent b9a62e057c
commit cab2982563
12 changed files with 487 additions and 514 deletions

View File

@ -26,6 +26,8 @@
#pragma warning ( disable : 4003 ) #pragma warning ( disable : 4003 )
#endif #endif
#include <CGAL/Bbox_3.h>
CGAL_BEGIN_NAMESPACE CGAL_BEGIN_NAMESPACE
bool bool

View File

@ -61,7 +61,6 @@ namespace internal {
} }
FT dmax = dmin; FT dmax = dmin;
// ----------------------------------- // -----------------------------------
// treat y coord // treat y coord
// ----------------------------------- // -----------------------------------
@ -94,7 +93,6 @@ namespace internal {
dmax = d_; dmax = d_;
} }
// ----------------------------------- // -----------------------------------
// treat z coord // treat z coord
// ----------------------------------- // -----------------------------------
@ -123,8 +121,8 @@ namespace internal {
typedef typename K::Point_3 Point_3; typedef typename K::Point_3 Point_3;
typedef typename K::Vector_3 Vector_3; typedef typename K::Vector_3 Vector_3;
const Point_3 point = line.point(); const Point_3& point = line.point();
const Vector_3 v = line.to_vector(); const Vector_3& v = line.to_vector();
return bbox_line_do_intersect_aux( return bbox_line_do_intersect_aux(
point.x(), point.y(), point.z(), point.x(), point.y(), point.z(),
@ -152,5 +150,3 @@ bool do_intersect(const CGAL::Bbox_3& bbox,
CGAL_END_NAMESPACE CGAL_END_NAMESPACE
#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H #endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H

View File

@ -103,7 +103,6 @@ namespace internal {
dmax = d_; dmax = d_;
} }
// ----------------------------------- // -----------------------------------
// treat z coord // treat z coord
// ----------------------------------- // -----------------------------------
@ -131,8 +130,8 @@ namespace internal {
typedef typename K::FT FT; typedef typename K::FT FT;
typedef typename K::Point_3 Point_3; typedef typename K::Point_3 Point_3;
const Point_3 source = ray.source(); const Point_3& source = ray.source();
const Point_3 point_on_ray = ray.point(1); const Point_3& point_on_ray = ray.point(1);
return bbox_ray_do_intersect_aux( return bbox_ray_do_intersect_aux(
source.x(), source.y(), source.z(), source.x(), source.y(), source.z(),
@ -160,5 +159,3 @@ bool do_intersect(const CGAL::Bbox_3& bbox,
CGAL_END_NAMESPACE CGAL_END_NAMESPACE
#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H #endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H

View File

@ -104,7 +104,6 @@ namespace internal {
dmax = d_; dmax = d_;
} }
// ----------------------------------- // -----------------------------------
// treat z coord // treat z coord
// ----------------------------------- // -----------------------------------
@ -132,8 +131,8 @@ namespace internal {
typedef typename K::FT FT; typedef typename K::FT FT;
typedef typename K::Point_3 Point_3; typedef typename K::Point_3 Point_3;
const Point_3 source = segment.source(); const Point_3& source = segment.source();
const Point_3 target = segment.target(); const Point_3& target = segment.target();
return do_intersect_bbox_segment_aux( return do_intersect_bbox_segment_aux(
source.x(), source.y(), source.z(), source.x(), source.y(), source.z(),

View File

@ -157,7 +157,7 @@ namespace internal {
case 2: case 2:
return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta; return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta;
default: default:
CGAL_kernel_assertion(false); CGAL_error();
return typename K::FT(0.); return typename K::FT(0.);
} }
} }
@ -221,7 +221,7 @@ namespace internal {
break; break;
default: default:
// Should not happen // Should not happen
CGAL_kernel_assertion(false); CGAL_error();
return false; return false;
} }
} }

View File

@ -16,12 +16,12 @@
// //
// //
// Author(s) : Stéphane Tayeb // 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 #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H
#define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H #define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H
@ -59,8 +59,8 @@ t3l3_intersection_coplanar_aux(const typename K::Line_3& l,
typename K::Compute_squared_length_3 sq_length = typename K::Compute_squared_length_3 sq_length =
k.compute_squared_length_3_object(); k.compute_squared_length_3_object();
const Point_3 p = l.point(); const Point_3& p = l.point();
const Vector_3 v = l.to_vector(); const Vector_3& v = l.to_vector();
const Vector_3 ab = vector(a,b); const Vector_3 ab = vector(a,b);
const Vector_3 pa = vector(p,a); const Vector_3 pa = vector(p,a);
@ -122,13 +122,11 @@ intersection_coplanar(const typename K::Triangle_3 &t,
const typename K::Line_3 &l, const typename K::Line_3 &l,
const K & k ) const K & k )
{ {
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ;
typedef typename K::Point_3 Point_3; 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(); k.construct_point_on_3_object();
@ -144,7 +142,6 @@ intersection_coplanar(const typename K::Triangle_3 &t,
typename K::Construct_segment_3 segment = typename K::Construct_segment_3 segment =
k.construct_segment_3_object(); k.construct_segment_3_object();
const Point_3 & p = point_on(l,0); const Point_3 & p = point_on(l,0);
const Point_3 & q = point_on(l,1); const Point_3 & q = point_on(l,1);
@ -215,7 +212,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -260,7 +257,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -306,20 +303,18 @@ intersection_coplanar(const typename K::Triangle_3 &t,
case COLLINEAR: case COLLINEAR:
// case pqc == COLLINEAR is impossible since the triangle is // case pqc == COLLINEAR is impossible since the triangle is
// assumed to be non flat // assumed to be non flat
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default:// should not happen. default:// should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
} }
@ -337,14 +332,13 @@ t3l3_intersection_aux(const typename K::Triangle_3 &t,
Object obj = intersection(l,t.supporting_plane()); Object obj = intersection(l,t.supporting_plane());
// Intersection should be a point (because of orientation test done before) // Intersection should be a point (because of orientation test done before)
if ( NULL == object_cast<typename K::Line_3>(&obj) ) if ( obj.is<typename K::Line_3>() )
return obj;
else
return Object(); return Object();
else
return obj;
} }
template <class K> template <class K>
Object Object
intersection(const typename K::Triangle_3 &t, intersection(const typename K::Triangle_3 &t,
@ -377,8 +371,6 @@ intersection(const typename K::Triangle_3 &t,
const Point_3 & p = point_on(l,0); const Point_3 & p = point_on(l,0);
const Point_3 & q = point_on(l,1); const Point_3 & q = point_on(l,1);
if ( ( orientation(a,b,c,p) != COPLANAR ) if ( ( orientation(a,b,c,p) != COPLANAR )
|| ( orientation(a,b,c,q) != COPLANAR ) ) || ( orientation(a,b,c,q) != COPLANAR ) )
{ {
@ -415,12 +407,12 @@ intersection(const typename K::Triangle_3 &t,
return t3l3_intersection_aux(t,l,k); return t3l3_intersection_aux(t,l,k);
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
} }

View File

@ -19,7 +19,6 @@
// //
//****************************************************************************** //******************************************************************************
// File Description : Implements triangle_3 ray_3 intersection construction. // File Description : Implements triangle_3 ray_3 intersection construction.
//
// This implementation is adapted from Triangle_3_Ray_3_do_intersect.h. // This implementation is adapted from Triangle_3_Ray_3_do_intersect.h.
//****************************************************************************** //******************************************************************************
@ -111,11 +110,8 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a,
const Point_3& p = point_on(r,0); const Point_3& p = point_on(r,0);
// A ray is not symetric, 2 cases depending on isolated side of c // A ray is not symetric, 2 cases depending on isolated side of c
Orientation cap; Orientation cap = negative_side ? coplanar_orientation(c,a,p)
if ( negative_side ) : coplanar_orientation(b,c,p);
cap = coplanar_orientation(c,a,p);
else
cap = coplanar_orientation(b,c,p);
switch ( cap ) { switch ( cap ) {
@ -160,20 +156,15 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
template <class K> template <class K>
Object Object
intersection_coplanar(const typename K::Triangle_3 &t, intersection_coplanar(const typename K::Triangle_3 &t,
@ -185,7 +176,6 @@ intersection_coplanar(const typename K::Triangle_3 &t,
typedef typename K::Point_3 Point_3; 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(); k.construct_point_on_3_object();
@ -291,7 +281,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -351,7 +341,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -423,25 +413,24 @@ intersection_coplanar(const typename K::Triangle_3 &t,
case COLLINEAR: case COLLINEAR:
// case pqc == COLLINEAR is impossible since the triangle is // case pqc == COLLINEAR is impossible since the triangle is
// assumed to be non flat // assumed to be non flat
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default:// should not happen. default:// should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
} }
template <class K> template <class K>
inline inline
Object Object
@ -455,12 +444,13 @@ t3r3_intersection_aux(const typename K::Triangle_3 &t,
Object obj = intersection(r.supporting_line(),t.supporting_plane()); Object obj = intersection(r.supporting_line(),t.supporting_plane());
// Intersection should be a point (because of orientation test done before) // Intersection should be a point (because of orientation test done before)
if ( NULL == object_cast<typename K::Line_3>(&obj) ) if ( obj.is<typename K::Line_3>() )
return obj;
else
return Object(); return Object();
else
return obj;
} }
template <class K> template <class K>
Object Object
intersection(const typename K::Triangle_3 &t, intersection(const typename K::Triangle_3 &t,
@ -519,7 +509,7 @@ intersection(const typename K::Triangle_3 &t,
return Object(); return Object();
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -546,7 +536,7 @@ intersection(const typename K::Triangle_3 &t,
return Object(); return Object();
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -575,17 +565,16 @@ intersection(const typename K::Triangle_3 &t,
return intersection_coplanar(t,r,k); return intersection_coplanar(t,r,k);
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }

View File

@ -175,9 +175,9 @@ t3s3_intersection_collinear_aux(const typename K::Point_3& a,
else else
return make_object(segment(p,q)); return make_object(segment(p,q));
} }
} }
template <class K> template <class K>
Object Object
intersection_coplanar(const typename K::Triangle_3 &t, intersection_coplanar(const typename K::Triangle_3 &t,
@ -285,7 +285,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -334,7 +334,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
@ -384,20 +384,18 @@ intersection_coplanar(const typename K::Triangle_3 &t,
case COLLINEAR: case COLLINEAR:
// case pqc == COLLINEAR is impossible since the triangle is // case pqc == COLLINEAR is impossible since the triangle is
// assumed to be non flat // assumed to be non flat
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default:// should not happen. default:// should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
} }
@ -408,13 +406,11 @@ intersection(const typename K::Triangle_3 &t,
const typename K::Segment_3 &s, const typename K::Segment_3 &s,
const K & k) const K & k)
{ {
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ;
CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ;
typedef typename K::Point_3 Point_3; 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(); k.construct_point_on_3_object();
@ -433,7 +429,6 @@ intersection(const typename K::Triangle_3 &t,
const Point_3 & p = point_on(s,0); const Point_3 & p = point_on(s,0);
const Point_3 & q = point_on(s,1); const Point_3 & q = point_on(s,1);
const Orientation abcp = orientation(a,b,c,p); const Orientation abcp = orientation(a,b,c,p);
const Orientation abcq = orientation(a,b,c,q); const Orientation abcq = orientation(a,b,c,q);
@ -453,10 +448,10 @@ intersection(const typename K::Triangle_3 &t,
{ {
// The intersection should be a point // The intersection should be a point
Object obj = intersection(s.supporting_line(),t.supporting_plane()); Object obj = intersection(s.supporting_line(),t.supporting_plane());
if ( NULL == object_cast<typename K::Line_3>(&obj) ) if ( obj.is<typename K::Line_3>() )
return obj;
else
return Object(); return Object();
else
return obj;
} }
else else
return Object(); return Object();
@ -472,7 +467,7 @@ intersection(const typename K::Triangle_3 &t,
return Object(); return Object();
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
case NEGATIVE: case NEGATIVE:
@ -484,10 +479,10 @@ intersection(const typename K::Triangle_3 &t,
&& orientation(q,p,c,a) != POSITIVE ) && orientation(q,p,c,a) != POSITIVE )
{ {
Object obj = intersection(s.supporting_line(),t.supporting_plane()); Object obj = intersection(s.supporting_line(),t.supporting_plane());
if ( NULL == object_cast<typename K::Line_3>(&obj) ) if ( obj.is<typename K::Line_3>() )
return obj;
else
return Object(); return Object();
else
return obj;
} }
else else
return Object(); return Object();
@ -508,7 +503,7 @@ intersection(const typename K::Triangle_3 &t,
return Object(); return Object();
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
case COPLANAR: // p belongs to the triangle's supporting plane case COPLANAR: // p belongs to the triangle's supporting plane
@ -538,11 +533,11 @@ intersection(const typename K::Triangle_3 &t,
return intersection_coplanar(t,s,k); return intersection_coplanar(t,s,k);
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
default: // should not happen. default: // should not happen.
CGAL_kernel_assertion(false); CGAL_error();
return Object(); return Object();
} }
} }
@ -579,4 +574,3 @@ intersection(const Segment_3<K> &s, const Triangle_3<K> &t)
} // end namespace CGAL } // end namespace CGAL
#endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H #endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <CGAL/internal/AABB_Intersections_3/Bbox_3_Bbox_3_do_intersect.h>
#include <CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h> #include <CGAL/internal/AABB_Intersections_3/Bbox_3_Ray_3_do_intersect.h>
#include <CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h> #include <CGAL/internal/AABB_Intersections_3/Bbox_3_Line_3_do_intersect.h>
#include <CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h> #include <CGAL/internal/AABB_Intersections_3/Bbox_3_Segment_3_do_intersect.h>
@ -272,6 +273,9 @@ bool test()
test_aux(line3, "line3", bbox3, true); test_aux(line3, "line3", bbox3, true);
test_aux(line4, "line4", bbox4, false); test_aux(line4, "line4", bbox4, false);
// Use do_intersect(bbox,bbox)
CGAL::do_intersect(bbox2,bbox4);
return b; return b;
} }