1 // Copyright (c) 2000  Max-Planck-Institute Saarbruecken (Germany).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Partition_2/include/CGAL/Partition_traits_2.h $
7 // $Id: Partition_traits_2.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Susan Hert <hert@mpi-sb.mpg.de>
12 
13 #ifndef CGAL_PARTITION_TRAITS_2_H
14 #define CGAL_PARTITION_TRAITS_2_H
15 
16 #include <CGAL/license/Partition_2.h>
17 
18 
19 #include <boost/call_traits.hpp>
20 
21 #include <CGAL/property_map.h>
22 #include <CGAL/polygon_function_objects.h>
23 #include <CGAL/Polygon_2.h>
24 #include <list>
25 
26 namespace CGAL {
27 
28   template <class Base_traits, class PointPropertyMap = Identity_property_map<typename Base_traits::Point_2> >
29 class Partition_traits_2;
30 
31   template <typename BT, typename PM>
32   struct Polygon_traits_getter{
33     typedef Partition_traits_2<BT,PM> type;
34   };
35 
36   template <typename BT>
37   struct Polygon_traits_getter<BT,Identity_property_map<typename BT::Point_2> > {
38     typedef BT type;
39   };
40 
41 template <class Base_traits, class PointPropertyMap>
42 class Partition_traits_2 : public Base_traits
43 {
44 private:
45   typedef Base_traits                                              Kernel;
46   typedef Partition_traits_2<Base_traits,PointPropertyMap> Self;
47 
48   PointPropertyMap ppmap;
49 
50 public:
51 
52   Partition_traits_2(const Base_traits& base=Base_traits())
53     : Base_traits(base)
54   {}
55 
56   Partition_traits_2(const PointPropertyMap& ppmap,
57                              const Base_traits& base=Base_traits())
58   : Base_traits(base),ppmap(ppmap)
59   {}
60 
61   typedef typename Kernel::FT FT;
62   typedef typename boost::property_traits<PointPropertyMap>::key_type Point_2;
63   typedef typename boost::call_traits<Point_2>::param_type Arg_type;
64 
65   typedef ::std::list<Point_2>                      Container;
66   typedef typename Polygon_traits_getter<Base_traits,PointPropertyMap>::type PolygonTraits;
67   typedef CGAL::Polygon_2<PolygonTraits, Container>          Polygon_2;
68 
69   template <typename BaseFct>
70   struct Pmap_fct : public BaseFct {
71     Pmap_fct(const PointPropertyMap& ppmap, const BaseFct& base)
72       : BaseFct(base),ppmap(ppmap)
73     {}
74 
75     const PointPropertyMap& ppmap;
76 
77     typename BaseFct::result_type operator()(const Arg_type& p, const Arg_type& q) const {
78       return static_cast<const BaseFct*>(this)->operator()(get(ppmap,p),get(ppmap,q));
79     }
80 
81     typename BaseFct::result_type operator()(const Arg_type& p, const Arg_type& q, const Arg_type& r) const {
82       return static_cast<const BaseFct*>(this)->operator()(get(ppmap,p),get(ppmap,q),get(ppmap,r));
83     }
84   };
85 
86 
87   typedef Pmap_fct<typename Kernel::Equal_2>                    Equal_2;
88   typedef Pmap_fct<typename Kernel::Less_yx_2>                  Less_yx_2;
89   typedef Pmap_fct<typename Kernel::Less_xy_2>                  Less_xy_2;
90   typedef Pmap_fct<typename Kernel::Left_turn_2>                Left_turn_2;
91   typedef Pmap_fct<typename Kernel::Orientation_2>              Orientation_2;
92   typedef Pmap_fct<typename Kernel::Compare_y_2>                Compare_y_2;
93   typedef Pmap_fct<typename Kernel::Compare_x_2>                Compare_x_2;
94   typedef CGAL::Is_convex_2<Self>                               Is_convex_2;
95   typedef CGAL::Is_y_monotone_2<Self>                           Is_y_monotone_2;
96 
97 
98   // needed by visibility graph and thus by optimal convex
99   typedef Pmap_fct<typename Kernel::Collinear_are_ordered_along_line_2>   Collinear_are_ordered_along_line_2;
100   typedef Pmap_fct<typename Kernel::Are_strictly_ordered_along_line_2>
101                                                                 Are_strictly_ordered_along_line_2;
102 
103 
104   Equal_2
105   equal_2_object() const
106   { return Equal_2(ppmap,static_cast<const Base_traits*>(this)->equal_2_object()); }
107 
108   Orientation_2
109   orientation_2_object() const
110   { return Orientation_2(ppmap,static_cast<const Base_traits*>(this)->orientation_2_object()); }
111 
112   Less_yx_2
113   less_yx_2_object() const
114   { return Less_yx_2(ppmap,static_cast<const Base_traits*>(this)->less_yx_2_object()); }
115 
116   Less_xy_2
117   less_xy_2_object() const
118   { return Less_xy_2(ppmap,static_cast<const Base_traits*>(this)->less_xy_2_object()); }
119 
120   Left_turn_2
121   left_turn_2_object() const
122   { return Left_turn_2(ppmap,static_cast<const Base_traits*>(this)->left_turn_2_object()); }
123 
124   Compare_y_2
125   compare_y_2_object() const
126   {  return Compare_y_2(ppmap,static_cast<const Base_traits*>(this)->compare_y_2_object()); }
127 
128   Compare_x_2
129   compare_x_2_object() const
130   {  return Compare_x_2(ppmap,static_cast<const Base_traits*>(this)->compare_x_2_object()); }
131 
132 
133   Collinear_are_ordered_along_line_2
134   collinear_are_ordered_along_line_2_object() const
135   { return Collinear_are_ordered_along_line_2(ppmap,static_cast<const Base_traits*>(this)->collinear_are_ordered_along_line_2_object()); }
136 
137   Are_strictly_ordered_along_line_2
138   are_strictly_ordered_along_line_2_object() const
139   { return Are_strictly_ordered_along_line_2(ppmap,static_cast<const Base_traits*>(this)->are_strictly_ordered_along_line_2_object()); }
140 
141 
142   Is_convex_2
143   is_convex_2_object(const Self& traits) const
144   {  return Is_convex_2(traits); }
145 
146   Is_y_monotone_2
147   is_y_monotone_2_object(const Self& traits) const
148   {  return Is_y_monotone_2(traits); }
149 
150 
151 
152 };
153 
154 }
155 
156 
157 #endif // CGAL_PARTITION_TRAITS_2_H
158