More *_pair classes cleanups.

This commit is contained in:
Sylvain Pion 2008-09-07 15:09:56 +00:00
parent 64650bcffc
commit 696cbd9e6e
2 changed files with 45 additions and 121 deletions

View File

@ -42,14 +42,15 @@ template <class K>
class Ray_2_Iso_rectangle_2_pair { class Ray_2_Iso_rectangle_2_pair {
public: public:
enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT}; 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, 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; typename K::Point_2 intersection_point() const;
bool intersection( typename K::Segment_2 &result) const; typename K::Segment_2 intersection_segment() const;
protected: protected:
mutable bool _known; mutable bool _known;
mutable Intersection_results _result; mutable Intersection_results _result;
@ -57,8 +58,7 @@ protected:
mutable typename K::Vector_2 _dir; mutable typename K::Vector_2 _dir;
mutable typename K::Point_2 _isomin; mutable typename K::Point_2 _isomin;
mutable typename K::Point_2 _isomax; mutable typename K::Point_2 _isomax;
mutable typename K::FT _min, mutable typename K::FT _min, _max;
_max;
}; };
template <class K> template <class K>
@ -91,16 +91,10 @@ intersection(const typename K::Ray_2 &ray,
case is_t::NO_INTERSECTION: case is_t::NO_INTERSECTION:
default: default:
return Object(); return Object();
case is_t::POINT: { case is_t::POINT:
typename K::Point_2 ipt; return make_object(ispair.intersection_point());
ispair.intersection(ipt); case is_t::SEGMENT:
return make_object(ipt); return make_object(ispair.intersection_segment());
}
case is_t::SEGMENT: {
typename K::Segment_2 iseg;
ispair.intersection(iseg);
return make_object(iseg);
}
} }
} }
@ -113,27 +107,6 @@ intersection(const typename K::Iso_rectangle_2 &iso,
return intersection(ray, iso, k); return intersection(ray, iso, k);
} }
template <class K>
Ray_2_Iso_rectangle_2_pair<K>::Ray_2_Iso_rectangle_2_pair()
{
_known = false;
}
template <class K>
Ray_2_Iso_rectangle_2_pair<K>::
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 <class K> template <class K>
typename Ray_2_Iso_rectangle_2_pair<K>::Intersection_results typename Ray_2_Iso_rectangle_2_pair<K>::Intersection_results
Ray_2_Iso_rectangle_2_pair<K>::intersection_type() const Ray_2_Iso_rectangle_2_pair<K>::intersection_type() const
@ -200,47 +173,32 @@ Ray_2_Iso_rectangle_2_pair<K>::intersection_type() const
template <class K> template <class K>
bool Ray_2_Iso_rectangle_2_pair<K>:: typename K::Segment_2
intersection(typename K::Segment_2 &seg) const Ray_2_Iso_rectangle_2_pair<K>::intersection_segment() const
{ {
typedef typename K::Segment_2 Segment_2; typedef typename K::Segment_2 Segment_2;
typename K::Construct_translated_point_2 translated_point; typename K::Construct_translated_point_2 translated_point;
typename K::Construct_scaled_vector_2 construct_scaled_vector; typename K::Construct_scaled_vector_2 construct_scaled_vector;
if (!_known) if (!_known)
intersection_type(); intersection_type();
if (_result != SEGMENT) CGAL_kernel_assertion(_result == SEGMENT);
return false;
typename K::Point_2 p1(translated_point(_ref_point, construct_scaled_vector(_dir,_min))); 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))); typename K::Point_2 p2(translated_point(_ref_point, construct_scaled_vector(_dir,_max)));
seg = Segment_2(p1, p2); return Segment_2(p1, p2);
return true;
} }
template <class K> bool Ray_2_Iso_rectangle_2_pair<K>::
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 K> template <class K>
class Iso_rectangle_2_Ray_2_pair: typename K::Point_2
public Ray_2_Iso_rectangle_2_pair<K> { Ray_2_Iso_rectangle_2_pair<K>::intersection_point() const
public: {
Iso_rectangle_2_Ray_2_pair() {} typedef typename K::Point_2 Point_2;
Iso_rectangle_2_Ray_2_pair(typename K::Iso_rectangle_2 const *rect, typename K::Construct_translated_point_2 translated_point;
typename K::Ray_2 const *ray) typename K::Construct_scaled_vector_2 construct_scaled_vector;
:Ray_2_Iso_rectangle_2_pair<K> (ray, rect){} if (!_known)
}; intersection_type();
CGAL_kernel_assertion(_result == POINT);
return Point_2(translated_point(_ref_point, construct_scaled_vector(_dir, _min)));
}
} // namespace CGALi } // namespace CGALi

