Replaced operator*(Vector,Vector), and operator*(Vector,NT) with functors

This commit is contained in:
Andreas Fabri 2004-03-09 21:40:44 +00:00
parent 44f6761237
commit 5cbc3e4f6a
6 changed files with 31 additions and 17 deletions

View File

@ -1,3 +1,6 @@
09 Mar 2004 Andreas Fabri
- Replaced operator*(Vector,Vector), and operator*(Vector,NT) with functors
25 Feb 2004 Sylvain Pion
- parallel(x,x,k) is now in CGALi::.

View File

@ -50,7 +50,7 @@ namespace CGALi {
const K& k)
{
typename K::Vector_2 vec = k.construct_vector_2_object()(pt2, pt1);
return (typename K::FT)(vec*vec);
return (typename K::FT)k.compute_squared_length_2_object()(vec);
}
template <class K>
@ -116,7 +116,7 @@ namespace CGALi {
Vector_2 diff = construct_vector(ray.source(), pt);
const Vector_2 &dir = ray.direction().vector();
if (!is_acute_angle(dir,diff, k) )
return (typename K::FT)(diff*diff);
return (typename K::FT)k.compute_squared_length_2_object()(diff);
return CGALi::squared_distance(pt, ray.supporting_line(), k);
}
@ -143,7 +143,7 @@ namespace CGALi {
Vector_2 segvec = construct_vector(seg.source(), seg.target());
RT d = wdot(diff,segvec, k);
if (d <= (RT)0)
return (typename K::FT)(diff*diff);
return (typename K::FT)k.compute_squared_length_2_object()(diff);
RT e = wdot(segvec,segvec, k);
if (wmult((K*)0 ,d, segvec.hw()) > wmult((K*)0, e, diff.hw()))
return CGALi::squared_distance(pt, seg.target(), k);
@ -487,7 +487,7 @@ namespace CGALi {
typedef typename K::FT FT;
if (!is_acute_angle(ray1dir, from1to2, k)) {
if (!same_direction(ray1dir, ray2dir, k))
return (typename K::FT)(from1to2*from1to2);
return (typename K::FT)k.compute_squared_length_2_object()(from1to2);
}
RT wcr, w;
wcr = wcross(ray1dir, from1to2, k);
@ -553,7 +553,7 @@ namespace CGALi {
typedef typename K::Vector_2 Vector_2;
Vector_2 normalvec(line.a(), line.b());
Vector_2 diff = construct_vector(line.point(), ray.source());
FT sign_dist = diff*normalvec;
FT sign_dist = k.compute_scalar_product_2_object()(diff,normalvec);
if (sign_dist < FT(0)) {
if (is_acute_angle(normalvec, ray.direction().vector(), k) )
return (FT)0;
@ -561,7 +561,7 @@ namespace CGALi {
if (is_obtuse_angle(normalvec, ray.direction().vector(), k) )
return (FT)0;
}
return (typename K::FT)((sign_dist*sign_dist)/(normalvec*normalvec));
return (typename K::FT)((sign_dist*sign_dist)/k.compute_squared_length_2_object()(normalvec));
}
template <class K>
@ -719,9 +719,10 @@ class Squared_distance_to_ray {
typename K::FT operator()(typename K::Point_2 const &pt) const
{
typename K::Construct_vector_2 construct_vector;
typename K::Compute_squared_length_2 compute_squared_length;
typename K::Vector_2 diff = construct_vector(ray_source, pt);
if (! CGALi::is_acute_angle(ray_dir,diff, K()) )
return (typename K::FT)(diff*diff);
return (typename K::FT)compute_squared_length(diff);
return supline_dist(pt);
}
};
@ -763,12 +764,13 @@ class Squared_distance_to_segment {
typename K::FT operator()(typename K::Point_2 const &pt) const
{
typename K::Construct_vector_2 construct_vector;
typename K::Compute_squared_length_2 compute_squared_length;
typedef typename K::RT RT;
// assert that the segment is valid (non zero length).
typename K::Vector_2 diff = construct_vector(seg_source, pt);
RT d = CGALi::wdot(diff,segvec, K());
if (d <= (RT)0)
return (typename K::FT)(diff*diff);
return (typename K::FT)compute_squared_length(diff);
if (wmult((K*)0 ,d, segvec.hw()) > wmult((K*)0, e, diff.hw()))
return CGALi::squared_distance(pt, seg_target, K());
return supline_dist(pt);

View File

@ -1,3 +1,6 @@
09 Mar 2004 Andreas Fabri
Replaced operator*(Vector,Vector), and operator*(Vector,NT) with functors
2.33 (02 Jan 2004) [rursu]
- fixed Ray_2_Triangle_2_intersection.h for gcc 3.4

View File

@ -173,12 +173,13 @@ Line_2_Iso_rectangle_2_pair<K>::
intersection(typename K::Point_2 &result) const
{
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;
result = translated_point(_ref_point,_dir * _min);
result = translated_point(_ref_point, construct_scaled_vector(_dir, _min));
return true;
}
@ -189,12 +190,13 @@ intersection(typename K::Segment_2 &result) const
{
typename K::Construct_segment_2 construct_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;
result = construct_segment_2(translated_point(_ref_point, _dir*_min),
translated_point(_ref_point, _dir*_max));
result = construct_segment_2(translated_point(_ref_point, construct_scaled_vector(_dir,_min)),
translated_point(_ref_point, construct_scaled_vector(_dir,_max)));
return true;
}

View File

@ -206,12 +206,13 @@ intersection(typename K::Segment_2 &seg) 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;
typename K::Point_2 p1(translated_point(_ref_point, _dir*_min));
typename K::Point_2 p2(translated_point(_ref_point, _dir*_max));
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;
}
@ -221,11 +222,12 @@ 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, _dir*_min));
pt = Point_2(translated_point(_ref_point, construct_scaled_vector(_dir, _min)));
return true;
}

View File

@ -202,13 +202,14 @@ intersection(typename K::Segment_2 &seg) 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;
typename K::Point_2 p1(translated_point(_ref_point, _dir*_min));
typename K::Point_2 p2(translated_point(_ref_point, _dir*_max));
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;
}
@ -218,11 +219,12 @@ 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, _dir*_min));
pt = Point_2(translated_point(_ref_point, construct_scaled_vector(_dir,_min)));
return true;
}