1 // Copyright (c) 2005, 2012, 2020 Tel-Aviv University (Israel).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
7 //
8 // Author(s): Baruch Zukerman <baruchzu@post.tau.ac.il>
9 //            Alex Tsui <alextsui05@gmail.com>
10 //            Saurabh Singh <ssingh@cs.iitr.ac.in>
11 //            Ahmed Essam <theartful.ae@gmail.com>
12 
13 #ifndef ARRANGEMENT_DEMO_TYPES_H
14 #define ARRANGEMENT_DEMO_TYPES_H
15 
16 #include <CGAL/Arrangement_with_history_2.h>
17 #include <CGAL/Cartesian.h>
18 #include <CGAL/Arr_default_dcel.h>
19 #include <CGAL/Arr_segment_traits_2.h>
20 #include <CGAL/Arr_linear_traits_2.h>
21 #include <CGAL/Arr_polyline_traits_2.h>
22 
23 #ifdef CGAL_USE_CORE
24   #include <CGAL/CORE_algebraic_number_traits.h>
25   #include <CGAL/Arr_conic_traits_2.h>
26   #include <CGAL/Arr_algebraic_segment_traits_2.h>
27   #include <CGAL/Arr_Bezier_curve_traits_2.h>
28   #include <CGAL/Arr_rational_function_traits_2.h>
29   #include <CGAL/Algebraic_kernel_d_1.h>
30   #include <CGAL/CORE_BigRat.h>
31 #endif
32 
33 #include "RationalTypes.h"
34 
35 #include <QColor>
36 
37 // avoid polluting global namespace
38 // caused multiple bugs before!
39 namespace demo_types
40 {
41 struct DemoTypes
42 {
43 class Face_with_color : public CGAL::Arr_face_base
44 {
45   QColor    m_color;
46   bool      m_visited;
47 
48 public:
Face_with_colorDemoTypes49   Face_with_color() :
50       CGAL::Arr_face_base(), m_color(::Qt::white), m_visited(false)
51   {
52   }
53 
colorDemoTypes54   QColor color() const { return m_color; }
set_colorDemoTypes55   void set_color(const QColor& c) { m_color = c; }
visitedDemoTypes56   bool visited() const{ return m_visited; }
set_visitedDemoTypes57   void set_visited(bool b) { m_visited = b; }
58 };
59 
60 template <class Traits>
61 class Dcel :
62     public CGAL::Arr_dcel_base<
63       CGAL::Arr_vertex_base<typename Traits::Point_2>,
64       CGAL::Arr_halfedge_base<typename Traits::X_monotone_curve_2>,
65       Face_with_color>
66 {
67 public:
68    /*! \struct
69    * An auxiliary structure for rebinding the DCEL with a new traits class.
70    */
71   template <typename T>
72   struct rebind
73   {
74     typedef Dcel<T> other;
75   };
76 };
77 
78 // use same rational type across arrangements
79 // less specializations, and makes PointSnapper untemplated
80 typedef typename RationalTypes::Rational                Rational;
81 typedef typename RationalTypes::Rat_kernel              Rat_kernel;
82 typedef typename RationalTypes::Rat_point_2             Rat_point_2;
83 
84 // Segments:
85 typedef CGAL::Arr_segment_traits_2<Rat_kernel>          Seg_traits;
86 typedef Dcel<Seg_traits>                                Seg_dcel;
87 typedef CGAL::Arrangement_with_history_2<Seg_traits, Seg_dcel>
88                                                         Seg_arr;
89 
90 // Polyline
91 typedef CGAL::Arr_polyline_traits_2<Seg_traits>         Pol_traits;
92 typedef Dcel<Pol_traits>                                Pol_dcel;
93 typedef CGAL::Arrangement_with_history_2<Pol_traits,
94                                          Pol_dcel>      Pol_arr;
95 
96 // Linear:
97 typedef CGAL::Arr_linear_traits_2<Rat_kernel>           Lin_traits;
98 typedef Dcel<Lin_traits>                                Lin_dcel;
99 typedef CGAL::Arrangement_with_history_2<Lin_traits, Lin_dcel>
100                                                         Lin_arr;
101 
102 #ifdef CGAL_USE_CORE
103   typedef CGAL::CORE_algebraic_number_traits            Core_nt_traits;
104   typedef Core_nt_traits::Integer                       Core_integer;
105   typedef Core_nt_traits::Rational                      Core_rational;
106   typedef Core_nt_traits::Algebraic                     Core_algebraic;
107   typedef CGAL::Cartesian<Core_rational>                Core_rat_kernel;
108   typedef CGAL::Cartesian<Core_algebraic>               Core_alg_kernel;
109 
110   // Conics
111   typedef CGAL::Arr_conic_traits_2<
112     Core_rat_kernel, Core_alg_kernel, Core_nt_traits>
113                                                         Conic_traits;
114 
115   typedef Dcel<Conic_traits>                            Conic_dcel;
116   typedef CGAL::Arrangement_with_history_2<Conic_traits, Conic_dcel>
117                                                         Conic_arr;
118   // Algebraic
119   typedef CGAL::Arr_algebraic_segment_traits_2<Core_integer>
120                                                         Alg_seg_traits;
121   typedef Dcel<Alg_seg_traits>                          Alg_seg_dcel;
122   typedef CGAL::Arrangement_with_history_2<Alg_seg_traits, Alg_seg_dcel>
123                                                         Alg_seg_arr;
124   // Bezier
125   typedef CGAL::Arr_Bezier_curve_traits_2<
126     Core_rat_kernel, Core_alg_kernel, Core_nt_traits>
127                                                         Bezier_traits;
128   typedef Dcel<Bezier_traits>                           Bezier_dcel;
129   typedef CGAL::Arrangement_with_history_2<Bezier_traits, Bezier_dcel>
130                                                         Bezier_arr;
131 
132   // Rational functions
133   typedef CGAL::Algebraic_kernel_d_1<Core_integer>      AK1;
134   typedef CGAL::Arr_rational_function_traits_2<AK1>     Rational_traits;
135   typedef Dcel<Rational_traits>                         Rational_dcel;
136   typedef CGAL::Arrangement_with_history_2<Rational_traits, Rational_dcel>
137                                                         Rational_arr;
138 #endif
139 };
140 }
141 
142 #ifdef CGAL_USE_CORE
143   #define ARRANGEMENT_DEMO_SPECIALIZE_ARR_CORE(class_name)                     \
144     template class class_name<demo_types::DemoTypes::Conic_arr>;               \
145     template class class_name<demo_types::DemoTypes::Alg_seg_arr>;             \
146     template class class_name<demo_types::DemoTypes::Bezier_arr>;              \
147     template class class_name<demo_types::DemoTypes::Rational_arr>;
148   #define ARRANGEMENT_DEMO_SPECIALIZE_TRAITS_CORE(class_name)                  \
149     template class class_name<demo_types::DemoTypes::Conic_traits>;            \
150     template class class_name<demo_types::DemoTypes::Alg_seg_traits>;          \
151     template class class_name<demo_types::DemoTypes::Bezier_traits>;           \
152     template class class_name<demo_types::DemoTypes::Rational_traits>;
153 #else
154   #define ARRANGEMENT_DEMO_SPECIALIZE_ARR_CORE(class_name)
155   #define ARRANGEMENT_DEMO_SPECIALIZE_TRAITS_CORE(class_name)
156 #endif
157 
158 #define ARRANGEMENT_DEMO_SPECIALIZE_ARR(class_name)                            \
159   template class class_name<demo_types::DemoTypes::Seg_arr>;                   \
160   template class class_name<demo_types::DemoTypes::Pol_arr>;                   \
161   template class class_name<demo_types::DemoTypes::Lin_arr>;                   \
162   ARRANGEMENT_DEMO_SPECIALIZE_ARR_CORE(class_name)
163 
164 #define ARRANGEMENT_DEMO_SPECIALIZE_TRAITS(class_name)                         \
165   template class class_name<demo_types::DemoTypes::Seg_traits>;                \
166   template class class_name<demo_types::DemoTypes::Pol_traits>;                \
167   template class class_name<demo_types::DemoTypes::Lin_traits>;                \
168   ARRANGEMENT_DEMO_SPECIALIZE_TRAITS_CORE(class_name)
169 
170 #endif // ARRANGEMENT_DEMO_TYPES_H
171