Skip to content

Commit 79a4180

Browse files
committed
Add static filter
1 parent 3863280 commit 79a4180

File tree

2 files changed

+89
-51
lines changed

2 files changed

+89
-51
lines changed

Filtered_kernel/include/CGAL/Filtered_rational_kernel.h

+86-50
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <CGAL/Simple_cartesian.h>
1717
#include <CGAL/intersections.h>
1818
#include <CGAL/Filtered_rational.h>
19+
#include <CGAL/Static_filtered_predicate.h>
1920
#include <CGAL/Filtered_kernel/Cartesian_coordinate_iterator_2.h>
2021
#include <CGAL/Filtered_kernel/Cartesian_coordinate_iterator_3.h>
2122
#include <CGAL/Interval_nt.h>
@@ -27,6 +28,27 @@
2728

2829
namespace CGAL {
2930

31+
template <typename T1, typename T2>
32+
struct Approximate_exact_pair : public std::pair<T1,T2> {
33+
typedef std::pair<T1,T2> Base;
34+
35+
Approximate_exact_pair()
36+
{}
37+
38+
Approximate_exact_pair(const T1& t1, const T2& ts)
39+
: Base(t1,t2)
40+
{}
41+
42+
Approximate_exact_pair(const std::pair<T1,T2>& p)
43+
: Base(p)
44+
{}
45+
46+
const T1& approx() const
47+
{
48+
return first;
49+
}
50+
};
51+
3052
namespace mpl {
3153

3254
BOOST_MPL_HAS_XXX_TRAIT_DEF(first_type)
@@ -102,7 +124,7 @@ struct Getter<X>\
102124
typedef X first_type; \
103125
typedef X second_type; \
104126
}; \
105-
const X& get_approx(const X& x) { return x; }\
127+
const X& approx(const X& x) { return x; }\
106128
const X& get_exact(const X& x) { return x; }
107129

108130
template <class A>
@@ -130,6 +152,13 @@ struct Getter<std::pair<A1, A2> >
130152
typedef A2 second_type;
131153
};
132154

155+
template <class A1, class A2>
156+
struct Getter<Approximate_exact_pair<A1, A2> >
157+
{
158+
typedef A1 first_type;
159+
typedef A2 second_type;
160+
};
161+
133162
template <class A_FT, class E_FT>
134163
struct Getter<Filtered_rational<A_FT,E_FT>>
135164
{
@@ -139,23 +168,23 @@ struct Getter<Filtered_rational<A_FT,E_FT>>
139168

140169
template <class A1, class A2>
141170
const A1&
142-
get_approx(const std::pair<A1,A2>& p)
171+
approx(const Approximate_exact_pair<A1,A2>& p)
143172
{
144173
return p.first;
145174
}
146175

147176
template <class A1, class A2>
148177
const A1&
149-
get_approx(const Filtered_rational<A1,A2>& p)
178+
approx(const Filtered_rational<A1,A2>& p)
150179
{
151180
return p.n1();
152181
}
153182

154183
template <class A>
155184
const typename A::Rep::first_type&
156-
get_approx(const A& a, typename boost::disable_if< mpl::is_pair_<A> >::type* = nullptr)
185+
approx(const A& a, typename boost::disable_if< mpl::is_pair_<A> >::type* = nullptr)
157186
{
158-
return get_approx(a.rep());
187+
return approx(a.rep());
159188
}
160189

161190
template <class A1, class A2>
@@ -180,13 +209,17 @@ get_exact(const A& a, typename boost::disable_if< mpl::is_pair_<A> >::type* = nu
180209
}
181210

182211
template <class AP, class EP>
183-
class Predicate_wrapper
212+
class Filtered_rational_predicate
184213
{
185214
AP ap;
186215
EP ep;
187216

188217
public:
189-
Predicate_wrapper(const AP &pap = AP(), const EP &pep = EP()) : ap(pap), ep(pep) { }
218+
// CGAL_static_assertion((std::is_same<typename AP::result_type, typename EP::result_type>::value));
219+
typedef typename EP::result_type result_type;
220+
221+
public:
222+
Filtered_rational_predicate(const AP &pap = AP(), const EP &pep = EP()) : ap(pap), ep(pep) { }
190223

191224
template <class ... A>
192225
typename CGAL::cpp11::result_of<EP(typename Getter<A>::second_type...)>::type
@@ -199,7 +232,7 @@ class Predicate_wrapper
199232

200233
try
201234
{
202-
result_type_1 res1 = ap(get_approx(a)...);
235+
result_type_1 res1 = ap(approx(a)...);
203236
if (is_certain(res1))
204237
return make_certain(res1);
205238
}
@@ -211,15 +244,15 @@ class Predicate_wrapper
211244
};
212245

213246
template <class AP, class EP, class AK, class EK, class FRK>
214-
class Construction_wrapper
247+
class Filtered_rational_construction
215248
{
216249
AP ap;
217250
EP ep;
218251

219252
CGAL::Cartesian_converter<EK, AK> e2a;
220253

221254
public:
222-
Construction_wrapper(const AP &pap = AP(), const EP &pep = EP()) : ap(pap), ep(pep) { }
255+
Filtered_rational_construction(const AP &pap = AP(), const EP &pep = EP()) : ap(pap), ep(pep) { }
223256

224257
template <class T>
225258
struct result;
@@ -269,10 +302,12 @@ class Construction_wrapper
269302
result_type_2 res2 = ep(get_exact(a)...);
270303

271304
return Pairify<result_type_1, result_type_2, EK, FRK>()(Approx<result_type_1>(e2a, ap)
272-
(res2, get_approx(a)...), res2);
305+
(res2, approx(a)...), res2);
273306
}
274307
};
275308