View File

@ -41,14 +41,14 @@ template <class K>
class Segment_2_Line_2_pair { class Segment_2_Line_2_pair {
public: public:
enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT}; enum Intersection_results {NO_INTERSECTION, POINT, SEGMENT};
Segment_2_Line_2_pair() ;
Segment_2_Line_2_pair(typename K::Segment_2 const *seg, 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; Intersection_results intersection_type() const;
bool intersection(typename K::Point_2 &result) const; typename K::Point_2 intersection_point() const;
bool intersection(typename K::Segment_2 &result) const; typename K::Segment_2 intersection_segment() const;
protected: protected:
typename K::Segment_2 const*_seg; typename K::Segment_2 const*_seg;
typename K::Line_2 const * _line; typename K::Line_2 const * _line;
@ -80,11 +80,8 @@ intersection(const typename K::Segment_2 &seg,
case is_t::NO_INTERSECTION: case is_t::NO_INTERSECTION:
default: default:
return Object(); return Object();
case is_t::POINT: { case is_t::POINT:
typename K::Point_2 pt; return make_object(ispair.intersection_point());
ispair.intersection(pt);
return make_object(pt);
}
case is_t::SEGMENT: case is_t::SEGMENT:
return make_object(seg); return make_object(seg);
} }
@ -100,45 +97,18 @@ intersection(const typename K::Line_2 &line,
} }
template <class K>
class Line_2_Segment_2_pair: public Segment_2_Line_2_pair<K> {
public:
Line_2_Segment_2_pair(
typename K::Line_2 const *line,
typename K::Segment_2 const *seg) :
Segment_2_Line_2_pair<K>(seg, line) {}
};
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const typename K::Line_2 &p1, const typename K::Line_2 &p1,
const typename K::Segment_2 &p2, const typename K::Segment_2 &p2,
const K&) const K&)
{ {
typedef Line_2_Segment_2_pair<K> pair_t; typedef Segment_2_Line_2_pair<K> pair_t;
pair_t pair(&p1, &p2); pair_t pair(&p2, &p1);
return pair.intersection_type() != pair_t::NO_INTERSECTION; return pair.intersection_type() != pair_t::NO_INTERSECTION;
} }
template <class K>
Segment_2_Line_2_pair<K>::Segment_2_Line_2_pair()
{
_seg = 0;
_line = 0;
_known = false;
}
template <class K>
Segment_2_Line_2_pair<K>::Segment_2_Line_2_pair(
typename K::Segment_2 const *seg, typename K::Line_2 const *line)
{
_seg = seg;
_line = line;
_known = false;
}
template <class K> template <class K>
typename Segment_2_Line_2_pair<K>::Intersection_results typename Segment_2_Line_2_pair<K>::Intersection_results
Segment_2_Line_2_pair<K>::intersection_type() const Segment_2_Line_2_pair<K>::intersection_type() const
@ -166,27 +136,23 @@ Segment_2_Line_2_pair<K>::intersection_type() const
} }
template <class K> template <class K>
bool typename K::Point_2
Segment_2_Line_2_pair<K>::intersection(typename K::Point_2 &result) const Segment_2_Line_2_pair<K>::intersection_point() const
{ {
if (!_known) if (!_known)
intersection_type(); intersection_type();
if (_result != POINT) CGAL_kernel_assertion(_result == POINT);
return false; return _intersection_point;
result = _intersection_point;
return true;
} }
template <class K> template <class K>
bool typename K::Segment_2
Segment_2_Line_2_pair<K>::intersection(typename K::Segment_2 &result) const Segment_2_Line_2_pair<K>::intersection_segment() const
{ {
if (!_known) if (!_known)
intersection_type(); intersection_type();
if (_result != SEGMENT) CGAL_kernel_assertion(_result == SEGMENT);
return false; return *_seg;
result = *_seg;
return true;
} }
} // namespace CGALi } // namespace CGALi