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 )
#endif
#include <CGAL/Bbox_3.h>
CGAL_BEGIN_NAMESPACE
bool

View File

@ -61,7 +61,6 @@ namespace internal {
}
FT dmax = dmin;
// -----------------------------------
// treat y coord
// -----------------------------------
@ -94,7 +93,6 @@ namespace internal {
dmax = d_;
}
// -----------------------------------
// treat z coord
// -----------------------------------
@ -123,8 +121,8 @@ namespace internal {
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(),
@ -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

View File

@ -103,7 +103,6 @@ namespace internal {
dmax = d_;
}
// -----------------------------------
// treat z coord
// -----------------------------------
@ -131,8 +130,8 @@ namespace internal {
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(),
@ -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

View File

@ -104,7 +104,6 @@ namespace internal {
dmax = d_;
}
// -----------------------------------
// treat z coord
// -----------------------------------
@ -132,8 +131,8 @@ namespace internal {
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(),

View File

@ -157,7 +157,7 @@ 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.);
}
}
@ -221,7 +221,7 @@ namespace internal {
break;
default:
// Should not happen
CGAL_kernel_assertion(false);
CGAL_error();
return false;
}
}

View File

@ -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
@ -59,8 +59,8 @@ t3l3_intersection_coplanar_aux(const typename K::Line_3& l,
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);
@ -122,13 +122,11 @@ 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 =
k.construct_point_on_3_object();
@ -144,7 +142,6 @@ intersection_coplanar(const typename K::Triangle_3 &t,
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);
@ -215,7 +212,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -260,7 +257,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -306,20 +303,18 @@ 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();
}
}
@ -337,14 +332,13 @@ t3l3_intersection_aux(const typename K::Triangle_3 &t,
Object obj = intersection(l,t.supporting_plane());
// Intersection should be a point (because of orientation test done before)
if ( NULL == object_cast<typename K::Line_3>(&obj) )
return obj;
else
if ( obj.is<typename K::Line_3>() )
return Object();
else
return obj;
}
template <class K>
Object
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 & q = point_on(l,1);
if ( ( orientation(a,b,c,p) != 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);
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
}

View File

@ -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.
//******************************************************************************
@ -51,16 +50,16 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& p,
typedef typename K::FT FT;
typename K::Construct_vector_3 vector =
k.construct_vector_3_object();
k.construct_vector_3_object();
typename K::Construct_cross_product_vector_3 cross_product =
k.construct_cross_product_vector_3_object();
k.construct_cross_product_vector_3_object();
typename K::Compute_scalar_product_3 scalar_product =
k.compute_scalar_product_3_object();
k.compute_scalar_product_3_object();
typename K::Compute_squared_length_3 sq_length =
k.compute_squared_length_3_object();
k.compute_squared_length_3_object();
const Vector_3 ab = vector(a,b);
const Vector_3 pa = vector(p,a);
@ -111,11 +110,8 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a,
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 ) {
@ -160,20 +156,15 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
template <class K>
Object
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;
typename K::Construct_point_on_3 point_on =
k.construct_point_on_3_object();
@ -291,7 +281,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -351,7 +341,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -423,25 +413,24 @@ 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 <class K>
inline
Object
@ -455,12 +444,13 @@ t3r3_intersection_aux(const typename K::Triangle_3 &t,
Object obj = intersection(r.supporting_line(),t.supporting_plane());
// Intersection should be a point (because of orientation test done before)
if ( NULL == object_cast<typename K::Line_3>(&obj) )
return obj;
else
if ( obj.is<typename K::Line_3>() )
return Object();
else
return obj;
}
template <class K>
Object
intersection(const typename K::Triangle_3 &t,
@ -519,7 +509,7 @@ intersection(const typename K::Triangle_3 &t,
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -546,7 +536,7 @@ intersection(const typename K::Triangle_3 &t,
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -575,17 +565,16 @@ intersection(const typename K::Triangle_3 &t,
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();
}

View File

@ -175,9 +175,9 @@ t3s3_intersection_collinear_aux(const typename K::Point_3& a,
else
return make_object(segment(p,q));
}
}
template <class K>
Object
intersection_coplanar(const typename K::Triangle_3 &t,
@ -285,7 +285,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -334,7 +334,7 @@ intersection_coplanar(const typename K::Triangle_3 &t,
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
@ -384,20 +384,18 @@ 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();
}
}
@ -408,13 +406,11 @@ 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 =
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 & q = point_on(s,1);
const Orientation abcp = orientation(a,b,c,p);
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
Object obj = intersection(s.supporting_line(),t.supporting_plane());
if ( NULL == object_cast<typename K::Line_3>(&obj) )
return obj;
else
if ( obj.is<typename K::Line_3>() )
return Object();
else
return obj;
}
else
return Object();
@ -472,7 +467,7 @@ intersection(const typename K::Triangle_3 &t,
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
case NEGATIVE:
@ -484,10 +479,10 @@ intersection(const typename K::Triangle_3 &t,
&& orientation(q,p,c,a) != POSITIVE )
{
Object obj = intersection(s.supporting_line(),t.supporting_plane());
if ( NULL == object_cast<typename K::Line_3>(&obj) )
return obj;
else
if ( obj.is<typename K::Line_3>() )
return Object();
else
return obj;
}
else
return Object();
@ -508,7 +503,7 @@ intersection(const typename K::Triangle_3 &t,
return Object();
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
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);
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
default: // should not happen.
CGAL_kernel_assertion(false);
CGAL_error();
return Object();
}
}
@ -579,4 +574,3 @@ intersection(const Segment_3<K> &s, const Triangle_3<K> &t)
} // end namespace CGAL
#endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H

View File

@ -25,6 +25,7 @@
#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_Line_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(line4, "line4", bbox4, false);
// Use do_intersect(bbox,bbox)
CGAL::do_intersect(bbox2,bbox4);
return b;
}