diff --git a/Intersections_2/include/CGAL/Ray_2_Iso_rectangle_2_intersection.h b/Intersections_2/include/CGAL/Ray_2_Iso_rectangle_2_intersection.h index f9290a3d3d2..dcae81a0e7b 100644 --- a/Intersections_2/include/CGAL/Ray_2_Iso_rectangle_2_intersection.h +++ b/Intersections_2/include/CGAL/Ray_2_Iso_rectangle_2_intersection.h @@ -42,14 +42,15 @@ template class Ray_2_Iso_rectangle_2_pair { public: enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT}; - Ray_2_Iso_rectangle_2_pair() ; Ray_2_Iso_rectangle_2_pair(typename K::Ray_2 const *ray, - typename K::Iso_rectangle_2 const *rect) ; + typename K::Iso_rectangle_2 const *iso) + : _known(false), _ref_point(ray->source()), _dir(ray->direction().to_vector()), + _isomin((iso->min)()), _isomax((iso->max)()), _min((typename K::FT)(0)) {} - Intersection_results intersection_type() const; + Intersection_results intersection_type() const; - bool intersection( typename K::Point_2 &result) const; - bool intersection( typename K::Segment_2 &result) const; + typename K::Point_2 intersection_point() const; + typename K::Segment_2 intersection_segment() const; protected: mutable bool _known; mutable Intersection_results _result; @@ -57,8 +58,7 @@ protected: mutable typename K::Vector_2 _dir; mutable typename K::Point_2 _isomin; mutable typename K::Point_2 _isomax; - mutable typename K::FT _min, - _max; + mutable typename K::FT _min, _max; }; template @@ -91,16 +91,10 @@ intersection(const typename K::Ray_2 &ray, case is_t::NO_INTERSECTION: default: return Object(); - case is_t::POINT: { - typename K::Point_2 ipt; - ispair.intersection(ipt); - return make_object(ipt); - } - case is_t::SEGMENT: { - typename K::Segment_2 iseg; - ispair.intersection(iseg); - return make_object(iseg); - } + case is_t::POINT: + return make_object(ispair.intersection_point()); + case is_t::SEGMENT: + return make_object(ispair.intersection_segment()); } } @@ -113,27 +107,6 @@ intersection(const typename K::Iso_rectangle_2 &iso, return intersection(ray, iso, k); } - -template -Ray_2_Iso_rectangle_2_pair::Ray_2_Iso_rectangle_2_pair() -{ - _known = false; -} - -template -Ray_2_Iso_rectangle_2_pair:: -Ray_2_Iso_rectangle_2_pair( - typename K::Ray_2 const *ray, - typename K::Iso_rectangle_2 const *iso) -{ - _known = false; - _isomin = (iso->min)(); - _isomax = (iso->max)(); - _ref_point = ray->source(); - _dir = ray->direction().to_vector(); - _min = (typename K::FT)(0); -} - template typename Ray_2_Iso_rectangle_2_pair::Intersection_results Ray_2_Iso_rectangle_2_pair::intersection_type() const @@ -200,47 +173,32 @@ Ray_2_Iso_rectangle_2_pair::intersection_type() const template -bool Ray_2_Iso_rectangle_2_pair:: -intersection(typename K::Segment_2 &seg) const +typename K::Segment_2 +Ray_2_Iso_rectangle_2_pair::intersection_segment() const { - typedef typename K::Segment_2 Segment_2; - typename K::Construct_translated_point_2 translated_point; - typename K::Construct_scaled_vector_2 construct_scaled_vector; + typedef typename K::Segment_2 Segment_2; + typename K::Construct_translated_point_2 translated_point; + typename K::Construct_scaled_vector_2 construct_scaled_vector; if (!_known) intersection_type(); - if (_result != SEGMENT) - return false; + CGAL_kernel_assertion(_result == SEGMENT); typename K::Point_2 p1(translated_point(_ref_point, construct_scaled_vector(_dir,_min))); typename K::Point_2 p2(translated_point(_ref_point, construct_scaled_vector(_dir,_max))); - seg = Segment_2(p1, p2); - return true; + return Segment_2(p1, p2); } -template bool Ray_2_Iso_rectangle_2_pair:: -intersection(typename K::Point_2 &pt) const -{ - typedef typename K::Point_2 Point_2; - typename K::Construct_translated_point_2 translated_point; - typename K::Construct_scaled_vector_2 construct_scaled_vector; - if (!_known) - intersection_type(); - if (_result != POINT) - return false; - pt = Point_2(translated_point(_ref_point, construct_scaled_vector(_dir, _min))); - return true; -} - - - template -class Iso_rectangle_2_Ray_2_pair: - public Ray_2_Iso_rectangle_2_pair { -public: - Iso_rectangle_2_Ray_2_pair() {} - Iso_rectangle_2_Ray_2_pair(typename K::Iso_rectangle_2 const *rect, - typename K::Ray_2 const *ray) - :Ray_2_Iso_rectangle_2_pair (ray, rect){} -}; +typename K::Point_2 +Ray_2_Iso_rectangle_2_pair::intersection_point() const +{ + typedef typename K::Point_2 Point_2; + typename K::Construct_translated_point_2 translated_point; + typename K::Construct_scaled_vector_2 construct_scaled_vector; + if (!_known) + intersection_type(); + CGAL_kernel_assertion(_result == POINT); + return Point_2(translated_point(_ref_point, construct_scaled_vector(_dir, _min))); +} } // namespace CGALi diff --git a/Intersections_2/include/CGAL/Segment_2_Line_2_intersection.h b/Intersections_2/include/CGAL/Segment_2_Line_2_intersection.h index df47e781bdc..61bf5e9b0be 100644 --- a/Intersections_2/include/CGAL/Segment_2_Line_2_intersection.h +++ b/Intersections_2/include/CGAL/Segment_2_Line_2_intersection.h @@ -41,14 +41,14 @@ template class Segment_2_Line_2_pair { public: enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT}; - Segment_2_Line_2_pair() ; Segment_2_Line_2_pair(typename K::Segment_2 const *seg, - typename K::Line_2 const *line); + typename K::Line_2 const *line) + : _seg(seg), _line(line), _known(false) {} Intersection_results intersection_type() const; - bool intersection(typename K::Point_2 &result) const; - bool intersection(typename K::Segment_2 &result) const; + typename K::Point_2 intersection_point() const; + typename K::Segment_2 intersection_segment() const; protected: typename K::Segment_2 const*_seg; typename K::Line_2 const * _line; @@ -80,11 +80,8 @@ intersection(const typename K::Segment_2 &seg, case is_t::NO_INTERSECTION: default: return Object(); - case is_t::POINT: { - typename K::Point_2 pt; - ispair.intersection(pt); - return make_object(pt); - } + case is_t::POINT: + return make_object(ispair.intersection_point()); case is_t::SEGMENT: return make_object(seg); } @@ -100,45 +97,18 @@ intersection(const typename K::Line_2 &line, } -template -class Line_2_Segment_2_pair: public Segment_2_Line_2_pair { -public: - Line_2_Segment_2_pair( - typename K::Line_2 const *line, - typename K::Segment_2 const *seg) : - Segment_2_Line_2_pair(seg, line) {} -}; - template inline bool do_intersect( const typename K::Line_2 &p1, const typename K::Segment_2 &p2, const K&) { - typedef Line_2_Segment_2_pair pair_t; - pair_t pair(&p1, &p2); + typedef Segment_2_Line_2_pair pair_t; + pair_t pair(&p2, &p1); return pair.intersection_type() != pair_t::NO_INTERSECTION; } - -template -Segment_2_Line_2_pair::Segment_2_Line_2_pair() -{ - _seg = 0; - _line = 0; - _known = false; -} - -template -Segment_2_Line_2_pair::Segment_2_Line_2_pair( - typename K::Segment_2 const *seg, typename K::Line_2 const *line) -{ - _seg = seg; - _line = line; - _known = false; -} - template typename Segment_2_Line_2_pair::Intersection_results Segment_2_Line_2_pair::intersection_type() const @@ -166,27 +136,23 @@ Segment_2_Line_2_pair::intersection_type() const } template -bool -Segment_2_Line_2_pair::intersection(typename K::Point_2 &result) const +typename K::Point_2 +Segment_2_Line_2_pair::intersection_point() const { if (!_known) intersection_type(); - if (_result != POINT) - return false; - result = _intersection_point; - return true; + CGAL_kernel_assertion(_result == POINT); + return _intersection_point; } template -bool -Segment_2_Line_2_pair::intersection(typename K::Segment_2 &result) const +typename K::Segment_2 +Segment_2_Line_2_pair::intersection_segment() const { if (!_known) intersection_type(); - if (_result != SEGMENT) - return false; - result = *_seg; - return true; + CGAL_kernel_assertion(_result == SEGMENT); + return *_seg; } } // namespace CGALi