1 // Copyright (c) 2005-2009  INRIA Sophia-Antipolis (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org)
5 //
6 // $URL$
7 // $Id$
8 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Sebastien Loriot, Sylvain Pion
12 
13 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
14 #include <CGAL/hilbert_sort.h>
15 #include <CGAL/CGAL_Ipelet_base.h>
16 
17 // --------------------------------------------------------------------
18 
19 
20 namespace CGAL_hilbert_sort{
21 
22 typedef CGAL::Exact_predicates_inexact_constructions_kernel               Kernel;
23 
24 const std::string sublabel[] ={
25   "Hilbert sorting curve", "Help"
26 };
27 
28 const std::string helpmsg[] = {
29   "Sort the points along a Hilbert curve"
30 };
31 
32 struct hilbertsortIpelet
33   : CGAL::Ipelet_base<Kernel,2>
34 {
hilbertsortIpeletCGAL_hilbert_sort::hilbertsortIpelet35   hilbertsortIpelet()
36     : CGAL::Ipelet_base<Kernel,2>("Hilbert sort",sublabel, helpmsg) {}
37 
38   void protected_run(int);
39 };
40 
41 
protected_run(int fn)42 void hilbertsortIpelet::protected_run(int fn)
43 {
44   if (fn==2) {
45     show_help();
46     return;
47   }
48 
49 
50 
51   std::vector<Point_2> pt_list;
52 
53   read_active_objects( CGAL::dispatch_or_drop_output<Point_2>( std::back_inserter(pt_list) ) );
54 
55   if (pt_list.empty()) {
56     print_error_message("No mark selected");
57     return;
58   }
59 
60   if (fn==0) CGAL::hilbert_sort(pt_list.begin(), pt_list.end());
61   else       CGAL::hilbert_sort(pt_list.begin(), pt_list.end(), CGAL::Hilbert_sort_middle_policy());
62 
63   draw_polyline_in_ipe(pt_list.begin(), pt_list.end());
64 }
65 
66 }
67 
68 CGAL_IPELET(CGAL_hilbert_sort::hilbertsortIpelet)
69