diff --git a/Spatial_sorting/doc/Spatial_sorting/CGAL/spatial_sort.h b/Spatial_sorting/doc/Spatial_sorting/CGAL/spatial_sort.h index 4beac521426..a2d7aabe8bf 100644 --- a/Spatial_sorting/doc/Spatial_sorting/CGAL/spatial_sort.h +++ b/Spatial_sorting/doc/Spatial_sorting/CGAL/spatial_sort.h @@ -45,7 +45,7 @@ times the original size of the set, Hilbert sort is applied on the second subset. */ - template +template void spatial_sort( RandomAccessIterator begin, RandomAccessIterator end, diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_2.h b/Spatial_sorting/include/CGAL/Hilbert_sort_2.h index b784365a176..1a4b7b249cd 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_2.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_2.h @@ -19,26 +19,26 @@ namespace CGAL { template - class Hilbert_sort_2; +class Hilbert_sort_2; -template - class Hilbert_sort_2 +template +class Hilbert_sort_2 : public Hilbert_sort_median_2 { - public: - Hilbert_sort_2 (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_median_2 (k,limit) - {} +public: + Hilbert_sort_2 (const K &k=K(), std::ptrdiff_t limit=1 ) + : Hilbert_sort_median_2 (k,limit) + {} }; template - class Hilbert_sort_2 +class Hilbert_sort_2 : public Hilbert_sort_middle_2 { - public: - Hilbert_sort_2 (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_middle_2 (k,limit) - {} +public: + Hilbert_sort_2 (const K &k=K(), std::ptrdiff_t limit=1 ) + : Hilbert_sort_middle_2 (k,limit) + {} }; } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_3.h b/Spatial_sorting/include/CGAL/Hilbert_sort_3.h index 486eec6c401..df51c0c973c 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_3.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_3.h @@ -18,27 +18,27 @@ namespace CGAL { - template - class Hilbert_sort_3; +template +class Hilbert_sort_3; - template +template class Hilbert_sort_3 - : public Hilbert_sort_median_3 + : public Hilbert_sort_median_3 { - public: - Hilbert_sort_3 (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_median_3 (k,limit) - {} +public: + Hilbert_sort_3 (const K &k=K(), std::ptrdiff_t limit=1 ) + : Hilbert_sort_median_3 (k,limit) + {} }; - template - class Hilbert_sort_3 +template +class Hilbert_sort_3 : public Hilbert_sort_middle_3 { - public: - Hilbert_sort_3 (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_middle_3 (k,limit) - {} +public: + Hilbert_sort_3 (const K &k=K(), std::ptrdiff_t limit=1 ) + : Hilbert_sort_middle_3 (k,limit) + {} }; } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_base.h b/Spatial_sorting/include/CGAL/Hilbert_sort_base.h index f5a0b3a9efe..d4d62d0b49a 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_base.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_base.h @@ -21,25 +21,27 @@ namespace CGAL { namespace internal { - template - RandomAccessIterator - hilbert_split (RandomAccessIterator begin, RandomAccessIterator end, - Cmp cmp = Cmp ()) - { - if (begin >= end) return begin; - #if defined(CGAL_HILBERT_SORT_WITH_MEDIAN_POLICY_CROSS_PLATFORM_BEHAVIOR) - RandomAccessIterator middle = begin + (end - begin) / 2; - CGAL::nth_element (begin, middle, end, cmp); - return middle; - #else - RandomAccessIterator middle = begin + (end - begin) / 2; - std::nth_element (begin, middle, end, cmp); - return middle; - #endif - - } +template +RandomAccessIterator +hilbert_split (RandomAccessIterator begin, RandomAccessIterator end, + Cmp cmp = Cmp ()) +{ + if (begin >= end) + return begin; + +#if defined(CGAL_HILBERT_SORT_WITH_MEDIAN_POLICY_CROSS_PLATFORM_BEHAVIOR) + RandomAccessIterator middle = begin + (end - begin) / 2; + CGAL::nth_element (begin, middle, end, cmp); + return middle; +#else + RandomAccessIterator middle = begin + (end - begin) / 2; + std::nth_element (begin, middle, end, cmp); + return middle; +#endif } +} // namespace internal + } // namespace CGAL #endif//CGAL_HILBERT_SORT_BASE_H diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_d.h b/Spatial_sorting/include/CGAL/Hilbert_sort_d.h index 0574b330262..b213c26f73d 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_d.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_d.h @@ -19,26 +19,26 @@ namespace CGAL { template - class Hilbert_sort_d; +class Hilbert_sort_d; template - class Hilbert_sort_d - : public Hilbert_sort_median_d +class Hilbert_sort_d + : public Hilbert_sort_median_d { - public: - Hilbert_sort_d (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_median_d (k,limit) - {} +public: + Hilbert_sort_d (const K &k=K() , std::ptrdiff_t limit=1 ) + : Hilbert_sort_median_d (k,limit) + {} }; template - class Hilbert_sort_d - : public Hilbert_sort_middle_d +class Hilbert_sort_d + : public Hilbert_sort_middle_d { - public: - Hilbert_sort_d (const K &k=K() , std::ptrdiff_t limit=1 ) - : Hilbert_sort_middle_d (k,limit) - {} +public: + Hilbert_sort_d (const K &k=K() , std::ptrdiff_t limit=1 ) + : Hilbert_sort_middle_d (k,limit) + {} }; } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_median_2.h b/Spatial_sorting/include/CGAL/Hilbert_sort_median_2.h index d66144c8158..330bea5e374 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_median_2.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_median_2.h @@ -14,8 +14,6 @@ #include #include -#include -#include #include #include @@ -24,124 +22,132 @@ #include #endif +#include +#include + namespace CGAL { namespace internal { - template struct Hilbert_cmp_2; - template - struct Hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return Hilbert_cmp_2 (k) (q, p); - } - }; - - template - struct Hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return k.less_x_2_object() (p, q); - } - }; - - template - struct Hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return k.less_y_2_object() (p, q); - } - }; -} +template struct Hilbert_cmp_2; + +template +struct Hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return Hilbert_cmp_2 (k) (q, p); + } +}; + +template +struct Hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return k.less_x_2_object() (p, q); + } +}; + +template +struct Hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + Hilbert_cmp_2 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return k.less_y_2_object() (p, q); + } +}; + +} // namespace internal template class Hilbert_sort_median_2 { public: typedef Hilbert_sort_median_2 Self; - typedef K Kernel; - typedef typename Kernel::Point_2 Point; - -private: - Kernel _k; - std::ptrdiff_t _limit; + typedef K Kernel; + typedef typename Kernel::Point_2 Point; - template struct Cmp : public internal::Hilbert_cmp_2 - { Cmp (const Kernel &k) : internal::Hilbert_cmp_2 (k) {} }; +private: + Kernel _k; + std::ptrdiff_t _limit; + + template + struct Cmp + : public internal::Hilbert_cmp_2 + { + Cmp (const Kernel &k) : internal::Hilbert_cmp_2 (k) {} + }; public: - Hilbert_sort_median_2 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) - : _k(k), _limit (limit) - {} - - template - void recursive_sort (RandomAccessIterator begin, RandomAccessIterator end) const - { - const int y = (x + 1) % 2; - if (end - begin <= _limit) return; - - RandomAccessIterator m0 = begin, m4 = end; - - RandomAccessIterator m2 = internal::hilbert_split (m0, m4, Cmp< x, upx> (_k)); - RandomAccessIterator m1 = internal::hilbert_split (m0, m2, Cmp< y, upy> (_k)); - RandomAccessIterator m3 = internal::hilbert_split (m2, m4, Cmp< y, !upy> (_k)); - - recursive_sort (m0, m1); - recursive_sort (m1, m2); - recursive_sort (m2, m3); - recursive_sort (m3, m4); - } + Hilbert_sort_median_2 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) + : _k(k), _limit (limit) + {} template - struct Recursive_sort { + void recursive_sort (RandomAccessIterator begin, RandomAccessIterator end) const + { + const int y = (x + 1) % 2; + if (end - begin <= _limit) + return; + + RandomAccessIterator m0 = begin, m4 = end; + + RandomAccessIterator m2 = internal::hilbert_split (m0, m4, Cmp< x, upx> (_k)); + RandomAccessIterator m1 = internal::hilbert_split (m0, m2, Cmp< y, upy> (_k)); + RandomAccessIterator m3 = internal::hilbert_split (m2, m4, Cmp< y, !upy> (_k)); + + recursive_sort (m0, m1); + recursive_sort (m1, m2); + recursive_sort (m2, m3); + recursive_sort (m3, m4); + } + + template + struct Recursive_sort + { const Self& hs; RandomAccessIterator begin,end; - + Recursive_sort(const Self& hs, RandomAccessIterator begin, RandomAccessIterator end) : hs(hs), begin(begin), end(end) {} - + void operator()() const { hs.recursive_sort(begin,end); } }; - + template struct Hilbert_split { RandomAccessIterator& res; RandomAccessIterator begin, end; const Comp& comp; - + Hilbert_split(RandomAccessIterator& res, RandomAccessIterator begin, RandomAccessIterator end, const Comp comp) : res(res), begin(begin), end(end), comp(comp) {} - + void operator()() const { res = internal::hilbert_split(begin, end, comp); } }; - + template void sort (RandomAccessIterator begin, RandomAccessIterator end, Parallel_tag) const { @@ -150,19 +156,20 @@ public: CGAL_USE(end); CGAL_static_assertion_msg (!(boost::is_convertible::value), "Parallel_tag is enabled but TBB is unavailable."); -#else +#else const int y = (x + 1) % 2; - if (end - begin <= _limit) return; - + if (end - begin <= _limit) + return; + RandomAccessIterator m0 = begin, m4 = end; - + if((end - begin) > 1024){ RandomAccessIterator m1, m2, m3; m2 = internal::hilbert_split (m0, m4, Cmp< x, upx> (_k)); - + tbb::parallel_invoke(Hilbert_split > (m1, m0, m2, Cmp< y, upy> (_k)), Hilbert_split > (m3, m2, m4, Cmp< y, !upy> (_k))); - + tbb::parallel_invoke(Recursive_sort (*this, m0, m1), Recursive_sort (*this, m1, m2), Recursive_sort (*this, m2, m3), @@ -175,10 +182,10 @@ public: template void sort (RandomAccessIterator begin, RandomAccessIterator end, Sequential_tag) const - { + { recursive_sort<0, false, false>(begin, end); } - + template void operator() (RandomAccessIterator begin, RandomAccessIterator end) const { diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_median_3.h b/Spatial_sorting/include/CGAL/Hilbert_sort_median_3.h index 38d03ff6299..5e8525bb7c1 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_median_3.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_median_3.h @@ -27,156 +27,154 @@ namespace CGAL { namespace internal { - template struct Hilbert_cmp_3; +template struct Hilbert_cmp_3; - template - struct Hilbert_cmp_3 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_3 Point; - K k; - Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return Hilbert_cmp_3 (k) (q, p); - } - }; +template +struct Hilbert_cmp_3 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_3 Point; + K k; + Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return Hilbert_cmp_3 (k) (q, p); + } +}; - template - struct Hilbert_cmp_3 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_3 Point; - K k; - Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return k.less_x_3_object() (p, q); - } - }; +template +struct Hilbert_cmp_3 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_3 Point; + K k; + Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return k.less_x_3_object() (p, q); + } +}; - template - struct Hilbert_cmp_3 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_3 Point; - K k; - Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return k.less_y_3_object() (p, q); - } - }; +template +struct Hilbert_cmp_3 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_3 Point; + K k; + Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return k.less_y_3_object() (p, q); + } +}; - template - struct Hilbert_cmp_3 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_3 Point; - K k; - Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} - bool operator() (const Point &p, const Point &q) const - { - return k.less_z_3_object() (p, q); - } - }; -} +template +struct Hilbert_cmp_3 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_3 Point; + K k; + Hilbert_cmp_3 (const K &_k = K()) : k(_k) {} + bool operator() (const Point &p, const Point &q) const + { + return k.less_z_3_object() (p, q); + } +}; + +} // namespace internal template class Hilbert_sort_median_3 { public: - typedef Hilbert_sort_median_3 Self; - typedef K Kernel; - typedef typename Kernel::Point_3 Point; + typedef K Kernel; + typedef typename Kernel::Point_3 Point; private: - Kernel _k; - std::ptrdiff_t _limit; + Kernel _k; + std::ptrdiff_t _limit; - template struct Cmp : public internal::Hilbert_cmp_3 - { Cmp (const Kernel &k) : internal::Hilbert_cmp_3 (k) {} }; + template + struct Cmp + : public internal::Hilbert_cmp_3 + { + Cmp (const Kernel &k) : internal::Hilbert_cmp_3 (k) {} + }; public: - Hilbert_sort_median_3 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) - : _k(k), _limit (limit) - {} - - - template - void recursive_sort (RandomAccessIterator begin, RandomAccessIterator end) const - { - const int y = (x + 1) % 3, z = (x + 2) % 3; - if (end - begin <= _limit) return; - - RandomAccessIterator m0 = begin, m8 = end; - - RandomAccessIterator m4 = internal::hilbert_split (m0, m8, Cmp< x, upx> (_k)); - RandomAccessIterator m2 = internal::hilbert_split (m0, m4, Cmp< y, upy> (_k)); - RandomAccessIterator m1 = internal::hilbert_split (m0, m2, Cmp< z, upz> (_k)); - RandomAccessIterator m3 = internal::hilbert_split (m2, m4, Cmp< z, !upz> (_k)); - RandomAccessIterator m6 = internal::hilbert_split (m4, m8, Cmp< y, !upy> (_k)); - RandomAccessIterator m5 = internal::hilbert_split (m4, m6, Cmp< z, upz> (_k)); - RandomAccessIterator m7 = internal::hilbert_split (m6, m8, Cmp< z, !upz> (_k)); - - recursive_sort (m0, m1); - recursive_sort (m1, m2); - recursive_sort (m2, m3); - recursive_sort (m3, m4); - recursive_sort (m4, m5); - recursive_sort (m5, m6); - recursive_sort (m6, m7); - recursive_sort (m7, m8); - } + Hilbert_sort_median_3 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) + : _k(k), _limit (limit) + {} template - struct Recursive_sort { + void recursive_sort (RandomAccessIterator begin, RandomAccessIterator end) const + { + const int y = (x + 1) % 3, z = (x + 2) % 3; + if (end - begin <= _limit) return; + + RandomAccessIterator m0 = begin, m8 = end; + + RandomAccessIterator m4 = internal::hilbert_split (m0, m8, Cmp< x, upx> (_k)); + RandomAccessIterator m2 = internal::hilbert_split (m0, m4, Cmp< y, upy> (_k)); + RandomAccessIterator m1 = internal::hilbert_split (m0, m2, Cmp< z, upz> (_k)); + RandomAccessIterator m3 = internal::hilbert_split (m2, m4, Cmp< z, !upz> (_k)); + RandomAccessIterator m6 = internal::hilbert_split (m4, m8, Cmp< y, !upy> (_k)); + RandomAccessIterator m5 = internal::hilbert_split (m4, m6, Cmp< z, upz> (_k)); + RandomAccessIterator m7 = internal::hilbert_split (m6, m8, Cmp< z, !upz> (_k)); + + recursive_sort (m0, m1); + recursive_sort (m1, m2); + recursive_sort (m2, m3); + recursive_sort (m3, m4); + recursive_sort (m4, m5); + recursive_sort (m5, m6); + recursive_sort (m6, m7); + recursive_sort (m7, m8); + } + + template + struct Recursive_sort + { const Self& hs; RandomAccessIterator begin,end; - + Recursive_sort(const Self& hs, RandomAccessIterator begin, RandomAccessIterator end) : hs(hs), begin(begin), end(end) {} - + void operator()() const { hs.recursive_sort(begin,end); } }; - + template struct Hilbert_split { RandomAccessIterator& res; RandomAccessIterator begin, end; const Comp& comp; - + Hilbert_split(RandomAccessIterator& res, RandomAccessIterator begin, RandomAccessIterator end, const Comp comp) : res(res), begin(begin), end(end), comp(comp) {} - + void operator()() const { res = internal::hilbert_split(begin, end, comp); } }; - template void sort (RandomAccessIterator begin, RandomAccessIterator end, Parallel_tag) const { #ifndef CGAL_LINKED_WITH_TBB - CGAL_USE(begin); CGAL_USE(end); CGAL_static_assertion_msg (!(boost::is_convertible::value), "Parallel_tag is enabled but TBB is unavailable."); -#else +#else const int y = (x + 1) % 3, z = (x + 2) % 3; if ((end - begin) <= _limit) return; @@ -184,42 +182,41 @@ public: if((end - begin) > 1024){ RandomAccessIterator m1, m2, m3, m4, m5, m6, m7; m4 = internal::hilbert_split(m0, m8, Cmp(_k)); - - tbb::parallel_invoke(Hilbert_split >(m2,m0,m4,Cmp(_k)), - Hilbert_split >(m6,m4,m8,Cmp(_k))); - - tbb::parallel_invoke(Hilbert_split >(m1,m0,m2,Cmp(_k)), - Hilbert_split >(m3,m2,m4,Cmp(_k)), - Hilbert_split >(m5,m4,m6,Cmp(_k)), - Hilbert_split >(m7,m6,m8,Cmp(_k))); - - tbb::parallel_invoke(Recursive_sort(*this, m0, m1), - Recursive_sort(*this, m1, m2), - Recursive_sort(*this, m2, m3), - Recursive_sort(*this, m3, m4), - Recursive_sort(*this, m4, m5), - Recursive_sort(*this, m5, m6), - Recursive_sort(*this, m6, m7), - Recursive_sort(*this, m7, m8)); + tbb::parallel_invoke(Hilbert_split >(m2, m0, m4, Cmp(_k)), + Hilbert_split >(m6, m4, m8, Cmp(_k))); + + tbb::parallel_invoke(Hilbert_split >(m1, m0, m2, Cmp(_k)), + Hilbert_split >(m3, m2, m4, Cmp(_k)), + Hilbert_split >(m5, m4, m6, Cmp(_k)), + Hilbert_split >(m7, m6, m8, Cmp(_k))); + + tbb::parallel_invoke(Recursive_sort(*this, m0, m1), + Recursive_sort(*this, m1, m2), + Recursive_sort(*this, m2, m3), + Recursive_sort(*this, m3, m4), + Recursive_sort(*this, m4, m5), + Recursive_sort(*this, m5, m6), + Recursive_sort(*this, m6, m7), + Recursive_sort(*this, m7, m8)); } else { recursive_sort<0, false, false, false>(begin, end); } #endif } - + template void sort (RandomAccessIterator begin, RandomAccessIterator end, Sequential_tag) const { recursive_sort<0, false, false, false>(begin, end); } - - template - void operator() (RandomAccessIterator begin, RandomAccessIterator end) const - { - sort <0, false, false, false> (begin, end, ConcurrencyTag()); - } + + template + void operator() (RandomAccessIterator begin, RandomAccessIterator end) const + { + sort <0, false, false, false> (begin, end, ConcurrencyTag()); + } }; } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h b/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h index be6cf647254..df4c3858e5c 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_median_d.h @@ -23,138 +23,139 @@ namespace CGAL { namespace internal { - template - struct Hilbert_cmp_d - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_d Point; - K k; - int axe; - bool orient; - Hilbert_cmp_d (int a, bool o, const K &_k = K()) - : k(_k), axe(a), orient(o) {} - bool operator() (const Point &p, const Point &q) const - { - return (orient ? (k.less_coordinate_d_object() (q,p,axe) ) - : (k.less_coordinate_d_object() (p,q,axe) )); - } - }; +template +struct Hilbert_cmp_d + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_d Point; + K k; + int axe; + bool orient; + Hilbert_cmp_d (int a, bool o, const K &_k = K()) : k(_k), axe(a), orient(o) {} -} + bool operator() (const Point &p, const Point &q) const + { + return (orient ? (k.less_coordinate_d_object() (q,p,axe) ) + : (k.less_coordinate_d_object() (p,q,axe) )); + } +}; + +} // namespace internal template class Hilbert_sort_median_d { public: - typedef K Kernel; - typedef typename Kernel::Point_d Point; - typedef std::vector< bool > Starting_position; + typedef K Kernel; + typedef typename Kernel::Point_d Point; + typedef std::vector< bool > Starting_position; private: - Kernel _k; - std::ptrdiff_t _limit; - mutable int _dimension; - mutable int two_to_dim; + Kernel _k; + std::ptrdiff_t _limit; + mutable int _dimension; + mutable int two_to_dim; - struct Cmp : public internal::Hilbert_cmp_d - { Cmp (int a, bool dir, const Kernel &k) - : internal::Hilbert_cmp_d (a,dir,k) {} }; + struct Cmp + : public internal::Hilbert_cmp_d + { + Cmp (int a, bool dir, const Kernel &k) : internal::Hilbert_cmp_d (a,dir,k) {} + }; public: - Hilbert_sort_median_d(const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) - : _k(k), _limit (limit) - {} + Hilbert_sort_median_d(const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) + : _k(k), _limit (limit) + {} - template - void sort (RandomAccessIterator begin, RandomAccessIterator end, - Starting_position start, int direction) const - { - if (end - begin <= _limit) return; + template + void sort (RandomAccessIterator begin, RandomAccessIterator end, + Starting_position start, int direction) const + { + if (end - begin <= _limit) + return; - int nb_directions = _dimension; - int nb_splits = two_to_dim; + int nb_directions = _dimension; + int nb_splits = two_to_dim; - if ( (end-begin) < (two_to_dim/2) ) { // not many points - nb_splits = 1; - nb_directions = 0; - while ( (end-begin) > nb_splits) { - ++nb_directions; - nb_splits *= 2; // compute 2^nb_directions - } - } - - std::vector places(nb_splits +1); - std::vector dir (nb_splits +1); - places[0]=begin; - places[nb_splits]=end; - - int last_dir = (direction + nb_directions) % _dimension; - int current_dir = direction; - int current_level_step =nb_splits; - do{ - int half_step = current_level_step/2; - int left=0; - int middle = half_step; - int right=current_level_step; - bool orient = start[current_dir]; - do{ - dir[middle] = current_dir; - places[middle] = internal::hilbert_split - (places[left], places[right], Cmp (current_dir,orient,_k)); - left =right; - right+=current_level_step; - middle+=current_level_step; - orient = ! orient; - }while( left< nb_splits); - current_level_step = half_step; - current_dir = (current_dir +1) % _dimension; - }while (current_dir != last_dir); - - if ( end-begin < two_to_dim) return; // less than 2^dim points - - /////////////start recursive calls - last_dir = (direction + _dimension -1) % _dimension; - // first step is special - sort( places[0], places[1], start, last_dir); - - for(int i=1; i - void operator() (RandomAccessIterator begin, RandomAccessIterator end) const - { - _dimension = _k.point_dimension_d_object()(*begin); - two_to_dim = 1; - Starting_position start(_dimension); - - typename std::iterator_traits::difference_type N=end-begin; - N*=2; - for (int i=0; i<_dimension; ++i) start[i]=false; // we start below in all coordinates - for (int i=0; i<_dimension; ++i) { - two_to_dim *= 2; // compute 2^_dimension - N/=2; - if (N==0) break; // not many points, this number of dimension is enough + if ( (end-begin) < (two_to_dim/2) ) { // not many points + nb_splits = 1; + nb_directions = 0; + while ( (end-begin) > nb_splits) { + ++nb_directions; + nb_splits *= 2; // compute 2^nb_directions } - - - // we start with direction 0; - sort (begin, end, start, 0); } + + std::vector places(nb_splits +1); + std::vector dir (nb_splits +1); + places[0]=begin; + places[nb_splits]=end; + + int last_dir = (direction + nb_directions) % _dimension; + int current_dir = direction; + int current_level_step =nb_splits; + do{ + int half_step = current_level_step/2; + int left=0; + int middle = half_step; + int right=current_level_step; + bool orient = start[current_dir]; + do{ + dir[middle] = current_dir; + places[middle] = internal::hilbert_split + (places[left], places[right], Cmp (current_dir,orient,_k)); + left =right; + right+=current_level_step; + middle+=current_level_step; + orient = ! orient; + }while( left< nb_splits); + current_level_step = half_step; + current_dir = (current_dir +1) % _dimension; + }while (current_dir != last_dir); + + if ( end-begin < two_to_dim) return; // less than 2^dim points + + /////////////start recursive calls + last_dir = (direction + _dimension -1) % _dimension; + // first step is special + sort( places[0], places[1], start, last_dir); + + for(int i=1; i + void operator() (RandomAccessIterator begin, RandomAccessIterator end) const + { + _dimension = _k.point_dimension_d_object()(*begin); + two_to_dim = 1; + Starting_position start(_dimension); + + typename std::iterator_traits::difference_type N=end-begin; + N*=2; + for (int i=0; i<_dimension; ++i) + start[i]=false; // we start below in all coordinates + + for (int i=0; i<_dimension; ++i) { + two_to_dim *= 2; // compute 2^_dimension + N/=2; + if (N==0) + break; // not many points, this number of dimension is enough + } + + // we start with direction 0; + sort (begin, end, start, 0); + } }; - - - } // namespace CGAL #endif//CGAL_HILBERT_SORT_MEDIAN_d_H diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_middle_2.h b/Spatial_sorting/include/CGAL/Hilbert_sort_middle_2.h index f347ca1f978..766e4fac4c6 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_middle_2.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_middle_2.h @@ -16,135 +16,135 @@ #include #include #include -#include +#include namespace CGAL { namespace internal { - template struct Fixed_hilbert_cmp_2; +template struct Fixed_hilbert_cmp_2; - template - struct Fixed_hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - double value; - Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} - bool operator() (const Point &p) const - { - return ! Fixed_hilbert_cmp_2 (value, k) (p); - } - }; - - template - struct Fixed_hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - double value; - Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} - bool operator() (const Point &p) const - { - return to_double(k.compute_x_2_object()(p)) < value; - } - }; - - template - struct Fixed_hilbert_cmp_2 - : public CGAL::cpp98::binary_function - { - typedef typename K::Point_2 Point; - K k; - double value; - Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} - bool operator() (const Point &p) const - { - return to_double(k.compute_y_2_object()(p)) < value; - } - }; -} +template +struct Fixed_hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + double value; + Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} + bool operator() (const Point &p) const + { + return ! Fixed_hilbert_cmp_2 (value, k) (p); + } +}; +template +struct Fixed_hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + double value; + Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} + bool operator() (const Point &p) const + { + return to_double(k.compute_x_2_object()(p)) < value; + } +}; + +template +struct Fixed_hilbert_cmp_2 + : public CGAL::cpp98::binary_function +{ + typedef typename K::Point_2 Point; + K k; + double value; + Fixed_hilbert_cmp_2 (double v, const K &_k = K()) : k(_k),value(v) {} + bool operator() (const Point &p) const + { + return to_double(k.compute_y_2_object()(p)) < value; + } +}; + +} // namespace internal template class Hilbert_sort_middle_2 { public: - typedef K Kernel; - typedef typename Kernel::Point_2 Point; - -private: - Kernel _k; - std::ptrdiff_t _limit; + typedef K Kernel; + typedef typename Kernel::Point_2 Point; - template struct Cmp : public internal::Fixed_hilbert_cmp_2 - { Cmp (double v, const Kernel &k) : internal::Fixed_hilbert_cmp_2 (v, k) {} }; +private: + Kernel _k; + std::ptrdiff_t _limit; + + template + struct Cmp + : public internal::Fixed_hilbert_cmp_2 + { + Cmp (double v, const Kernel &k) : internal::Fixed_hilbert_cmp_2 (v, k) {} + }; public: - Hilbert_sort_middle_2 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) - : _k(k), _limit (limit) - {} + Hilbert_sort_middle_2 (const Kernel &k = Kernel(), std::ptrdiff_t limit = 1) + : _k(k), _limit (limit) + {} - template - void sort (RandomAccessIterator begin, RandomAccessIterator end, - double xmin, double ymin, double xmax, double ymax) const - { - const int y = (x + 1) % 2; - if (end - begin <= _limit) return; + template + void sort (RandomAccessIterator begin, RandomAccessIterator end, + double xmin, double ymin, double xmax, double ymax) const + { + const int y = (x + 1) % 2; + if (end - begin <= _limit) return; - double xmed= (xmin+xmax)/2; - double ymed= (ymin+ymax)/2; + double xmed= (xmin+xmax)/2; + double ymed= (ymin+ymax)/2; - RandomAccessIterator m0 = begin, m4 = end; + RandomAccessIterator m0 = begin, m4 = end; - RandomAccessIterator m2 = - internal::fixed_hilbert_split (m0, m4, Cmp< x, upx> (xmed,_k)); - RandomAccessIterator m1 = - internal::fixed_hilbert_split (m0, m2, Cmp< y, upy> (ymed,_k)); - RandomAccessIterator m3 = - internal::fixed_hilbert_split (m2, m4, Cmp< y, !upy> (ymed,_k)); + RandomAccessIterator m2 = internal::fixed_hilbert_split (m0, m4, Cmp< x, upx> (xmed,_k)); + RandomAccessIterator m1 = internal::fixed_hilbert_split (m0, m2, Cmp< y, upy> (ymed,_k)); + RandomAccessIterator m3 = internal::fixed_hilbert_split (m2, m4, Cmp< y, !upy> (ymed,_k)); - if (m1!=m4) - sort (m0, m1, ymin, xmin, ymed, xmed); - if (m1!=m0 || m2!=m4) - sort (m1, m2, xmin, ymed, xmed, ymax); - if (m2!=m0 || m3!=m4) - sort (m2, m3, xmed, ymed, xmax, ymax); - if (m3!=m0) - sort (m3, m4, ymed, xmax, ymin, xmed); + if (m1!=m4) + sort (m0, m1, ymin, xmin, ymed, xmed); + if (m1!=m0 || m2!=m4) + sort (m1, m2, xmin, ymed, xmed, ymax); + if (m2!=m0 || m3!=m4) + sort (m2, m3, xmed, ymed, xmax, ymax); + if (m3!=m0) + sort (m3, m4, ymed, xmax, ymin, xmed); + } + + template + void operator() (RandomAccessIterator begin, RandomAccessIterator end) const + { + //Bbox_2 box=bbox_2(begin, end); BUG: WE NEED TO FIX THIS + + K k; + double xmin=to_double(k.compute_x_2_object()(*begin)), + ymin=to_double(k.compute_y_2_object()(*begin)), + xmax=xmin, + ymax=ymin; + + for(RandomAccessIterator it=begin+1; it xmax) + xmax = to_double(k.compute_x_2_object()(*it)); + if ( to_double(k.compute_y_2_object()(*it)) > ymax) + ymax = to_double(k.compute_y_2_object()(*it)); } - template - void operator() (RandomAccessIterator begin, RandomAccessIterator end) const - { - //Bbox_2 box=bbox_2(begin, end); BUG: WE NEED TO FIX THIS - - K k; - double xmin=to_double(k.compute_x_2_object()(*begin)), - ymin=to_double(k.compute_y_2_object()(*begin)), - xmax=xmin, - ymax=ymin; - - for(RandomAccessIterator it=begin+1; it xmax) - xmax = to_double(k.compute_x_2_object()(*it)); - if ( to_double(k.compute_y_2_object()(*it)) > ymax) - ymax = to_double(k.compute_y_2_object()(*it)); - } - - sort <0, false, false> (begin, end, xmin, ymin, xmax, ymax); - } + sort <0, false, false> (begin, end, xmin, ymin, xmax, ymax); + } }; - } // namespace CGAL #endif//CGAL_HILBERT_SORT_MIDDLE_2_H diff --git a/Spatial_sorting/include/CGAL/Hilbert_sort_middle_base.h b/Spatial_sorting/include/CGAL/Hilbert_sort_middle_base.h index a331dac49e3..b8998a6f99b 100644 --- a/Spatial_sorting/include/CGAL/Hilbert_sort_middle_base.h +++ b/Spatial_sorting/include/CGAL/Hilbert_sort_middle_base.h @@ -19,17 +19,19 @@ namespace CGAL { namespace internal { - template - RandomAccessIterator - fixed_hilbert_split (RandomAccessIterator begin, RandomAccessIterator end, - Cmp cmp = Cmp ()) - { - if (begin >= end) return begin; +template +RandomAccessIterator +fixed_hilbert_split (RandomAccessIterator begin, RandomAccessIterator end, + Cmp cmp = Cmp ()) +{ + if (begin >= end) + return begin; - return std::partition (begin, end, cmp); - } + return std::partition (begin, end, cmp); } +} // namespace internal + } // namespace CGAL #endif//CGAL_HILBERT_SORT_MIDDLE_BASE_H diff --git a/Spatial_sorting/include/CGAL/Multiscale_sort.h b/Spatial_sorting/include/CGAL/Multiscale_sort.h index 7d17617b3e1..b2cec8900ac 100644 --- a/Spatial_sorting/include/CGAL/Multiscale_sort.h +++ b/Spatial_sorting/include/CGAL/Multiscale_sort.h @@ -22,28 +22,28 @@ namespace CGAL { template class Multiscale_sort { - Sort _sort; - std::ptrdiff_t _threshold; - double _ratio; + Sort _sort; + std::ptrdiff_t _threshold; + double _ratio; public: - Multiscale_sort (const Sort &sort = Sort(), std::ptrdiff_t threshold = 1, double ratio = 0.5) - : _sort (sort), _threshold (threshold), _ratio (ratio) - { - CGAL_precondition (0. <= ratio && ratio <= 1.); - } + Multiscale_sort (const Sort &sort = Sort(), std::ptrdiff_t threshold = 1, double ratio = 0.5) + : _sort (sort), _threshold (threshold), _ratio (ratio) + { + CGAL_precondition (0. <= ratio && ratio <= 1.); + } - template - void operator() (RandomAccessIterator begin, RandomAccessIterator end) const - { - typedef typename std::iterator_traits::difference_type difference_type; - RandomAccessIterator middle = begin; - if (end - begin >= _threshold) { - middle = begin + difference_type (double(end - begin) * _ratio); - this->operator() (begin, middle); - } - _sort (middle, end); + template + void operator() (RandomAccessIterator begin, RandomAccessIterator end) const + { + typedef typename std::iterator_traits::difference_type difference_type; + RandomAccessIterator middle = begin; + if (end - begin >= _threshold) { + middle = begin + difference_type (double(end - begin) * _ratio); + this->operator() (begin, middle); } + _sort (middle, end); + } }; } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_2.h b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_2.h index 488599fc8f4..bd1e9069693 100644 --- a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_2.h +++ b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_2.h @@ -9,7 +9,6 @@ // // Author(s) : Sebastien Loriot - #ifndef CGAL_SPATIAL_SORT_TRAITS_ADAPTER_2_H #define CGAL_SPATIAL_SORT_TRAITS_ADAPTER_2_H @@ -19,47 +18,51 @@ #include - namespace CGAL{ - + using ::get; -template -class Spatial_sort_traits_adapter_2:public Base_traits{ +template +class Spatial_sort_traits_adapter_2 + : public Base_traits +{ PointPropertyMap ppmap_; public: Spatial_sort_traits_adapter_2(Base_traits base=Base_traits()):Base_traits(base){} - Spatial_sort_traits_adapter_2(const PointPropertyMap& ppmap,Base_traits base=Base_traits()) - :Base_traits(base),ppmap_(ppmap){} + Spatial_sort_traits_adapter_2(const PointPropertyMap& ppmap, Base_traits base=Base_traits()) + :Base_traits(base), ppmap_(ppmap){} typedef Base_traits Gt; typedef typename boost::property_traits::key_type Point_2; typedef typename boost::call_traits::param_type Arg_type; - struct Less_x_2 : public Base_traits::Less_x_2{ - Less_x_2(const PointPropertyMap& ppmap,const typename Base_traits::Less_x_2& base): - Base_traits::Less_x_2(base),ppmap_(ppmap){} + struct Less_x_2 + : public Base_traits::Less_x_2 + { + Less_x_2(const PointPropertyMap& ppmap, const typename Base_traits::Less_x_2& base): + Base_traits::Less_x_2(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q)); + bool operator()(Arg_type p, Arg_type q) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q)); } }; - struct Less_y_2 : public Base_traits::Less_y_2{ - Less_y_2(const PointPropertyMap& ppmap,const typename Base_traits::Less_y_2& base): - Base_traits::Less_y_2(base),ppmap_(ppmap){} + struct Less_y_2 + : public Base_traits::Less_y_2 + { + Less_y_2(const PointPropertyMap& ppmap, const typename Base_traits::Less_y_2& base): + Base_traits::Less_y_2(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q)); + bool operator()(Arg_type p, Arg_type q) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q)); } }; - Less_x_2 less_x_2_object () const {return Less_x_2(ppmap_,static_cast(this)->less_x_2_object() );} - Less_y_2 less_y_2_object () const {return Less_y_2(ppmap_,static_cast(this)->less_y_2_object() );} - + Less_x_2 less_x_2_object () const {return Less_x_2(ppmap_, static_cast(this)->less_x_2_object() );} + Less_y_2 less_y_2_object () const {return Less_y_2(ppmap_, static_cast(this)->less_y_2_object() );} + const PointPropertyMap& point_property_map() const {return ppmap_;} - }; } //namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.h b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.h index a9f4778345c..ac43a8586d9 100644 --- a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.h +++ b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_3.h @@ -17,57 +17,63 @@ #include - namespace CGAL{ using ::get; - -template -class Spatial_sort_traits_adapter_3:public Base_traits{ + +template +class Spatial_sort_traits_adapter_3 + : public Base_traits +{ PointPropertyMap ppmap_; public: Spatial_sort_traits_adapter_3(Base_traits base=Base_traits()):Base_traits(base){} - Spatial_sort_traits_adapter_3(const PointPropertyMap& ppmap,Base_traits base=Base_traits()) - :Base_traits(base),ppmap_(ppmap){} + Spatial_sort_traits_adapter_3(const PointPropertyMap& ppmap, Base_traits base=Base_traits()) + :Base_traits(base), ppmap_(ppmap){} typedef Base_traits Gt; typedef typename boost::property_traits::key_type Point_3; typedef typename boost::call_traits::param_type Arg_type; - struct Less_x_3 : public Base_traits::Less_x_3{ - Less_x_3(const PointPropertyMap& ppmap,const typename Base_traits::Less_x_3& base): - Base_traits::Less_x_3(base),ppmap_(ppmap){} + struct Less_x_3 + : public Base_traits::Less_x_3 + { + Less_x_3(const PointPropertyMap& ppmap, const typename Base_traits::Less_x_3& base): + Base_traits::Less_x_3(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q)); + bool operator()(Arg_type p, Arg_type q) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q)); } }; - struct Less_y_3 : public Base_traits::Less_y_3{ - Less_y_3(const PointPropertyMap& ppmap,const typename Base_traits::Less_y_3& base): + struct Less_y_3 + : public Base_traits::Less_y_3 + { + Less_y_3(const PointPropertyMap& ppmap, const typename Base_traits::Less_y_3& base): Base_traits::Less_y_3(base),ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q)); + bool operator()(Arg_type p, Arg_type q) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q)); } }; - struct Less_z_3 : public Base_traits::Less_z_3{ - Less_z_3(const PointPropertyMap& ppmap,const typename Base_traits::Less_z_3& base): - Base_traits::Less_z_3(base),ppmap_(ppmap){} + struct Less_z_3 + : public Base_traits::Less_z_3 + { + Less_z_3(const PointPropertyMap& ppmap, const typename Base_traits::Less_z_3& base): + Base_traits::Less_z_3(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q)); + bool operator()(Arg_type p, Arg_type q) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q)); } }; - Less_x_3 less_x_3_object () const {return Less_x_3(ppmap_,static_cast(this)->less_x_3_object() );} - Less_y_3 less_y_3_object () const {return Less_y_3(ppmap_,static_cast(this)->less_y_3_object() );} - Less_z_3 less_z_3_object () const {return Less_z_3(ppmap_,static_cast(this)->less_z_3_object() );} - + Less_x_3 less_x_3_object () const {return Less_x_3(ppmap_, static_cast(this)->less_x_3_object() );} + Less_y_3 less_y_3_object () const {return Less_y_3(ppmap_, static_cast(this)->less_y_3_object() );} + Less_z_3 less_z_3_object () const {return Less_z_3(ppmap_, static_cast(this)->less_z_3_object() );} + const PointPropertyMap& point_property_map() const {return ppmap_;} - }; } //namespace CGAL diff --git a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h index 039718fc854..0a6313c244f 100644 --- a/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h +++ b/Spatial_sorting/include/CGAL/Spatial_sort_traits_adapter_d.h @@ -20,58 +20,60 @@ namespace CGAL{ using ::get; - -template -class Spatial_sort_traits_adapter_d:public Base_traits{ + +template +class Spatial_sort_traits_adapter_d + : public Base_traits +{ PointPropertyMap ppmap_; public: - Spatial_sort_traits_adapter_d(Base_traits base=Base_traits()):Base_traits(base){} + Spatial_sort_traits_adapter_d(Base_traits base=Base_traits()) : Base_traits(base){} - Spatial_sort_traits_adapter_d(const PointPropertyMap& ppmap,Base_traits base=Base_traits()) - :Base_traits(base),ppmap_(ppmap){} + Spatial_sort_traits_adapter_d(const PointPropertyMap& ppmap, Base_traits base=Base_traits()) + :Base_traits(base), ppmap_(ppmap){} typedef Base_traits Gt; typedef typename boost::property_traits::key_type Point_d; typedef typename boost::call_traits::param_type Arg_type; - - - struct Point_dimension_d: public Base_traits::Point_dimension_d{ - Point_dimension_d(const PointPropertyMap& ppmap,const typename Base_traits::Point_dimension_d& base): - Base_traits::Point_dimension_d(base),ppmap_(ppmap){} + struct Point_dimension_d + : public Base_traits::Point_dimension_d + { + Point_dimension_d(const PointPropertyMap& ppmap, const typename Base_traits::Point_dimension_d& base): + Base_traits::Point_dimension_d(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; int operator()(Arg_type p) const { - return static_cast(this)->operator()(get(ppmap_,p)); + return static_cast(this)->operator()(get(ppmap_, p)); } }; - struct Less_coordinate_d: public Base_traits::Less_coordinate_d{ - Less_coordinate_d(const PointPropertyMap& ppmap,const typename Base_traits::Less_coordinate_d& base): - Base_traits::Less_coordinate_d(base),ppmap_(ppmap){} + struct Less_coordinate_d + : public Base_traits::Less_coordinate_d + { + Less_coordinate_d(const PointPropertyMap& ppmap, const typename Base_traits::Less_coordinate_d& base): + Base_traits::Less_coordinate_d(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,Arg_type q,int i) const { - return static_cast(this)->operator()(get(ppmap_,p),get(ppmap_,q),i); + bool operator()(Arg_type p, Arg_type q, int i) const { + return static_cast(this)->operator()(get(ppmap_,p), get(ppmap_,q), i); } }; - - struct Compute_coordinate_d: public Base_traits::Compute_coordinate_d{ - Compute_coordinate_d(const PointPropertyMap& ppmap,const typename Base_traits::Compute_coordinate_d& base): - Base_traits::Compute_coordinate_d(base),ppmap_(ppmap){} + struct Compute_coordinate_d + : public Base_traits::Compute_coordinate_d + { + Compute_coordinate_d(const PointPropertyMap& ppmap, const typename Base_traits::Compute_coordinate_d& base): + Base_traits::Compute_coordinate_d(base), ppmap_(ppmap){} const PointPropertyMap& ppmap_; - bool operator()(Arg_type p,int i) const { - return static_cast(this)->operator()(get(ppmap_,p),i); + bool operator()(Arg_type p, int i) const { + return static_cast(this)->operator()(get(ppmap_,p), i); } }; - - - Point_dimension_d point_dimension_d_object () const {return Point_dimension_d(ppmap_,static_cast(this)->point_dimension_d_object() );} - Less_coordinate_d less_coordinate_d_object () const {return Less_coordinate_d(ppmap_,static_cast(this)->less_coordinate_d_object() );} - Compute_coordinate_d compute_coordinate_d_object () const {return Compute_coordinate_d(ppmap_,static_cast(this)->compute_coordinate_d_object() );} - + Point_dimension_d point_dimension_d_object () const {return Point_dimension_d(ppmap_, static_cast(this)->point_dimension_d_object() );} + Less_coordinate_d less_coordinate_d_object () const {return Less_coordinate_d(ppmap_, static_cast(this)->less_coordinate_d_object() );} + Compute_coordinate_d compute_coordinate_d_object () const {return Compute_coordinate_d(ppmap_, static_cast(this)->compute_coordinate_d_object() );} + const PointPropertyMap& point_property_map() const {return ppmap_;} - }; } //namespace CGAL diff --git a/Spatial_sorting/include/CGAL/hilbert_sort.h b/Spatial_sorting/include/CGAL/hilbert_sort.h index 0a1e8552e9b..3fbf0961720 100644 --- a/Spatial_sorting/include/CGAL/hilbert_sort.h +++ b/Spatial_sorting/include/CGAL/hilbert_sort.h @@ -27,120 +27,115 @@ #include namespace CGAL { - - namespace internal { - template - void hilbert_sort (RandomAccessIterator begin, - RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_2 *) - { - typedef std::iterator_traits ITraits; - typedef typename ITraits::difference_type Diff_t; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); - (Hilbert_sort_2 (k))(begin, end); - } - - template - void hilbert_sort (RandomAccessIterator begin, - RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_3 *) - { - typedef std::iterator_traits ITraits; - typedef typename ITraits::difference_type Diff_t; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); - (Hilbert_sort_3 (k))(begin, end); - } +template +void hilbert_sort (RandomAccessIterator begin, + RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_2 *) +{ + typedef std::iterator_traits ITraits; + typedef typename ITraits::difference_type Diff_t; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); + (Hilbert_sort_2 (k))(begin, end); +} + +template +void hilbert_sort (RandomAccessIterator begin, + RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_3 *) +{ + typedef std::iterator_traits ITraits; + typedef typename ITraits::difference_type Diff_t; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); + (Hilbert_sort_3 (k))(begin, end); +} + +template +void hilbert_sort (RandomAccessIterator begin, + RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_d *) +{ + typedef std::iterator_traits ITraits; + typedef typename ITraits::difference_type Diff_t; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); + (Hilbert_sort_d (k))(begin, end); +} - template - void hilbert_sort (RandomAccessIterator begin, - RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_d *) - { - typedef std::iterator_traits ITraits; - typedef typename ITraits::difference_type Diff_t; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); - (Hilbert_sort_d (k))(begin, end); - } } // namespace internal template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - internal::hilbert_sort(begin, end, Kernel(), Hilbert_sort_median_policy(), - static_cast (0)); + internal::hilbert_sort(begin, end, Kernel(), Hilbert_sort_median_policy(), + static_cast (0)); } template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k) + const Kernel &k) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; - internal::hilbert_sort(begin, end, k, Hilbert_sort_median_policy(), - static_cast (0)); + internal::hilbert_sort(begin, end, k, Hilbert_sort_median_policy(), + static_cast (0)); } - template +template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_median_policy policy) + Hilbert_sort_median_policy policy) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; - - internal::hilbert_sort(begin, end, Kernel(), policy, - static_cast (0)); + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; + internal::hilbert_sort(begin, end, Kernel(), policy, + static_cast (0)); } - - template +template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_middle_policy policy) + Hilbert_sort_middle_policy policy) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; - - internal::hilbert_sort(begin, end, Kernel(), policy, - static_cast (0)); + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; + internal::hilbert_sort(begin, end, Kernel(), policy, + static_cast (0)); } - - template +template void hilbert_sort (RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, Policy policy) + const Kernel &k, Policy policy) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; - internal::hilbert_sort(begin, end, - k, policy, static_cast (0)); + internal::hilbert_sort(begin, end, + k, policy, static_cast (0)); } } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/hilbert_sort_on_sphere.h b/Spatial_sorting/include/CGAL/hilbert_sort_on_sphere.h index 3b6665a6628..57e436c671c 100644 --- a/Spatial_sorting/include/CGAL/hilbert_sort_on_sphere.h +++ b/Spatial_sorting/include/CGAL/hilbert_sort_on_sphere.h @@ -22,12 +22,12 @@ namespace internal { template void hilbert_sort_on_sphere (RandomAccessIterator begin, - RandomAccessIterator end, - const Kernel &k, - Policy, - typename Kernel::Point_3 *, - double sq_r, - const typename Kernel::Point_3 &p) + RandomAccessIterator end, + const Kernel &k, + Policy, + typename Kernel::Point_3 *, + double sq_r, + const typename Kernel::Point_3 &p) { typedef std::iterator_traits ITraits; typedef typename ITraits::difference_type Diff_t; @@ -41,62 +41,63 @@ void hilbert_sort_on_sphere (RandomAccessIterator begin, template void hilbert_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - double sq_r = 1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0)) + double sq_r = 1.0, + const typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3(0,0,0)) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; - - internal::hilbert_sort_on_sphere(begin, end, Kernel(), Hilbert_sort_median_policy(), - static_cast (0), sq_r, p); + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; + internal::hilbert_sort_on_sphere(begin, end, Kernel(), Hilbert_sort_median_policy(), static_cast (0), sq_r, p); } template void hilbert_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, Hilbert_sort_median_policy policy, - double sq_r = 1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0)) + double sq_r = 1.0, + const typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3(0,0,0)) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - internal::hilbert_sort_on_sphere(begin, end, Kernel(), policy, - static_cast (0), sq_r, p); + internal::hilbert_sort_on_sphere(begin, end, Kernel(), policy, static_cast (0), sq_r, p); } - template void hilbert_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, Hilbert_sort_middle_policy policy, - double sq_r = 1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0)) + double sq_r = 1.0, + const typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits< + typename std::iterator_traits::value_type>::Kernel::Point_3(0,0,0)) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - internal::hilbert_sort_on_sphere(begin, end, Kernel(), policy, - static_cast (0), sq_r, p); + internal::hilbert_sort_on_sphere(begin, end, Kernel(), policy, static_cast (0), sq_r, p); } - template -void hilbert_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, Policy policy, - double sq_r = 1.0, const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0)) +void hilbert_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, + const Kernel &k, Policy policy, + double sq_r = 1.0, + const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0)) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; - internal::hilbert_sort_on_sphere(begin, end, - k, policy, static_cast (0), sq_r, p); + internal::hilbert_sort_on_sphere(begin, end, k, policy, static_cast (0), sq_r, p); } } // end of namespace CGAL diff --git a/Spatial_sorting/include/CGAL/internal/Transform_coordinates_traits_3.h b/Spatial_sorting/include/CGAL/internal/Transform_coordinates_traits_3.h index 0ce6c186a63..699720504c6 100644 --- a/Spatial_sorting/include/CGAL/internal/Transform_coordinates_traits_3.h +++ b/Spatial_sorting/include/CGAL/internal/Transform_coordinates_traits_3.h @@ -13,10 +13,10 @@ #ifndef CGAL_INTERNAL_SCALE_COORDINATES_ADAPTOR_TRAITS_3_H #define CGAL_INTERNAL_SCALE_COORDINATES_ADAPTOR_TRAITS_3_H -namespace CGAL { +namespace CGAL { namespace internal { - + template struct Transform_constant_struct; @@ -52,162 +52,162 @@ struct Coordinate_value_adaptor; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.x();} - static typename R::FT y(const typename R::Point_3& p) {return p.y();} + static typename R::FT x(const typename R::Point_3& p) {return p.x();} + static typename R::FT y(const typename R::Point_3& p) {return p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.x();} - static typename R::FT y(const typename R::Point_3& p) {return p.y();} + static typename R::FT x(const typename R::Point_3& p) {return -p.x();} + static typename R::FT y(const typename R::Point_3& p) {return p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.x();} - static typename R::FT y(const typename R::Point_3& p) {return -p.y();} + static typename R::FT x(const typename R::Point_3& p) {return p.x();} + static typename R::FT y(const typename R::Point_3& p) {return -p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.x();} - static typename R::FT y(const typename R::Point_3& p) {return -p.y();} + static typename R::FT x(const typename R::Point_3& p) {return -p.x();} + static typename R::FT y(const typename R::Point_3& p) {return -p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.y();} - static typename R::FT y(const typename R::Point_3& p) {return p.x();} + static typename R::FT x(const typename R::Point_3& p) {return p.y();} + static typename R::FT y(const typename R::Point_3& p) {return p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.y();} - static typename R::FT y(const typename R::Point_3& p) {return p.x();} + static typename R::FT x(const typename R::Point_3& p) {return -p.y();} + static typename R::FT y(const typename R::Point_3& p) {return p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.y();} - static typename R::FT y(const typename R::Point_3& p) {return -p.x();} + static typename R::FT x(const typename R::Point_3& p) {return p.y();} + static typename R::FT y(const typename R::Point_3& p) {return -p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.y();} - static typename R::FT y(const typename R::Point_3& p) {return -p.x();} + static typename R::FT x(const typename R::Point_3& p) {return -p.y();} + static typename R::FT y(const typename R::Point_3& p) {return -p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.x();} - static typename R::FT y(const typename R::Point_3& p) {return p.z();} + static typename R::FT x(const typename R::Point_3& p) {return p.x();} + static typename R::FT y(const typename R::Point_3& p) {return p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.x();} - static typename R::FT y(const typename R::Point_3& p) {return p.z();} + static typename R::FT x(const typename R::Point_3& p) {return -p.x();} + static typename R::FT y(const typename R::Point_3& p) {return p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.x();} - static typename R::FT y(const typename R::Point_3& p) {return -p.z();} + static typename R::FT x(const typename R::Point_3& p) {return p.x();} + static typename R::FT y(const typename R::Point_3& p) {return -p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.x();} - static typename R::FT y(const typename R::Point_3& p) {return -p.z();} + static typename R::FT x(const typename R::Point_3& p) {return -p.x();} + static typename R::FT y(const typename R::Point_3& p) {return -p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.z();} - static typename R::FT y(const typename R::Point_3& p) {return p.x();} + static typename R::FT x(const typename R::Point_3& p) {return p.z();} + static typename R::FT y(const typename R::Point_3& p) {return p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.z();} - static typename R::FT y(const typename R::Point_3& p) {return p.x();} + static typename R::FT x(const typename R::Point_3& p) {return -p.z();} + static typename R::FT y(const typename R::Point_3& p) {return p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.z();} - static typename R::FT y(const typename R::Point_3& p) {return -p.x();} + static typename R::FT x(const typename R::Point_3& p) {return p.z();} + static typename R::FT y(const typename R::Point_3& p) {return -p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.z();} - static typename R::FT y(const typename R::Point_3& p) {return -p.x();} + static typename R::FT x(const typename R::Point_3& p) {return -p.z();} + static typename R::FT y(const typename R::Point_3& p) {return -p.x();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.y();} - static typename R::FT y(const typename R::Point_3& p) {return p.z();} + static typename R::FT x(const typename R::Point_3& p) {return p.y();} + static typename R::FT y(const typename R::Point_3& p) {return p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.y();} - static typename R::FT y(const typename R::Point_3& p) {return p.z();} + static typename R::FT x(const typename R::Point_3& p) {return -p.y();} + static typename R::FT y(const typename R::Point_3& p) {return p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.y();} - static typename R::FT y(const typename R::Point_3& p) {return -p.z();} + static typename R::FT x(const typename R::Point_3& p) {return p.y();} + static typename R::FT y(const typename R::Point_3& p) {return -p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.y();} - static typename R::FT y(const typename R::Point_3& p) {return -p.z();} + static typename R::FT x(const typename R::Point_3& p) {return -p.y();} + static typename R::FT y(const typename R::Point_3& p) {return -p.z();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.z();} - static typename R::FT y(const typename R::Point_3& p) {return p.y();} + static typename R::FT x(const typename R::Point_3& p) {return p.z();} + static typename R::FT y(const typename R::Point_3& p) {return p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.z();} - static typename R::FT y(const typename R::Point_3& p) {return p.y();} + static typename R::FT x(const typename R::Point_3& p) {return -p.z();} + static typename R::FT y(const typename R::Point_3& p) {return p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return p.z();} - static typename R::FT y(const typename R::Point_3& p) {return -p.y();} + static typename R::FT x(const typename R::Point_3& p) {return p.z();} + static typename R::FT y(const typename R::Point_3& p) {return -p.y();} }; template struct Coordinate_value_adaptor { - static typename R::FT x(const typename R::Point_3& p) {return -p.z();} - static typename R::FT y(const typename R::Point_3& p) {return -p.y();} + static typename R::FT x(const typename R::Point_3& p) {return -p.z();} + static typename R::FT y(const typename R::Point_3& p) {return -p.y();} }; template class Compute_x_2 { public: - typedef typename R::Point_3 Point; + typedef typename R::Point_3 Point; typename R::FT x(const Point &p) const { return Coordinate_value_adaptor::x(p); } typename R::FT operator()(const Point& p) const { return x(p); } }; template -class Compute_y_2 +class Compute_y_2 { public: - typedef typename R::Point_3 Point; + typedef typename R::Point_3 Point; typename R::FT y(const Point &p) const { return Coordinate_value_adaptor::y(p); } typename R::FT operator()(const Point& p) const { return y(p); } }; @@ -216,7 +216,7 @@ template class Less_x_2 { public: - typedef typename R::Point_3 Point; + typedef typename R::Point_3 Point; typename R::FT x(const Point &p) const { return Coordinate_value_adaptor::x(p); } bool operator()(const Point& p, const Point& q) const { return x(p) < x(q); } }; @@ -225,34 +225,33 @@ template class Less_y_2 { public: - typedef typename R::Point_3 Point; + typedef typename R::Point_3 Point; typename R::FT y(const Point &p) const { return Coordinate_value_adaptor::y(p); } bool operator()(const Point& p, const Point& q) const { return y(p) < y(q); } }; template struct Transform_coordinates_traits_3 { - private: - enum {opt = Transform_constant_struct::value}; - - public: - typedef Transform_coordinates_traits_3 Traits; - typedef R Rp; - typedef typename Rp::Point_3 Point_2; - typedef Less_x_2 Less_x; - typedef Less_y_2 Less_y; - typedef Compute_x_2 Compute_x; - typedef Compute_y_2 Compute_y; - - Transform_coordinates_traits_3(){} - Transform_coordinates_traits_3(const Transform_coordinates_traits_3&){} - - Less_x less_x_2_object() const { return Less_x(); } - Less_y less_y_2_object() const { return Less_y(); } - Compute_x compute_x_2_object() const { return Compute_x(); } - Compute_y compute_y_2_object() const { return Compute_y(); } +private: + enum {opt = Transform_constant_struct::value}; + +public: + typedef Transform_coordinates_traits_3 Traits; + typedef R Rp; + typedef typename Rp::Point_3 Point_2; + typedef Less_x_2 Less_x; + typedef Less_y_2 Less_y; + typedef Compute_x_2 Compute_x; + typedef Compute_y_2 Compute_y; + + Transform_coordinates_traits_3(){} + Transform_coordinates_traits_3(const Transform_coordinates_traits_3&){} + + Less_x less_x_2_object() const { return Less_x(); } + Less_y less_y_2_object() const { return Less_y(); } + Compute_x compute_x_2_object() const { return Compute_x(); } + Compute_y compute_y_2_object() const { return Compute_y(); } }; - } } //namespace CGAL::internal diff --git a/Spatial_sorting/include/CGAL/spatial_sort.h b/Spatial_sorting/include/CGAL/spatial_sort.h index d49dbf39927..aa38be26af8 100644 --- a/Spatial_sorting/include/CGAL/spatial_sort.h +++ b/Spatial_sorting/include/CGAL/spatial_sort.h @@ -29,153 +29,146 @@ namespace CGAL { namespace internal { - template - void spatial_sort ( - RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_2 *, - std::ptrdiff_t threshold_hilbert, - std::ptrdiff_t threshold_multiscale, - double ratio) - { - typedef std::iterator_traits Iterator_traits; - typedef typename Iterator_traits::difference_type Diff_t; - typedef Hilbert_sort_2 Sort; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end,rng); +template +void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_2 *, + std::ptrdiff_t threshold_hilbert, + std::ptrdiff_t threshold_multiscale, + double ratio) +{ + typedef std::iterator_traits Iterator_traits; + typedef typename Iterator_traits::difference_type Diff_t; + typedef Hilbert_sort_2 Sort; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end,rng); - if (threshold_hilbert==0) threshold_hilbert=4; - if (threshold_multiscale==0) threshold_multiscale=16; - if (ratio==0.0) ratio=0.25; - - (Multiscale_sort (Sort (k, threshold_hilbert), - threshold_multiscale, ratio)) (begin, end); - } - - template - void spatial_sort ( - RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_3 *, - std::ptrdiff_t threshold_hilbert, - std::ptrdiff_t threshold_multiscale, - double ratio) - { - typedef std::iterator_traits Iterator_traits; - typedef typename Iterator_traits::difference_type Diff_t; - typedef Hilbert_sort_3 Sort; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); - - if (threshold_hilbert==0) threshold_hilbert=8; - if (threshold_multiscale==0) threshold_multiscale=64; - if (ratio==0.0) ratio=0.125; - - (Multiscale_sort (Sort (k, threshold_hilbert), - threshold_multiscale, ratio)) (begin, end); - } - - template - void spatial_sort ( - RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_d *, - std::ptrdiff_t threshold_hilbert, - std::ptrdiff_t threshold_multiscale, - double ratio) - { - typedef std::iterator_traits Iterator_traits; - typedef typename Iterator_traits::difference_type Diff_t; - typedef Hilbert_sort_d Sort; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); - - if (threshold_hilbert==0) threshold_hilbert=10; - if (threshold_multiscale==0) threshold_multiscale=500; - if (ratio==0.0) ratio=0.05; - - (Multiscale_sort (Sort (k, threshold_hilbert), - threshold_multiscale, ratio)) (begin, end); - } - -} //namespace internal + if (threshold_hilbert==0) threshold_hilbert=4; + if (threshold_multiscale==0) threshold_multiscale=16; + if (ratio==0.0) ratio=0.25; + (Multiscale_sort (Sort (k, threshold_hilbert), threshold_multiscale, ratio)) (begin, end); +} template void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, - Policy policy, - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + Policy /*policy*/, + typename Kernel::Point_3 *, + std::ptrdiff_t threshold_hilbert, + std::ptrdiff_t threshold_multiscale, + double ratio) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; + typedef std::iterator_traits Iterator_traits; + typedef typename Iterator_traits::difference_type Diff_t; + typedef Hilbert_sort_3 Sort; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); - internal::spatial_sort(begin, end, k, policy, static_cast (0), - threshold_hilbert,threshold_multiscale,ratio); + if (threshold_hilbert==0) threshold_hilbert=8; + if (threshold_multiscale==0) threshold_multiscale=64; + if (ratio==0.0) ratio=0.125; + + (Multiscale_sort (Sort (k, threshold_hilbert), threshold_multiscale, ratio)) (begin, end); +} + +template +void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_d *, + std::ptrdiff_t threshold_hilbert, + std::ptrdiff_t threshold_multiscale, + double ratio) +{ + typedef std::iterator_traits Iterator_traits; + typedef typename Iterator_traits::difference_type Diff_t; + typedef Hilbert_sort_d Sort; + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); + + if (threshold_hilbert==0) threshold_hilbert=10; + if (threshold_multiscale==0) threshold_multiscale=500; + if (ratio==0.0) ratio=0.05; + + (Multiscale_sort (Sort (k, threshold_hilbert), threshold_multiscale, ratio)) (begin, end); +} + +} //namespace internal + +template +void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, + const Kernel &k, + Policy policy, + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) +{ + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + + internal::spatial_sort(begin, end, k, policy, static_cast (0), + threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_median_policy policy, - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + Hilbert_sort_median_policy policy, + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - spatial_sort (begin, end, Kernel(), policy, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort (begin, end, Kernel(), policy, + threshold_hilbert,threshold_multiscale,ratio); } - + template void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_middle_policy policy, - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + Hilbert_sort_middle_policy policy, + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - spatial_sort (begin, end, Kernel(), policy, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort (begin, end, Kernel(), policy, + threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, const Kernel &k, - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - spatial_sort (begin, end, k, - Hilbert_sort_median_policy(), - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort (begin, end, k, + Hilbert_sort_median_policy(), + threshold_hilbert,threshold_multiscale,ratio); } - template +template void spatial_sort (RandomAccessIterator begin, RandomAccessIterator end, - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { spatial_sort (begin, end, - Hilbert_sort_median_policy(), - threshold_hilbert,threshold_multiscale,ratio); + Hilbert_sort_median_policy(), + threshold_hilbert,threshold_multiscale,ratio); } } // namespace CGAL diff --git a/Spatial_sorting/include/CGAL/spatial_sort_on_sphere.h b/Spatial_sorting/include/CGAL/spatial_sort_on_sphere.h index ada26c748b6..2bcd6ec10e3 100644 --- a/Spatial_sorting/include/CGAL/spatial_sort_on_sphere.h +++ b/Spatial_sorting/include/CGAL/spatial_sort_on_sphere.h @@ -22,116 +22,115 @@ namespace CGAL { namespace internal { template -void spatial_sort_on_sphere ( - RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - Policy /*policy*/, - typename Kernel::Point_3 *, - double sq_r, - const typename Kernel::Point_3 &p, - std::ptrdiff_t threshold_hilbert, - std::ptrdiff_t threshold_multiscale, - double ratio) +void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, + const Kernel &k, + Policy /*policy*/, + typename Kernel::Point_3 *, + double sq_r, + const typename Kernel::Point_3 &p, + std::ptrdiff_t threshold_hilbert, + std::ptrdiff_t threshold_multiscale, + double ratio) { typedef Hilbert_sort_on_sphere_3 Sort; - typedef std::iterator_traits ITraits; - typedef typename ITraits::difference_type Diff_t; + typedef std::iterator_traits ITraits; + typedef typename ITraits::difference_type Diff_t; - boost::rand48 random; - boost::random_number_generator rng(random); - CGAL::cpp98::random_shuffle(begin,end, rng); + boost::rand48 random; + boost::random_number_generator rng(random); + CGAL::cpp98::random_shuffle(begin,end, rng); - if (threshold_hilbert==0) threshold_hilbert=4; - if (threshold_multiscale==0) threshold_multiscale=16; - if (ratio==0.0) ratio=0.25; + if (threshold_hilbert==0) threshold_hilbert=4; + if (threshold_multiscale==0) threshold_multiscale=16; + if (ratio==0.0) ratio=0.25; - (Multiscale_sort (Sort (k, sq_r, p, threshold_hilbert), - threshold_multiscale, ratio)) (begin, end); + (Multiscale_sort (Sort (k, sq_r, p, threshold_hilbert), + threshold_multiscale, ratio)) (begin, end); } } // end of namespace internal template void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - Policy policy, - double sq_r=1.0, - const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0), - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + const Kernel &k, + Policy policy, + double sq_r=1.0, + const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0), + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; - internal::spatial_sort_on_sphere(begin, end, k, policy, static_cast (0), - sq_r,p, threshold_hilbert,threshold_multiscale,ratio); + internal::spatial_sort_on_sphere(begin, end, k, policy, static_cast (0), + sq_r,p, threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_median_policy policy, - double sq_r=1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + Hilbert_sort_median_policy policy, + double sq_r=1.0, + const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - spatial_sort_on_sphere (begin, end, Kernel(), policy, sq_r, p, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort_on_sphere (begin, end, Kernel(), policy, sq_r, p, + threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - Hilbert_sort_middle_policy policy, - double sq_r=1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + Hilbert_sort_middle_policy policy, + double sq_r=1.0, + const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - typedef std::iterator_traits ITraits; - typedef typename ITraits::value_type value_type; - typedef CGAL::Kernel_traits KTraits; - typedef typename KTraits::Kernel Kernel; + typedef std::iterator_traits ITraits; + typedef typename ITraits::value_type value_type; + typedef CGAL::Kernel_traits KTraits; + typedef typename KTraits::Kernel Kernel; - spatial_sort_on_sphere (begin, end, Kernel(), policy, sq_r,p, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort_on_sphere (begin, end, Kernel(), policy, sq_r,p, + threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - const Kernel &k, - double sq_r = 1.0, - const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0), - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + const Kernel &k, + double sq_r = 1.0, + const typename Kernel::Point_3 &p = typename Kernel::Point_3(0,0,0), + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - spatial_sort_on_sphere (begin, end, k, - Hilbert_sort_median_policy(), sq_r, p, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort_on_sphere (begin, end, k, + Hilbert_sort_median_policy(), sq_r, p, + threshold_hilbert,threshold_multiscale,ratio); } template void spatial_sort_on_sphere (RandomAccessIterator begin, RandomAccessIterator end, - double sq_r = 1.0, - const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = - typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), - std::ptrdiff_t threshold_hilbert=0, - std::ptrdiff_t threshold_multiscale=0, - double ratio=0.0) + double sq_r = 1.0, + const typename CGAL::Kernel_traits::value_type>::Kernel::Point_3 &p = + typename CGAL::Kernel_traits::value_type>::Kernel::Point_3(0,0,0), + std::ptrdiff_t threshold_hilbert=0, + std::ptrdiff_t threshold_multiscale=0, + double ratio=0.0) { - spatial_sort_on_sphere (begin, end, - Hilbert_sort_median_policy(), sq_r,p, - threshold_hilbert,threshold_multiscale,ratio); + spatial_sort_on_sphere (begin, end, + Hilbert_sort_median_policy(), sq_r,p, + threshold_hilbert,threshold_multiscale,ratio); } } // end of namespace CGAL