Easy3D 2.5.3
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
43 template <typename FT> inline FT min();
45 template <typename FT> inline FT max();
46
47 // Template specializations for float and double
48
50 template <> inline int min<int>() { return INT_MIN; }
52 template <> inline int max<int>() { return INT_MAX; }
54 template <> inline float min<float>() { return FLT_MIN; }
56 template <> inline float max<float>() { return FLT_MAX; }
58 template <> inline double min<double>() { return DBL_MIN; }
60 template <> inline double max<double>() { return DBL_MAX; }
61
63 template <typename FT> inline FT epsilon();
65 template <typename FT> inline FT epsilon_sqr();
66
67 // Template specializations for float and double
69 template <> inline float epsilon<float>() { return 1.0e-6f; }
71 template <> inline float epsilon_sqr<float>() { return 1.0e-12f; }
73 template <> inline double epsilon<double>() { return 1.0e-12; }
75 template <> inline double epsilon_sqr<double>() { return 1.0e-24; }
76
77
79 template<typename FT>
80 bool epsilon_equal(FT const& x, FT const& y, FT const& eps) { return std::abs(x - y) < eps; }
81
83 template<typename FT>
84 bool epsilon_not_equal(FT const& x, FT const& y, FT const& eps) { return std::abs(x - y) >= eps; }
85}
86
87
88#endif // EASY3D_CORE_CONSTANT_H
Definition: collider.cpp:182
int max< int >()
Function returning max for int type numbers.
Definition: constant.h:52
bool epsilon_equal(FT const &x, FT const &y, FT const &eps)
Tests if two values are Epsilon equal.
Definition: constant.h:80
double min< double >()
Function returning min for double type numbers.
Definition: constant.h:58
float epsilon_sqr< float >()
Function returning squared epsilon for float type numbers.
Definition: constant.h:71
double epsilon< double >()
Function returning epsilon for double type numbers.
Definition: constant.h:73
double epsilon_sqr< double >()
Function returning squared epsilon for double type numbers.
Definition: constant.h:75
FT max()
Function returning maximum representable value for a given type.
float min< float >()
Function returning min for float type numbers.
Definition: constant.h:54
int min< int >()
Function returning min for int type numbers.
Definition: constant.h:50
FT epsilon()
Function returning the epsilon value for a given type.
bool epsilon_not_equal(FT const &x, FT const &y, FT const &eps)
Tests if two values are not Epsilon equal.
Definition: constant.h:84
float max< float >()
Function returning max for float type numbers.
Definition: constant.h:56
double max< double >()
Function returning max for double type numbers.
Definition: constant.h:60
FT epsilon_sqr()
Function returning the squared epsilon value for a given type.
FT min()
Function returning minimum representable value for a given type.
float epsilon< float >()
Function returning epsilon for float type numbers.
Definition: constant.h:69