Easy3D 2.6.1
Loading...
Searching...
No Matches
constant.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_CORE_CONSTANT_H
28#define EASY3D_CORE_CONSTANT_H
29
30#include <cfloat>
31#include <climits>
32#include <cmath>
33
34
35namespace easy3d {
36
37#ifndef M_PI
38#define M_PI 3.14159265358979323846264338327950288
39#endif
40
41
47 template <typename FT> FT min();
53 template <typename FT> FT max();
54
55 // Template specializations for int, float, and double
56
61 template <> inline int min<int>() { return INT_MIN; }
66 template <> inline int max<int>() { return INT_MAX; }
71 template <> inline float min<float>() { return FLT_MIN; }
76 template <> inline float max<float>() { return FLT_MAX; }
81 template <> inline double min<double>() { return DBL_MIN; }
86 template <> inline double max<double>() { return DBL_MAX; }
87
93 template <typename FT> FT epsilon();
99 template <typename FT> FT epsilon_sqr();
100
101 // Template specializations for float and double
102
107 template <> inline float epsilon<float>() { return 1.0e-6f; }
112 template <> inline float epsilon_sqr<float>() { return 1.0e-12f; }
117 template <> inline double epsilon<double>() { return 1.0e-12; }
122 template <> inline double epsilon_sqr<double>() { return 1.0e-24; }
123
124
133 template<typename FT>
134 bool epsilon_equal(FT const& x, FT const& y, FT const& eps) { return std::abs(x - y) < eps; }
135
144 template<typename FT>
145 bool epsilon_not_equal(FT const& x, FT const& y, FT const& eps) { return std::abs(x - y) >= eps; }
146
147}
148
149
150#endif // EASY3D_CORE_CONSTANT_H
Definition collider.cpp:182
bool epsilon_not_equal(FT const &x, FT const &y, FT const &eps)
Tests if two values are not Epsilon equal.
Definition constant.h:145
double epsilon< double >()
Function returning epsilon for double type numbers.
Definition constant.h:117
double min< double >()
Function returning min for double type numbers.
Definition constant.h:81
FT min()
Function returning minimum representable value for a given type.
float max< float >()
Function returning max for float type numbers.
Definition constant.h:76
FT epsilon()
Function returning the epsilon value for a given type.
bool epsilon_equal(FT const &x, FT const &y, FT const &eps)
Tests if two values are Epsilon equal.
Definition constant.h:134
FT max()
Function returning maximum representable value for a given type.
FT epsilon_sqr()
Function returning the squared epsilon value for a given type.
int min< int >()
Function returning min for int type numbers.
Definition constant.h:61
double epsilon_sqr< double >()
Function returning squared epsilon for double type numbers.
Definition constant.h:122
double max< double >()
Function returning max for double type numbers.
Definition constant.h:86
int max< int >()
Function returning max for int type numbers.
Definition constant.h:66
float min< float >()
Function returning min for float type numbers.
Definition constant.h:71
float epsilon< float >()
Function returning epsilon for float type numbers.
Definition constant.h:107
float epsilon_sqr< float >()
Function returning squared epsilon for float type numbers.
Definition constant.h:112