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 {
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;
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 <class K>
@ -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 <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>
typename Ray_2_Iso_rectangle_2_pair<K>::Intersection_results
Ray_2_Iso_rectangle_2_pair<K>::intersection_type() const
@ -200,48 +173,33 @@ Ray_2_Iso_rectangle_2_pair<K>::intersection_type() const
template <class K>
bool Ray_2_Iso_rectangle_2_pair<K>::
intersection(typename K::Segment_2 &seg) const
typename K::Segment_2
Ray_2_Iso_rectangle_2_pair<K>::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 <class K> bool Ray_2_Iso_rectangle_2_pair<K>::
intersection(typename K::Point_2 &pt) const
template <class K>
typename K::Point_2
Ray_2_Iso_rectangle_2_pair<K>::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 Point_2(translated_point(_ref_point, construct_scaled_vector(_dir, _min)));
}
template <class K>
class Iso_rectangle_2_Ray_2_pair:
public Ray_2_Iso_rectangle_2_pair<K> {
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<K> (ray, rect){}
};
} // namespace CGALi

View File

@ -41,14 +41,14 @@ template <class K>
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 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>
inline bool do_intersect(
const typename K::Line_2 &p1,
const typename K::Segment_2 &p2,
const K&)
{
typedef Line_2_Segment_2_pair<K> pair_t;
pair_t pair(&p1, &p2);
typedef Segment_2_Line_2_pair<K> pair_t;
pair_t pair(&p2, &p1);
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>
typename Segment_2_Line_2_pair<K>::Intersection_results
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>
bool
Segment_2_Line_2_pair<K>::intersection(typename K::Point_2 &result) const
typename K::Point_2
Segment_2_Line_2_pair<K>::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 <class K>
bool
Segment_2_Line_2_pair<K>::intersection(typename K::Segment_2 &result) const
typename K::Segment_2
Segment_2_Line_2_pair<K>::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