Skip to content

Commit

Permalink
do not use interval for SC<double>
Browse files Browse the repository at this point in the history
  • Loading branch information
sloriot committed Nov 7, 2024
1 parent 107ed0f commit aa009bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
30 changes: 26 additions & 4 deletions Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Curve<T, false>

//////
using FT = typename Traits::FT;
using IFT = CGAL::Interval_nt<false>; //TODO: if not filter + double --> should be double
using IFT = std::conditional_t<std::is_floating_point_v<FT>, FT, CGAL::Interval_nt<false>>;
using distance_t = FT;

using Point = typename Traits::Point_d;
Expand Down Expand Up @@ -237,9 +237,7 @@ class Curve<T, false>

for (int d=0;d<Traits::Dimension::value; ++d)
{
std::pair<double,double> ip = to_interval(*itp);
std::pair<double,double> iq = to_interval(*itq);
res+=square(IFT(ip)-IFT(iq));
res+=square(to_ift(*itp)-to_ift(*itq));
++itp; ++itq;
}
return res;
Expand All @@ -248,6 +246,30 @@ class Curve<T, false>
{
return sqrt(squared_distance(p,q));
}
static IFT to_ift(const FT& n)
{
if constexpr(std::is_floating_point_v<FT>)
{
return n;
}
else
{
return IFT(to_interval(n));
}
}
static FT inf(const IFT& n)
{
if constexpr(std::is_floating_point_v<FT>)
{
return n;
}
else
{
return n.inf();
}
}


template <class P>
Point interpolate_at(P const& pt) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ bool FrechetLight<C>::lessThan(distance_t const& d, Curve const& curve1,
{
this->curve_pair[0] = &curve1;
this->curve_pair[1] = &curve2;
this->distance = to_interval(d);
this->distance = C::to_ift(d);

// curves empty or start or end are already far
if (curve1.empty() || curve2.empty()) {
Expand Down Expand Up @@ -1181,7 +1181,7 @@ bool FrechetLight<C>::lessThanWithFilters(distance_t const& d, Curve const& curv
{
this->curve_pair[0] = &curve1;
this->curve_pair[1] = &curve2;
this->distance = typename Curve::IFT(to_interval(d));
this->distance = Curve::to_ift(d);

assert(curve1.size());
assert(curve2.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ struct Lambda<Curve<T,false>>
{
if constexpr (!std::is_same_v<RO2, FT>)
{
approx = v.a0()+v.a1()*approximate_sqrt(v.root());
std::pair<double, double> iv = to_interval(v);
approx = FT((iv.first+iv.second)/2.);
}
else
approx=v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ intersection_interval(Curve<T, true> const& curve1,
// if not empty
if (fill_lambda<typename T::first_type>(
curve1[center_id], curve2[seg_start_id], curve2[seg_start_id + 1],
radius.inf(), II, curve1, center_id, curve2, seg_start_id))
C::inf(radius), II, curve1, center_id, curve2, seg_start_id))
{
I = Interval<C>(II.first, II.second);
}
Expand All @@ -111,7 +111,7 @@ intersection_interval(Curve<T, true> const& curve1,
// if not empty
if (fill_lambda<typename T::second_type>(
curve1.rpoint(center_id), curve2.rpoint(seg_start_id), curve2.rpoint(seg_start_id + 1),
radius.inf(), II, curve1, center_id, curve2, seg_start_id))
C::inf(radius), II, curve1, center_id, curve2, seg_start_id))
{
I = Interval<C>(II.first, II.second);
}
Expand All @@ -137,7 +137,7 @@ intersection_interval(Curve<T, false> const& curve1,
// if not empty
if (fill_lambda<T>(
curve1[center_id], curve2[seg_start_id], curve2[seg_start_id + 1],
radius.inf(), II, curve1, center_id, curve2, seg_start_id))
C::inf(radius), II, curve1, center_id, curve2, seg_start_id))
{
I = Interval<C>(II.first, II.second);
}
Expand Down

0 comments on commit aa009bc

Please sign in to comment.