From fb3d75763ac3527fe6bdc33384321b4a164cd039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 5 Nov 2024 10:17:44 +0100 Subject: [PATCH] using functor to iterator over coordinates --- .../CGAL/Frechet_distance/internal/curve.h | 18 ++++++++++---- .../internal/high_level_predicates.h | 18 ++++++++------ .../Frechet_distance_minimal_traits_2.cpp | 24 +++++++++++++++---- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h b/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h index 88b89435ae9..1e1fa8a99f1 100644 --- a/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h +++ b/Frechet_distance/include/CGAL/Frechet_distance/internal/curve.h @@ -163,6 +163,7 @@ class Curve 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; using Points = std::vector; @@ -230,11 +231,16 @@ class Curve 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 ip = to_interval(p[d]); - std::pair iq = to_interval(q[d]); + std::pair ip = to_interval(*itp); + std::pair iq = to_interval(*itq); res+=square(IFT(ip)-IFT(iq)); + ++itp; ++itq; } return sqrt(res); } @@ -258,10 +264,12 @@ class Curve std::array 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 lambda^2 + (2 b / a) * lambda + (c / a) = 0 // <=> lambda1/2 = - (b / a) +/- sqrt((b / a)^2 - c / a) //TODO: use optional! -template +template bool fill_lambda(const Point& circle_center, const Point& line_start, @@ -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); } @@ -95,7 +99,7 @@ intersection_interval(Curve const& curve1, try { std::pair, Lambda> II; // if not empty - if (fill_lambda( + if (fill_lambda( curve1[center_id], curve2[seg_start_id], curve2[seg_start_id + 1], radius.inf(), II, curve1, center_id, curve2, seg_start_id)) { @@ -105,7 +109,7 @@ intersection_interval(Curve const& curve1, CGAL_assertion(radius.is_point()); std::pair, Lambda> II; // if not empty - if (fill_lambda::Rational>( + if (fill_lambda( 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)) { @@ -131,7 +135,7 @@ intersection_interval(Curve const& curve1, std::pair, Lambda> II; // if not empty - if (fill_lambda( + if (fill_lambda( curve1[center_id], curve2[seg_start_id], curve2[seg_start_id + 1], radius.inf(), II, curve1, center_id, curve2, seg_start_id)) { diff --git a/Frechet_distance/test/Frechet_distance/Frechet_distance_minimal_traits_2.cpp b/Frechet_distance/test/Frechet_distance/Frechet_distance_minimal_traits_2.cpp index a9c9d44769c..a170f0252a3 100644 --- a/Frechet_distance/test/Frechet_distance/Frechet_distance_minimal_traits_2.cpp +++ b/Frechet_distance/test/Frechet_distance/Frechet_distance_minimal_traits_2.cpp @@ -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 @@ -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(); } + }; + };