309+
310+
276311
template < class AK, class EK, class Kernel_ >
277312
class Filtered_rational_kernel_generic_base
278313
{
@@ -294,8 +329,9 @@ class Filtered_rational_kernel_generic_base
294329
typedef CGAL::Object Object_3;
295330

296331
typedef Kernel_ Kernel;
297-
typedef AK Kernel1;
298-
typedef EK Kernel2;
332+
typedef AK Approximate_kernel;
333+
typedef EK Exact_kernel;
334+
299335

300336
template < typename T >
301337
struct Ambient_dimension {
@@ -319,7 +355,7 @@ class Filtered_rational_kernel_generic_base
319355
typedef CGAL::Aff_transformationC3<Kernel_> Aff_transformation_3;
320356

321357
// Kernel objects are defined as pairs, with primitives run in parallel.
322-
#define CGAL_kc_pair(X) typedef std::pair<typename AK::X, typename EK::X> X;
358+
#define CGAL_frk_pair(X) typedef Approximate_exact_pair<typename AK::X, typename EK::X> X;
323359

324360

325361
// TODO : Object_[23] are subtil : should probably be Object(pair<...>).
@@ -328,42 +364,42 @@ class Filtered_rational_kernel_generic_base
328364
// takes its first argument by non-const reference.
329365
// Maybe Primitive_checker should provide a variant with non-const ref...
330366

331-
CGAL_kc_pair(Point_2)
332-
CGAL_kc_pair(Weighted_point_2)
333-
CGAL_kc_pair(Vector_2)
334-
CGAL_kc_pair(Direction_2)
335-
CGAL_kc_pair(Line_2)
336-
CGAL_kc_pair(Ray_2)
337-
CGAL_kc_pair(Segment_2)
338-
CGAL_kc_pair(Triangle_2)
339-
CGAL_kc_pair(Iso_rectangle_2)
340-
CGAL_kc_pair(Circle_2)
341-
CGAL_kc_pair(Conic_2)
342-
343-
344-
CGAL_kc_pair(Point_3)
345-
CGAL_kc_pair(Weighted_point_3)
346-
CGAL_kc_pair(Plane_3)
347-
CGAL_kc_pair(Vector_3)
348-
CGAL_kc_pair(Direction_3)
349-
CGAL_kc_pair(Line_3)
350-
CGAL_kc_pair(Ray_3)
351-
CGAL_kc_pair(Segment_3)
352-
CGAL_kc_pair(Triangle_3)
353-
CGAL_kc_pair(Tetrahedron_3)
354-
CGAL_kc_pair(Iso_cuboid_3)
355-
CGAL_kc_pair(Circle_3)
356-
CGAL_kc_pair(Sphere_3)
357-
358-
#undef CGAL_kc_pair
359-
360-
#define CGAL_Kernel_pred(X, Y) \
361-
typedef Predicate_wrapper<typename AK::X, typename EK::X> X; \
362-
X Y() const { return X(ak.Y(), ek.Y()); }
363-
364-
#define CGAL_Kernel_cons(X, Y) \
365-
typedef Construction_wrapper<typename AK::X, typename EK::X, AK, EK, Kernel_> X; \
366-
X Y() const { return X(ak.Y(), ek.Y()); }
367+
CGAL_frk_pair(Point_2)
368+
CGAL_frk_pair(Weighted_point_2)
369+
CGAL_frk_pair(Vector_2)
370+
CGAL_frk_pair(Direction_2)
371+
CGAL_frk_pair(Line_2)
372+
CGAL_frk_pair(Ray_2)
373+
CGAL_frk_pair(Segment_2)
374+
CGAL_frk_pair(Triangle_2)
375+
CGAL_frk_pair(Iso_rectangle_2)
376+
CGAL_frk_pair(Circle_2)
377+
CGAL_frk_pair(Conic_2)
378+
379+
380+
CGAL_frk_pair(Point_3)
381+
CGAL_frk_pair(Weighted_point_3)
382+
CGAL_frk_pair(Plane_3)
383+
CGAL_frk_pair(Vector_3)
384+
CGAL_frk_pair(Direction_3)
385+
CGAL_frk_pair(Line_3)
386+
CGAL_frk_pair(Ray_3)
387+
CGAL_frk_pair(Segment_3)
388+
CGAL_frk_pair(Triangle_3)
389+
CGAL_frk_pair(Tetrahedron_3)
390+
CGAL_frk_pair(Iso_cuboid_3)
391+
CGAL_frk_pair(Circle_3)
392+
CGAL_frk_pair(Sphere_3)
393+
394+
#undef CGAL_frk_pair
395+
396+
#define CGAL_Kernel_pred(P, Pf) \
397+
typedef Static_filtered_predicate<Approximate_kernel,Filtered_rational_predicate<typename AK::P, typename EK::P>, Exact_predicates_inexact_constructions_kernel::P> P; \
398+
P Pf() const { return P(); } // AF: Why was it P(ak.Pf(), ek.Pf()) ?
399+
400+
#define CGAL_Kernel_cons(C, Cf) \
401+
typedef Filtered_rational_construction<typename AK::C, typename EK::C, AK, EK, Kernel_> C; \
402+
C Cf() const { return C(ak.Cf(), ek.Cf()); }
367403

368404

369405
public:

Number_types/include/CGAL/Filtered_rational.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ class Filtered_rational
107107

108108
NT1& n1() { return _n1; }
109109
NT2& n2() { return _n2; }
110-
110+
111+
const NT1& approx() const { return _n1; }
112+
111113
// Validity checking: the exact number must be in the interval
112114

113115
bool is_valid() const

0 commit comments

Comments
 (0)