// Copyright (c) 2024 Max-Planck-Institute Saarbruecken (Germany), GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : André Nusser // Marvin Künnemann // Karl Bringmann // Andreas Fabri // ============================================================================= #ifndef CGAL_FRECHET_DISTANCE_H #define CGAL_FRECHET_DISTANCE_H #include #include #include #include #include #include namespace CGAL { #ifdef CGAL_EIGEN3_ENABLED template struct Epick_d; template struct Epeck_d; #endif namespace internal { template ::value > struct Get_default_traits_base #ifdef CGAL_EIGEN3_ENABLED { using type = Frechet_distance_traits_d::Kernel>; }; #else ; #endif template struct Get_default_traits_base { using type = Frechet_distance_traits_2::Kernel>; }; template struct Get_default_traits_base { using type = Frechet_distance_traits_3::Kernel>; }; template ::Kernel> struct Get_default_traits { using type = typename Get_default_traits_base

::type; }; #ifdef CGAL_EIGEN3_ENABLED template struct Get_default_traits>> { using type = Frechet_distance_traits_d::Kernel>; }; template struct Get_default_traits>> { using type = Frechet_distance_traits_d::Kernel>; }; #endif template struct Get_default_traits> { using type = ::CGAL::internal_kernel_traits::Dummy_kernel

; }; } // end of internal namespace /** * \ingroup PkgFrechetDistanceFunctions * determines if the Frechet distance between two polylines is larger than a given distance bound. * * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is a `Point_d` * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param polyline1 the first polyline, defined by a sequence of consecutive points * \param polyline2 the second polyline, defined by a sequence of consecutive points * \param distance_bound the distance to compare against * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" containing the one listed below: * * \cgalNamedParamsBegin * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a model of `FrechetDistanceTraits`} * \cgalParamDefault{`Frechet_distance_traits_2`, `Frechet_distance_traits_3`, or `Frechet_distance_traits_d`, depending on the dimension of the point type * deduced from the point type, using `Kernel_traits`.} * \cgalParamExtra{The input point type (the range's value type) must be equal to the traits' `Point_d` type.} * \cgalParamNEnd * \cgalNamedParamsEnd * * \pre the polylines must not be empty */ template bool is_Frechet_distance_larger(const PointRange& polyline1, const PointRange& polyline2, const double distance_bound, const NamedParameters& np = parameters::default_values()) { constexpr bool force_filtering = internal_np::Lookup_named_param_def::type::value; using Point_d = std::remove_cv_t>; using Default_traits = typename internal::Get_default_traits::type; using Traits = typename internal_np::Lookup_named_param_def::type; Traits traits = parameters::choose_parameter( parameters::get_parameter(np, internal_np::geom_traits)); constexpr bool filtered = force_filtering || std::is_same_v(polyline1, traits))::IFT, Interval_nt>; Protect_FPU_rounding p; if(polyline1.empty() || polyline2.empty()){ return false; } auto icurve1 = Frechet_distance::internal::toCurve(polyline1, traits); auto icurve2 = Frechet_distance::internal::toCurve(polyline2, traits); using distance_t = const typename decltype(icurve1)::distance_t; return ! Frechet_distance::internal::lessThan(icurve1, icurve2, distance_t(distance_bound)); } /** * \ingroup PkgFrechetDistanceFunctions * returns an estimate of the Fréchet distance between the two polylines that is at most `error_bound` * away from the exact Fréchet distance between the two polylines, where `error_bound` must be a positive number. * * \tparam PointRange a model of the concept `RandomAccessContainer` whose value type is a `Point_d`. * \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" * * \param polyline1 the first polyline, defined by a sequence of consecutive points * \param polyline2 the second polyline, defined by a sequence of consecutive points * \param error_bound a maximum bound by which the Fréchet distance estimate is allowed to deviate from the exact Fréchet distance * \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" containing the one listed below: * * \cgalNamedParamsBegin * \cgalParamNBegin{geom_traits} * \cgalParamDescription{an instance of a geometric traits class} * \cgalParamType{a model of `FrechetDistanceTraits`} * \cgalParamDefault{`Frechet_distance_traits_2`, `Frechet_distance_traits_3`, or `Frechet_distance_traits_d`, depending on the dimension of the point type * deduced from the point type, using `Kernel_traits`.} * \cgalParamExtra{The input point type (the range's value type) must be equal to the traits' `Point_d` type.} * \cgalParamNEnd * \cgalNamedParamsEnd * * \pre the polylines must not be empty * * @return an interval enclosing the exact Fréchet distance, the difference between the upper and * the lower bound being smaller than `error_bound`. */ template std::pair bounded_error_Frechet_distance(const PointRange& polyline1, const PointRange& polyline2, const double error_bound, const NamedParameters& np = parameters::default_values()) { constexpr bool force_filtering = internal_np::Lookup_named_param_def::type::value; using Point_d = std::remove_cv_t>; using Default_traits = typename internal::Get_default_traits::type; using Traits = typename internal_np::Lookup_named_param_def::type; Traits traits = parameters::choose_parameter( parameters::get_parameter(np, internal_np::geom_traits)); constexpr bool filtered = force_filtering || std::is_same_v(polyline1, traits))::IFT, Interval_nt>; Protect_FPU_rounding p; if(polyline1.empty() || polyline2.empty()){ return std::make_pair(0,0); } auto icurve1 = Frechet_distance::internal::toCurve(polyline1, traits); auto icurve2 = Frechet_distance::internal::toCurve(polyline2, traits); return Frechet_distance::internal::calcDistance(icurve1, icurve2, error_bound); } } // end of namespace CGAL #endif // CGAL_FRECHET_DISTANCE_H