Skip to content

Commit

Permalink
using functor to iterator over coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
sloriot committed Nov 6, 2024
1 parent 7ef4400 commit fb3d757
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
18 changes: 13 additions & 5 deletions Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Curve<T, false>

using Squared_distance = typename Traits::Compute_squared_distance_d;
using Construct_bbox = typename Traits::Construct_bbox_d;
using Construct_cartesian_const_iterator_d = typename Traits::Construct_cartesian_const_iterator_d;

using PointID = ID<Point>;
using Points = std::vector<Point>;
Expand Down Expand Up @@ -230,11 +231,16 @@ class Curve<T, false>
static IFT distance(Point const& p, Point const& q)
{
IFT res(0);
Construct_cartesian_const_iterator_d ccci;

auto itp = ccci(p), itq = ccci(q);

for (int d=0;d<Traits::Dimension::value; ++d)
{
std::pair<double,double> ip = to_interval(p[d]);
std::pair<double,double> iq = to_interval(q[d]);
std::pair<double,double> ip = to_interval(*itp);
std::pair<double,double> iq = to_interval(*itq);
res+=square(IFT(ip)-IFT(iq));
++itp; ++itq;
}
return sqrt(res);
}
Expand All @@ -258,10 +264,12 @@ class Curve<T, false>
std::array<distance_t, dimension> b_coords;
auto fraction = pt.getFraction().approx;
distance_t one_m_f = distance_t(1) - fraction;
Construct_cartesian_const_iterator_d ccci;
auto itp = ccci(point(pt.getPoint()));
auto itq = ccci(point(pt.getPoint()+1));

for (int d=0; d<dimension; ++d)
//TODO: use Construct_cartesian_const_iterator_d
//TODO: use contruct point and add it in the traits concept
b_coords[d] = one_m_f * point(pt.getPoint())[d] + point(pt.getPoint() + 1)[d] * fraction;
b_coords[d] = one_m_f * (*itp++) + (*itq++) * fraction;

if constexpr (dimension==2)
return Point(b_coords[0], b_coords[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace internal {
// <=> lambda^2 + (2 b / a) * lambda + (c / a) = 0
// <=> lambda1/2 = - (b / a) +/- sqrt((b / a)^2 - c / a)
//TODO: use optional!
template <class FT, class C, class Point, class AFT>
template <class Traits, class C, class Point, class AFT>
bool
fill_lambda(const Point& circle_center,
const Point& line_start,
Expand All @@ -42,12 +42,16 @@ fill_lambda(const Point& circle_center,
C const& curve2,
typename C::PointID const& seg_start_id)
{
using FT = typename Traits::FT;
FT a(0), b(0), c(0);
for (auto i = 0; i < C::dimension; ++i)
auto ccci = typename Traits::Construct_cartesian_const_iterator_d();
auto it_cc = ccci(circle_center), it_s = ccci(line_start), it_e = ccci(line_end);

for (auto i = 0; i < C::dimension; ++i, ++it_cc, ++it_s, ++it_e)
{
FT start_end_diff = line_end[i] - line_start[i];
FT start_end_diff = *it_e - *it_s;
a += CGAL::square(start_end_diff);
FT start_center_diff = line_start[i] - circle_center[i];
FT start_center_diff = *it_s - *it_cc;
b -= start_center_diff * start_end_diff;
c += square(start_center_diff);
}
Expand Down Expand Up @@ -95,7 +99,7 @@ intersection_interval(Curve<T, true> const& curve1,
try {
std::pair<Lambda<C>, Lambda<C>> II;
// if not empty
if (fill_lambda<typename C::distance_t>(
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))
{
Expand All @@ -105,7 +109,7 @@ intersection_interval(Curve<T, true> const& curve1,
CGAL_assertion(radius.is_point());
std::pair<Lambda<C>, Lambda<C>> II;
// if not empty
if (fill_lambda<typename Lambda<C>::Rational>(
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))
{
Expand All @@ -131,7 +135,7 @@ intersection_interval(Curve<T, false> const& curve1,

std::pair<Lambda<C>, Lambda<C>> II;
// if not empty
if (fill_lambda<typename C::distance_t>(
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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ struct MinimalFrechetTraits {
using Dimension = CGAL::Dimension_tag<2>;
using FT = double;

struct Point_d {
struct Point_d
{
Point_d(double, double) {}

double operator[](int) const
{
return 0;
}
//~ double operator[](int) const
//~ {
//~ return 0;
//~ }
};

struct Compute_squared_distance_d
Expand All @@ -31,6 +32,19 @@ struct MinimalFrechetTraits {
}
};

struct Cartesian_const_iterator_d
{
FT operator*() { return 0; }
Cartesian_const_iterator_d& operator++() { return *this;}
Cartesian_const_iterator_d operator++(int) { return Cartesian_const_iterator_d(); }
};

struct Construct_cartesian_const_iterator_d
{
Cartesian_const_iterator_d operator()(Point_d){ return Cartesian_const_iterator_d(); }
Cartesian_const_iterator_d operator()(Point_d, int){ return Cartesian_const_iterator_d(); }
};

};


Expand Down

0 comments on commit fb3d757

Please sign in to comment.