1
/// This file is part of Rheolef.
3
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
5
/// Rheolef is free software; you can redistribute it and/or modify
6
/// it under the terms of the GNU General Public License as published by
7
/// the Free Software Foundation; either version 2 of the License, or
8
/// (at your option) any later version.
10
/// Rheolef is distributed in the hope that it will be useful,
11
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
/// GNU General Public License for more details.
15
/// You should have received a copy of the GNU General Public License
16
/// along with Rheolef; if not, write to the Free Software
17
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
/// =========================================================================
20
// robust floating point predicates:
21
// implementation using exact CGAL predicates, when available
22
// together witha custom cgal kernel that uses rheolef::point_basic<T>
24
// author: Pierre.Saramito@imag.fr
26
// date: 12 march 2012
28
// all the work for exact predicates is performed by :
29
// "CGAL/internal/Static_filters/Orientation_3.h"
31
#include "rheolef/point.h"
33
#ifdef _RHEOLEF_HAVE_CGAL
34
#include "rheolef/cgal_traits.h"
35
#endif // _RHEOLEF_HAVE_CGAL
42
inexact_orient2d (const point_basic<T>& x, const point_basic<T>& a,
43
const point_basic<T>& b)
49
return ax0*bx1 - ax1*bx0;
54
inexact_orient3d (const point_basic<T>& x, const point_basic<T>& a,
55
const point_basic<T>& b, const point_basic<T>& c)
66
return ax0 * (bx1 * cx2 - bx2 * cx1)
67
+ bx0 * (cx1 * ax2 - cx2 * ax1)
68
+ cx0 * (ax1 * bx2 - ax2 * bx1);
73
const point_basic<T>& a,
74
const point_basic<T>& b,
75
const point_basic<T>& c)
77
#ifdef _RHEOLEF_HAVE_CGAL
78
typedef typename geo_cgal_traits<T,2>::Kernel Kernel;
79
typename Kernel::Orientation_2 orientation;
80
CGAL::Orientation sgn = orientation(a, b, c);
81
return (sgn == CGAL::NEGATIVE) ? -1 : ((sgn == CGAL::ZERO) ? 0 : 1);
82
#else // _RHEOLEF_HAVE_CGAL
83
T sgn = inexact_orient2d(a, b, c);
84
return (sgn < 0) ? -1 : ((sgn == 0) ? 0 : 1);
85
#endif // _RHEOLEF_HAVE_CGAL
90
const point_basic<T>& a,
91
const point_basic<T>& b,
92
const point_basic<T>& c,
93
const point_basic<T>& d)
95
#ifdef _RHEOLEF_HAVE_CGAL
96
typedef typename geo_cgal_traits<T,3>::Kernel Kernel;
97
typename Kernel::Orientation_3 orientation;
98
CGAL::Orientation sgn = orientation(a, b, c, d);
99
return (sgn == CGAL::NEGATIVE) ? -1 : ((sgn == CGAL::ZERO) ? 0 : 1);
100
#else // _RHEOLEF_HAVE_CGAL
101
T sgn = inexact_orient3d(a, b, c, d);
102
return (sgn < 0) ? -1 : ((sgn == 0) ? 0 : 1);
103
#endif // _RHEOLEF_HAVE_CGAL
108
orient2d (const point_basic<T>& a, const point_basic<T>& b,
109
const point_basic<T>& c)
111
T value = inexact_orient2d(a, b, c);
112
#ifndef _RHEOLEF_HAVE_CGAL
114
#else // _RHEOLEF_HAVE_CGAL
115
int sgn = sign_orient2d(a, b, c);
117
if (sgn == 0) return 0;
118
if (value != 0) return sgn*value;
119
// sgn != 0 but value == 0
120
return sgn*std::numeric_limits<T>::epsilon();
121
#endif // _RHEOLEF_HAVE_CGAL
126
orient3d (const point_basic<T>& a, const point_basic<T>& b,
127
const point_basic<T>& c, const point_basic<T>& d)
129
T value = inexact_orient3d(a, b, c, d);
130
#ifndef _RHEOLEF_HAVE_CGAL
132
#else // _RHEOLEF_HAVE_CGAL
133
int sgn = sign_orient3d(a, b, c, d);
135
if (sgn == 0) return 0;
136
if (value != 0) return sgn*value;
137
// sgn != 0 but value == 0
138
return sgn*std::numeric_limits<T>::epsilon();
139
#endif // _RHEOLEF_HAVE_CGAL
141
// ----------------------------------------------------------------------------
142
// instanciation in library
143
// ----------------------------------------------------------------------------
144
#define _RHEOLEF_instanciation(T) \
145
template T orient2d ( \
146
const point_basic<T>&, \
147
const point_basic<T>&, \
148
const point_basic<T>&); \
149
template T orient3d ( \
150
const point_basic<T>&, \
151
const point_basic<T>&, \
152
const point_basic<T>&, \
153
const point_basic<T>&); \
154
template int sign_orient2d ( \
155
const point_basic<T>&, \
156
const point_basic<T>&, \
157
const point_basic<T>&); \
158
template int sign_orient3d ( \
159
const point_basic<T>&, \
160
const point_basic<T>&, \
161
const point_basic<T>&, \
162
const point_basic<T>&); \
164
_RHEOLEF_instanciation(Float)
166
} // namespace rheolef