Get back on CSQ Point-Segment, new was slower

This commit is contained in:
Léo Valque 2025-02-27 10:58:53 +01:00
parent bf4e61e4e5
commit fbf588e936
1 changed files with 1 additions and 32 deletions

View File

@ -116,38 +116,7 @@ compare_squared_distance(const typename K::Point_3& pt,
const K& k, const K& k,
const typename K::FT& d2) const typename K::FT& d2)
{ {
typedef typename K::RT RT; return compare(squared_distance(pt, seg, k), d2);
typedef typename K::FT FT;
typedef typename K::Vector_3 Vector_3;
typename K::Construct_vector_3 vector = k.construct_vector_3_object();
typename K::Compare_squared_distance_3 csq_dist = k.compare_squared_distance_3_object();
// assert that the segment is valid (non zero length).
const Vector_3 diff = vector(seg.source(), pt);
const Vector_3 segvec = vector(seg.source(), seg.target());
// If the segment is degen
if(seg.source()==seg.target())
return csq_dist(pt, seg.source(), d2);
// Compare first the distance to the line, if larger we can exit early
const typename K::Comparison_result res_pl= compare_squared_distance_to_line(segvec, diff, k, d2);
if(res_pl==LARGER)
return LARGER;
//If the distance is realized by the source
const RT d = wdot(diff, segvec, k);
if(d <= RT(0))
return compare(FT(diff*diff), d2);
//If the distance is realized by the target
const RT e = wdot(segvec, segvec, k);
if(wmult((K*)0, d, segvec.hw()) > wmult((K*)0, e, diff.hw()))
return csq_dist(pt, seg.target(), d2);
//If the distance is realized by the interior
return res_pl;
} }
template <class K> template <class K>