00001 00027 #ifndef SGDK_MATH_ZERO_CHECKER_HPP 00028 #define SGDK_MATH_ZERO_CHECKER_HPP 00029 00030 namespace sgdk { 00031 00033 00077 template < 00078 #ifndef SGDK_DOX 00079 typename RealNumber = float 00080 #endif /* SGDK_DOX */ 00081 > 00082 class ZeroChecker 00083 { 00084 private: 00085 RealNumber _zero_tolerance; 00086 00087 public: 00089 00099 explicit ZeroChecker(const RealNumber zero_tolerance = 0.00001f) 00100 : _zero_tolerance((zero_tolerance < 0) ? -zero_tolerance : zero_tolerance) 00101 { 00102 } 00103 00105 00111 ZeroChecker(const ZeroChecker& copy) 00112 : _zero_tolerance(copy._zero_tolerance) 00113 { 00114 } 00115 00117 00124 ZeroChecker& operator=(const ZeroChecker& copy) 00125 { 00126 _zero_tolerance = copy._zero_tolerance; 00127 return *this; 00128 } 00129 00140 inline bool isZero(const RealNumber zero) const 00141 { 00142 return (-_zero_tolerance <= zero) && (zero <= _zero_tolerance); 00143 } 00144 00153 inline RealNumber getZeroTolerance() const 00154 { 00155 return _zero_tolerance; 00156 } 00157 00167 inline void setZeroTolerance(const RealNumber zero_tolerance) 00168 { 00169 _zero_tolerance 00170 = (zero_tolerance < 0) ? -zero_tolerance : zero_tolerance; 00171 } 00172 }; 00173 } // namespace sgdk 00174 00175 #endif /* SGDK_MATH_ZERO_CHECKER_HPP */
Swiss GD Knife is hosted by .