rheolef  7.0
point_predicate.cc
Go to the documentation of this file.
1 // together witha custom cgal kernel that uses rheolef::point_basic<T>
2 // "CGAL/internal/Static_filters/Orientation_3.h"
3 #include "rheolef/point.h"
4
5 #ifdef _RHEOLEF_HAVE_CGAL
6 #include "rheolef/cgal_traits.h"
7 #endif // _RHEOLEF_HAVE_CGAL
8
9 namespace rheolef {
10
11 template<class T>
12 static
13 T
15  const point_basic<T>& b)
16 {
17  T ax0 = a[0] - x[0];
18  T bx0 = b[0] - x[0];
19  T ax1 = a[1] - x[1];
20  T bx1 = b[1] - x[1];
21  return ax0*bx1 - ax1*bx0;
22 }
23 template <class T>
24 static
25 T
27  const point_basic<T>& b, const point_basic<T>& c)
28 {
29  T ax0 = a[0] - x[0];
30  T bx0 = b[0] - x[0];
31  T cx0 = c[0] - x[0];
32  T ax1 = a[1] - x[1];
33  T bx1 = b[1] - x[1];
34  T cx1 = c[1] - x[1];
35  T ax2 = a[2] - x[2];
36  T bx2 = b[2] - x[2];
37  T cx2 = c[2] - x[2];
38  return ax0 * (bx1 * cx2 - bx2 * cx1)
39  + bx0 * (cx1 * ax2 - cx2 * ax1)
40  + cx0 * (ax1 * bx2 - ax2 * bx1);
41 }
42 template <class T>
43 int
45  const point_basic<T>& a,
46  const point_basic<T>& b,
47  const point_basic<T>& c)
48 {
49 #ifdef _RHEOLEF_HAVE_CGAL
50  typedef typename geo_cgal_traits<T,2>::Kernel Kernel;
51  typename Kernel::Orientation_2 orientation;
52  CGAL::Orientation sgn = orientation(a, b, c);
53  return (sgn == CGAL::NEGATIVE) ? -1 : ((sgn == CGAL::ZERO) ? 0 : 1);
54 #else // _RHEOLEF_HAVE_CGAL
55  T sgn = inexact_orient2d(a, b, c);
56  return (sgn < 0) ? -1 : ((sgn == 0) ? 0 : 1);
57 #endif // _RHEOLEF_HAVE_CGAL
58 }
59 template <class T>
60 int
62  const point_basic<T>& a,
63  const point_basic<T>& b,
64  const point_basic<T>& c,
65  const point_basic<T>& d)
66 {
67 #ifdef _RHEOLEF_HAVE_CGAL
68  typedef typename geo_cgal_traits<T,3>::Kernel Kernel;
69  typename Kernel::Orientation_3 orientation;
70  CGAL::Orientation sgn = orientation(a, b, c, d);
71  return (sgn == CGAL::NEGATIVE) ? -1 : ((sgn == CGAL::ZERO) ? 0 : 1);
72 #else // _RHEOLEF_HAVE_CGAL
73  T sgn = inexact_orient3d(a, b, c, d);
74  return (sgn < 0) ? -1 : ((sgn == 0) ? 0 : 1);
75 #endif // _RHEOLEF_HAVE_CGAL
76 }
77 template<class T>
78 T
80  const point_basic<T>& c)
81 {
82  T value = inexact_orient2d(a, b, c);
83 #ifndef _RHEOLEF_HAVE_CGAL
84  return value;
85 #else // _RHEOLEF_HAVE_CGAL
86  int sgn = sign_orient2d(a, b, c);
87  value = fabs(value);
88  if (sgn == 0) return 0;
89  if (value != 0) return sgn*value;
90  // sgn != 0 but value == 0
92 #endif // _RHEOLEF_HAVE_CGAL
93 }
94 template <class T>
95 T
97  const point_basic<T>& c, const point_basic<T>& d)
98 {
99  T value = inexact_orient3d(a, b, c, d);
100 #ifndef _RHEOLEF_HAVE_CGAL
101  return value;
102 #else // _RHEOLEF_HAVE_CGAL
103  int sgn = sign_orient3d(a, b, c, d);
104  value = fabs(value);
105  if (sgn == 0) return 0;
106  if (value != 0) return sgn*value;
107  // sgn != 0 but value == 0
108  return sgn*std::numeric_limits<T>::epsilon();
109 #endif // _RHEOLEF_HAVE_CGAL
110 }
111 #define _RHEOLEF_instanciation(T) \
112 template T orient2d ( \
113  const point_basic<T>&, \
114  const point_basic<T>&, \
115  const point_basic<T>&); \
116 template T orient3d ( \
117  const point_basic<T>&, \
118  const point_basic<T>&, \
119  const point_basic<T>&, \
120  const point_basic<T>&); \
121 template int sign_orient2d ( \
122  const point_basic<T>&, \
123  const point_basic<T>&, \
124  const point_basic<T>&); \
125 template int sign_orient3d ( \
126  const point_basic<T>&, \
127  const point_basic<T>&, \
128  const point_basic<T>&, \
129  const point_basic<T>&); \
130
132
133 } // namespace rheolef
T orient2d(const point_basic< T > &a, const point_basic< T > &b, const point_basic< T > &c)
point - vertex of a mesh
Definition: point.h:22
irheostream, orheostream - large data streams
Definition: compiler.h:7
double Float
Definition: compiler.h:160
size_t d
#define _RHEOLEF_instanciation(T)
int sign_orient3d(const point_basic< T > &a, const point_basic< T > &b, const point_basic< T > &c, const point_basic< T > &d)
rheolef::std value
static T inexact_orient2d(const point_basic< T > &x, const point_basic< T > &a, const point_basic< T > &b)
int sign_orient2d(const point_basic< T > &a, const point_basic< T > &b, const point_basic< T > &c)
static T inexact_orient3d(const point_basic< T > &x, const point_basic< T > &a, const point_basic< T > &b, const point_basic< T > &c)
T orient3d(const point_basic< T > &a, const point_basic< T > &b, const point_basic< T > &c, const point_basic< T > &d)
Float epsilon