Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:30:09

0001 /*
0002 ---------------------------------------------------------------------------
0003 Open Asset Import Library (assimp)
0004 ---------------------------------------------------------------------------
0005 
0006 Copyright (c) 2006-2024, assimp team
0007 
0008 All rights reserved.
0009 
0010 Redistribution and use of this software in source and binary forms,
0011 with or without modification, are permitted provided that the following
0012 conditions are met:
0013 
0014 * Redistributions of source code must retain the above
0015   copyright notice, this list of conditions and the
0016   following disclaimer.
0017 
0018 * Redistributions in binary form must reproduce the above
0019   copyright notice, this list of conditions and the
0020   following disclaimer in the documentation and/or other
0021   materials provided with the distribution.
0022 
0023 * Neither the name of the assimp team, nor the names of its
0024   contributors may be used to endorse or promote products
0025   derived from this software without specific prior
0026   written permission of the assimp team.
0027 
0028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0032 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0039 ---------------------------------------------------------------------------
0040 */
0041 
0042 #pragma once
0043 
0044 #ifdef __GNUC__
0045 #   pragma GCC system_header
0046 #endif
0047 
0048 /** @file  MathFunctions.h
0049 *  @brief Implementation of math utility functions.
0050  *
0051 */
0052 
0053 #include <limits>
0054 
0055 namespace Assimp {
0056 namespace Math {
0057 
0058 /// @brief  Will return the greatest common divisor.
0059 /// @param  a   [in] Value a.
0060 /// @param  b   [in] Value b.
0061 /// @return The greatest common divisor.
0062 template <typename IntegerType>
0063 inline IntegerType gcd( IntegerType a, IntegerType b ) {
0064     const IntegerType zero = (IntegerType)0;
0065     while ( true ) {
0066         if ( a == zero ) {
0067             return b;
0068         }
0069         b %= a;
0070 
0071         if ( b == zero ) {
0072             return a;
0073         }
0074         a %= b;
0075     }
0076 }
0077 
0078 /// @brief  Will return the greatest common divisor.
0079 /// @param  a   [in] Value a.
0080 /// @param  b   [in] Value b.
0081 /// @return The greatest common divisor.
0082 template < typename IntegerType >
0083 inline IntegerType lcm( IntegerType a, IntegerType b ) {
0084     const IntegerType t = gcd (a,b);
0085     if (!t) {
0086         return t;
0087     }
0088     return a / t * b;
0089 }
0090 /// @brief  Will return the smallest epsilon-value for the requested type.
0091 /// @return The numercical limit epsilon depending on its type.
0092 template<class T>
0093 inline T getEpsilon() {
0094     return std::numeric_limits<T>::epsilon();
0095 }
0096 
0097 /// @brief  Will return the constant PI for the requested type.
0098 /// @return Pi
0099 template<class T>
0100 inline T aiPi() {
0101     return static_cast<T>(3.14159265358979323846);
0102 }
0103 
0104 } // namespace Math
0105 } // namespace Assimp