From 8db83a466a6fc29c24f2543a8661dc6796b5f44f Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Sat, 30 Aug 2008 11:10:46 +0000 Subject: [PATCH] Refactorize Segment_2_Iso_rectangle_2_pair to avoid warning. --- .../Segment_2_Iso_rectangle_2_intersection.h | 66 ++++++------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/Intersections_2/include/CGAL/Segment_2_Iso_rectangle_2_intersection.h b/Intersections_2/include/CGAL/Segment_2_Iso_rectangle_2_intersection.h index d8066c7e2fd..fc7d5157011 100644 --- a/Intersections_2/include/CGAL/Segment_2_Iso_rectangle_2_intersection.h +++ b/Intersections_2/include/CGAL/Segment_2_Iso_rectangle_2_intersection.h @@ -39,14 +39,13 @@ template class Segment_2_Iso_rectangle_2_pair { public: enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT}; - Segment_2_Iso_rectangle_2_pair() ; Segment_2_Iso_rectangle_2_pair(typename K::Segment_2 const *seg, typename K::Iso_rectangle_2 const *rect) ; - 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; @@ -86,16 +85,10 @@ intersection( 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()); } } @@ -109,12 +102,6 @@ intersection(const typename K::Iso_rectangle_2 &iso, return CGALi::intersection(seg, iso, k); } -template -Segment_2_Iso_rectangle_2_pair::Segment_2_Iso_rectangle_2_pair() -{ - _known = false; -} - template Segment_2_Iso_rectangle_2_pair:: Segment_2_Iso_rectangle_2_pair( @@ -196,57 +183,44 @@ Segment_2_Iso_rectangle_2_pair::intersection_type() const template -bool Segment_2_Iso_rectangle_2_pair:: -intersection(typename K::Segment_2 &seg) const +typename K::Segment_2 +Segment_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; - 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 Segment_2_Iso_rectangle_2_pair:: -intersection(typename K::Point_2 &pt) const +template +typename K::Point_2 +Segment_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(); - if (_result != POINT) - return false; - pt = Point_2(translated_point(_ref_point, construct_scaled_vector(_dir,_min))); - return true; + CGAL_kernel_assertion(_result == POINT); + return translated_point(_ref_point, construct_scaled_vector(_dir,_min)); } -template -class Iso_rectangle_2_Segment_2_pair: - public Segment_2_Iso_rectangle_2_pair { -public: - Iso_rectangle_2_Segment_2_pair() {} - Iso_rectangle_2_Segment_2_pair(typename K::Iso_rectangle_2 const *rect, - typename K::Segment_2 const *seg) - :Segment_2_Iso_rectangle_2_pair (seg, rect){} -}; - template inline bool do_intersect( const typename K::Iso_rectangle_2 &p1, const typename K::Segment_2 &p2, const K&) { - typedef Iso_rectangle_2_Segment_2_pair pair_t; - pair_t pair(&p1, &p2); + typedef Segment_2_Iso_rectangle_2_pair pair_t; + pair_t pair(&p2, &p1); return pair.intersection_type() != pair_t::NO_INTERSECTION; }