OpenMesh
Loading...
Searching...
No Matches
MathDefs.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43/*===========================================================================*\
44 * *
45 * $Revision$ *
46 * $Date$ *
47 * *
48\*===========================================================================*/
49
50#ifndef MATHDEFS_HH
51#define MATHDEFS_HH
52
53#include <cmath>
54#include <cfloat>
55
56#ifndef M_PI
57 #define M_PI 3.14159265359
58#endif
59
60namespace OpenMesh
61{
62
65template <class T, typename Real>
66inline bool is_zero(const T& _a, Real _eps)
67{ return fabs(_a) < _eps; }
68
69template <class T1, class T2, typename Real>
70inline bool is_eq(const T1& a, const T2& b, Real _eps)
71{ return is_zero(a-b, _eps); }
72
73template <class T1, class T2, typename Real>
74inline bool is_gt(const T1& a, const T2& b, Real _eps)
75{ return (a > b) && !is_eq(a,b,_eps); }
76
77template <class T1, class T2, typename Real>
78inline bool is_ge(const T1& a, const T2& b, Real _eps)
79{ return (a > b) || is_eq(a,b,_eps); }
80
81template <class T1, class T2, typename Real>
82inline bool is_lt(const T1& a, const T2& b, Real _eps)
83{ return (a < b) && !is_eq(a,b,_eps); }
84
85template <class T1, class T2, typename Real>
86inline bool is_le(const T1& a, const T2& b, Real _eps)
87{ return (a < b) || is_eq(a,b,_eps); }
88
89/*const float flt_eps__ = 10*FLT_EPSILON;
90const double dbl_eps__ = 10*DBL_EPSILON;*/
91const float flt_eps__ = (float)1e-05;
92const double dbl_eps__ = 1e-09;
93
94inline float eps__(float)
95{ return flt_eps__; }
96
97inline double eps__(double)
98{ return dbl_eps__; }
99
100template <class T>
101inline bool is_zero(const T& a)
102{ return is_zero(a, eps__(a)); }
103
104template <class T1, class T2>
105inline bool is_eq(const T1& a, const T2& b)
106{ return is_zero(a-b); }
107
108template <class T1, class T2>
109inline bool is_gt(const T1& a, const T2& b)
110{ return (a > b) && !is_eq(a,b); }
111
112template <class T1, class T2>
113inline bool is_ge(const T1& a, const T2& b)
114{ return (a > b) || is_eq(a,b); }
115
116template <class T1, class T2>
117inline bool is_lt(const T1& a, const T2& b)
118{ return (a < b) && !is_eq(a,b); }
119
120template <class T1, class T2>
121inline bool is_le(const T1& a, const T2& b)
122{ return (a < b) || is_eq(a,b); }
123
125
126template <class T>
127inline T sane_aarg(T _aarg)
128{
129 if (_aarg < -1)
130 {
131 _aarg = -1;
132 }
133 else if (_aarg > 1)
134 {
135 _aarg = 1;
136 }
137 return _aarg;
138}
139
144template <class T>
145T angle(T _cos_angle, T _sin_angle)
146{//sanity checks - otherwise acos will return nan
147 _cos_angle = sane_aarg(_cos_angle);
148 return (T) _sin_angle >= 0 ? acos(_cos_angle) : -acos(_cos_angle);
149}
150
151template <class T>
152inline T positive_angle(T _angle)
153{ return _angle < 0 ? (2*M_PI + _angle) : _angle; }
154
155template <class T>
156inline T positive_angle(T _cos_angle, T _sin_angle)
157{ return positive_angle(angle(_cos_angle, _sin_angle)); }
158
159template <class T>
160inline T deg_to_rad(const T& _angle)
161{ return M_PI*(_angle/180); }
162
163template <class T>
164inline T rad_to_deg(const T& _angle)
165{ return 180*(_angle/M_PI); }
166
167inline double log_(double _value)
168{ return log(_value); }
169
170}//namespace OpenMesh
171
172#endif//MATHDEFS_HH
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
T angle(T _cos_angle, T _sin_angle)
returns the angle determined by its cos and the sign of its sin result is positive if the angle is in...
Definition: MathDefs.hh:145
bool is_zero(const T &_a, Real _eps)
comparison operators with user-selected precision control
Definition: MathDefs.hh:66
T sane_aarg(T _aarg)
Trigonometry/angles - related.
Definition: MathDefs.hh:127

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .