diff --git a/Spatial_searching/include/CGAL/Fuzzy_sphere.h b/Spatial_searching/include/CGAL/Fuzzy_sphere.h index 2ff94063b49..5953ac767a6 100644 --- a/Spatial_searching/include/CGAL/Fuzzy_sphere.h +++ b/Spatial_searching/include/CGAL/Fuzzy_sphere.h @@ -146,13 +146,17 @@ class Fuzzy_sphere< Search_traits_adapter > public: // constructors Fuzzy_sphere(const SearchTraits& traits_=SearchTraits()):Base(traits_){} - Fuzzy_sphere(const typename Base_traits::Point_d& center, FT radius, FT epsilon=FT(0),const SearchTraits& traits_=SearchTraits()) : - Base(center,radius,epsilon,traits_) {} - Fuzzy_sphere(const typename SearchTraits::Point_d& center, FT radius, FT epsilon=FT(0), - const SearchTraits& traits_=SearchTraits(), + + // Constructor for any point type that is not `SearchTraits::Point_d` + template // boost::disable_if requires a template argument to work + Fuzzy_sphere(const Point& center, FT radius, FT epsilon=FT(0),const SearchTraits& traits_=SearchTraits(), typename boost::disable_if< - boost::is_same >::type* = 0) + boost::is_same >::type* = 0) + : Base(center,radius,epsilon,traits_) {} + + Fuzzy_sphere(const typename SearchTraits::Point_d& center, FT radius, FT epsilon=FT(0), + const SearchTraits& traits_=SearchTraits()) : Base(get(traits_.point_property_map(),center),radius,epsilon,traits_) {} }; diff --git a/Spatial_searching/include/CGAL/Search_traits_adapter.h b/Spatial_searching/include/CGAL/Search_traits_adapter.h index f6d4eae7c6d..1fc87b33290 100644 --- a/Spatial_searching/include/CGAL/Search_traits_adapter.h +++ b/Spatial_searching/include/CGAL/Search_traits_adapter.h @@ -33,6 +33,7 @@ #include #include +#include namespace CGAL{ @@ -111,11 +112,23 @@ public: // This is needed because of an undocumented requirement of // Orthogonal_k_neighbor_search and Orthogonal_incremental_neighbor_search: // Traits::Construct_cartesian_const_iterator should be callable - // on the query point type - typename Base_traits::Cartesian_const_iterator_d operator()(const typename Base_traits::Point_d& p) const + // on the query point type. If the query point type is the same as + // Point_with_info, we disable it. + + template // boost::disable_if requires a template argument to work + typename Base_traits::Cartesian_const_iterator_d operator()(const Point& p, + typename boost::disable_if< + boost::is_same >::type* = 0 + ) const { return Base::operator() (p); } - typename Base_traits::Cartesian_const_iterator_d operator()(const typename Base_traits::Point_d& p, int) const + template // boost::disable_if requires a template argument to work + typename Base_traits::Cartesian_const_iterator_d operator()(const Point& p, int, + typename boost::disable_if< + boost::is_same >::type* = 0 + ) const { return Base::operator() (p,0); } }; diff --git a/Spatial_searching/test/Spatial_searching/Search_traits_adapter_with_identity_map.cpp b/Spatial_searching/test/Spatial_searching/Search_traits_adapter_with_identity_map.cpp new file mode 100644 index 00000000000..00e66ca1d0f --- /dev/null +++ b/Spatial_searching/test/Spatial_searching/Search_traits_adapter_with_identity_map.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_2 Point_2; +typedef CGAL::Random_points_in_disc_2 Random_points; + +typedef CGAL::Identity_property_map Point_map; +typedef CGAL::Search_traits_2 Search_base; +typedef CGAL::Search_traits_adapter Search_traits; +typedef CGAL::Fuzzy_sphere Fuzzy_circle; +typedef CGAL::Kd_tree Tree; + +int main () +{ + Random_points rdpts; + std::vector pts; + for (std::size_t i = 0; i < 50; ++ i) + pts.push_back (*(rdpts ++)); + + Tree tree (pts.begin(), pts.end()); + + Point_2 center(0., 0.); + Fuzzy_circle circle (center, 0.5); + std::vector result; + tree.search(std::back_inserter(result), circle); + std::cout << "The points in the fuzzy circle centered at (0., 0.) "; + std::cout << "with fuzzy radius (0.5) are: " << std::endl; + for (std::size_t i = 0; i < result.size(); ++ i) + std::cout << " * " << result[i] << std::endl; + + return 0; +}