Frechet Distance: Fix bugs in Lambda (#9103)

## Summary of Changes

_Describe what your pull request changes to CGAL (this can be skipped if
it solves an issue already in the tracker or if it is a Feature or Small
Feature submitted to the CGAL Wiki)._

## Release Management

* Affected package(s): Frechet Distance
* License and copyright ownership:  unchanged
This commit is contained in:
Sebastien Loriot 2025-10-30 20:16:29 +01:00 committed by GitHub
commit 80b4d1a1be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 863 additions and 3 deletions

View File

@ -514,6 +514,7 @@ inline void FrechetLight<C>::continueQSimpleSearch(QSimpleInterval& qsimple,
// TODO: uncritical for correctness or speed but unelegant coding style: stripping down information added by getInterval
CInterval temp_interval = FrechetLight::getInterval<IndexType>(
fixed_curve, fixed, curve, cur);
Interval interval = Interval(temp_interval.begin.getPoint() == cur
? temp_interval.begin.getFraction()
: 1,

View File

@ -113,7 +113,10 @@ struct Lambda<Curve<FilteredTraits,true>>
// fill_lambda returns a pair and we are only interested in a bound
bool update_exact() const
{
if (is_exact) {
if (is_exact){
if (!exact.has_value()){
exact = (is_one) ? std::make_optional(Exact(1)) : std::make_optional(Exact(0));
}
return true;
}
@ -198,7 +201,9 @@ struct Lambda<Curve<FilteredTraits,true>>
{
if ((is_zero && other.is_zero) || (is_one && other.is_one))
return false;
if ((is_zero && (!other.is_zero)) || (!is_one && other.is_one))
// AF this may be wrong if approx is [0.9,1.1] and other.is_one:
// if ((is_zero && (!other.is_zero)) || (!is_one && other.is_one))
if(is_zero && other.is_one)
return true;
CGAL::Uncertain<bool> res = approx < other.approx;
if (CGAL::is_certain(res)) {
@ -206,7 +211,8 @@ struct Lambda<Curve<FilteredTraits,true>>
}
update_exact();
other.update_exact();
return exact < other.exact;
bool eres = exact.value() < other.exact.value();
return eres;
}
};

View File

@ -6,6 +6,9 @@ project( Frechet_distance_Tests )
find_package(CGAL REQUIRED)
create_single_source_cgal_program( "Frechet-IssueOct25.cpp" )
find_package(Eigen3 3.1.0 QUIET) #(3.1.0 or greater)
include(CGAL_Eigen3_support)
if(TARGET CGAL::Eigen3_support)

View File

@ -0,0 +1,40 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Frechet_distance.h>
#include <fstream>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point = Kernel::Point_2;
using Segment = Kernel::Segment_2;
bool load_polyline(const std::string &filename, std::vector<Point> &polyline) {
polyline.clear();
std::ifstream ifs(filename);
if (!ifs)
return false;
while (ifs.good()) {
Point p;
ifs >> p;
if (ifs.good())
polyline.push_back(p);
}
return true;
}
int main() {
std::vector<Point> poly1, poly2;
if (!load_polyline("poly1.txt", poly1) || !load_polyline("poly2.txt", poly2)) {
std::cout << "input files could not be loaded" << std::endl;
return -1;
}
std::pair<double, double> res = CGAL::bounded_error_Frechet_distance(poly1, poly2, 0.000001);
std::cout << "Frechet distance: [" << res.first << ", " << res.second << "]" << std::endl;
return 0;
}

View File

@ -0,0 +1,185 @@
-126 70
-138 58
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-39 -18
-42.6 -14
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70

View File

@ -0,0 +1,625 @@
-126 70
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
70 -138
61.4 -118.4
61.4 -118
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70
-126 70