pull/3147/head
Kim Kulling 2020-04-14 19:07:41 +02:00 committed by GitHub
parent e399a12f71
commit b2a547b817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 16 deletions

View File

@ -55,42 +55,51 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
namespace Math { namespace Math {
// TODO: use binary GCD for unsigned integers .... /// @brief Will return the greatest common divisor.
template < typename IntegerType > /// @param a [in] Value a.
inline /// @param b [in] Value b.
IntegerType gcd( IntegerType a, IntegerType b ) { /// @return The greatest common divisor.
template <typename IntegerType>
inline IntegerType gcd( IntegerType a, IntegerType b ) {
const IntegerType zero = (IntegerType)0; const IntegerType zero = (IntegerType)0;
while ( true ) { while ( true ) {
if ( a == zero ) if ( a == zero ) {
return b; return b;
}
b %= a; b %= a;
if ( b == zero ) if ( b == zero ) {
return a; return a;
}
a %= b; a %= b;
} }
} }
/// @brief Will return the greatest common divisor.
/// @param a [in] Value a.
/// @param b [in] Value b.
/// @return The greatest common divisor.
template < typename IntegerType > template < typename IntegerType >
inline inline IntegerType lcm( IntegerType a, IntegerType b ) {
IntegerType lcm( IntegerType a, IntegerType b ) {
const IntegerType t = gcd (a,b); const IntegerType t = gcd (a,b);
if (!t) if (!t) {
return t; return t;
}
return a / t * b; return a / t * b;
} }
/// @brief Will return the smallest epsilon-value for the requested type.
/// @return The numercical limit epsilon depending on its type.
template<class T> template<class T>
inline inline T getEpsilon() {
T getEpsilon() {
return std::numeric_limits<T>::epsilon(); return std::numeric_limits<T>::epsilon();
} }
/// @brief Will return the constant PI for the requested type.
/// @return Pi
template<class T> template<class T>
inline inline T PI() {
T PI() {
return static_cast<T>(3.14159265358979323846); return static_cast<T>(3.14159265358979323846);
} }
} } // namespace Math
} } // namespace Assimp