From 25cda401c52b47475ab64c30687b08dc398c492c Mon Sep 17 00:00:00 2001 From: Eshed Date: Sat, 15 Oct 2016 03:29:45 +0300 Subject: [PATCH] use cmath and C++ (std::) versions of functions --- code/AssxmlExporter.cpp | 4 ++-- code/BlenderLoader.cpp | 2 +- code/ColladaLoader.cpp | 8 ++++---- code/FixNormalsStep.cpp | 6 +++--- code/LWOAnimation.cpp | 2 +- code/LWOMaterial.cpp | 2 +- code/SIBImporter.cpp | 4 ++-- code/X3DImporter.cpp | 2 +- code/X3DImporter_Geometry2D.cpp | 2 +- code/XGLLoader.cpp | 2 +- include/assimp/matrix4x4.inl | 18 +++++++++--------- include/assimp/types.h | 1 - 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/code/AssxmlExporter.cpp b/code/AssxmlExporter.cpp index 5bd174cce..e236df664 100644 --- a/code/AssxmlExporter.cpp +++ b/code/AssxmlExporter.cpp @@ -299,7 +299,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened) { else if (!shortened){ ioprintf(io,"\t\t \n",tex->mWidth*tex->mHeight*4); - // const unsigned int width = (unsigned int)log10((double)std::max(tex->mHeight,tex->mWidth))+1; + // const unsigned int width = (unsigned int)std::log10((double)std::max(tex->mHeight,tex->mWidth))+1; for (unsigned int y = 0; y < tex->mHeight;++y) { for (unsigned int x = 0; x < tex->mWidth;++x) { aiTexel* tx = tex->pcData + y*tex->mWidth+x; @@ -457,7 +457,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened) { ioprintf(io,"\n",scene->mNumMeshes); for (unsigned int i = 0; i < scene->mNumMeshes;++i) { aiMesh* mesh = scene->mMeshes[i]; - // const unsigned int width = (unsigned int)log10((double)mesh->mNumVertices)+1; + // const unsigned int width = (unsigned int)std::log10((double)mesh->mNumVertices)+1; // mesh header ioprintf(io,"\t\n", diff --git a/code/BlenderLoader.cpp b/code/BlenderLoader.cpp index 7bf9fde25..68388235f 100644 --- a/code/BlenderLoader.cpp +++ b/code/BlenderLoader.cpp @@ -1143,7 +1143,7 @@ aiCamera* BlenderImporter::ConvertCamera(const Scene& /*in*/, const Object* obj, out->mUp = aiVector3D(0.f, 1.f, 0.f); out->mLookAt = aiVector3D(0.f, 0.f, -1.f); if (cam->sensor_x && cam->lens) { - out->mHorizontalFOV = atan2(cam->sensor_x, 2.f * cam->lens); + out->mHorizontalFOV = std::atan2(cam->sensor_x, 2.f * cam->lens); } out->mClipPlaneNear = cam->clipsta; out->mClipPlaneFar = cam->clipend; diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 04fcfd507..4f463f2ec 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -420,13 +420,13 @@ void ColladaLoader::BuildCamerasForNode( const ColladaParser& pParser, const Col out->mHorizontalFOV = srcCamera->mHorFov; if (srcCamera->mVerFov != 10e10f && srcCamera->mAspect == 10e10f) { - out->mAspect = tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) / - tan(AI_DEG_TO_RAD(srcCamera->mVerFov)); + out->mAspect = std::tan(AI_DEG_TO_RAD(srcCamera->mHorFov)) / + std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov)); } } else if (srcCamera->mAspect != 10e10f && srcCamera->mVerFov != 10e10f) { - out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(atan(srcCamera->mAspect * - tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f))); + out->mHorizontalFOV = 2.0f * AI_RAD_TO_DEG(std::atan(srcCamera->mAspect * + std::tan(AI_DEG_TO_RAD(srcCamera->mVerFov) * 0.5f))); } // Collada uses degrees, we use radians diff --git a/code/FixNormalsStep.cpp b/code/FixNormalsStep.cpp index 9249b13e9..0325f8dfb 100644 --- a/code/FixNormalsStep.cpp +++ b/code/FixNormalsStep.cpp @@ -148,9 +148,9 @@ bool FixInfacingNormalsProcess::ProcessMesh( aiMesh* pcMesh, unsigned int index) // Check whether this is a planar surface const float fDelta1_yz = fDelta1_y * fDelta1_z; - if (fDelta1_x < 0.05f * sqrtf( fDelta1_yz ))return false; - if (fDelta1_y < 0.05f * sqrtf( fDelta1_z * fDelta1_x ))return false; - if (fDelta1_z < 0.05f * sqrtf( fDelta1_y * fDelta1_x ))return false; + if (fDelta1_x < 0.05f * std::sqrt( fDelta1_yz ))return false; + if (fDelta1_y < 0.05f * std::sqrt( fDelta1_z * fDelta1_x ))return false; + if (fDelta1_z < 0.05f * std::sqrt( fDelta1_y * fDelta1_x ))return false; // now compare the volumes of the bounding boxes if (std::fabs(fDelta0_x * fDelta0_y * fDelta0_z) < diff --git a/code/LWOAnimation.cpp b/code/LWOAnimation.cpp index 9f23c13b2..f41853dad 100644 --- a/code/LWOAnimation.cpp +++ b/code/LWOAnimation.cpp @@ -160,7 +160,7 @@ void AnimResolver::UpdateAnimRangeSetup() case LWO::PrePostBehaviour_Repeat: case LWO::PrePostBehaviour_Oscillate: { - const double start_time = delta - fmod(my_first-first,delta); + const double start_time = delta - std::fmod(my_first-first,delta); std::vector::iterator n = std::find_if((*it).keys.begin(),(*it).keys.end(), std::bind1st(std::greater(),start_time)),m; diff --git a/code/LWOMaterial.cpp b/code/LWOMaterial.cpp index 494f70033..961b16686 100644 --- a/code/LWOMaterial.cpp +++ b/code/LWOMaterial.cpp @@ -851,7 +851,7 @@ void LWOImporter::LoadLWO2Surface(unsigned int size) case AI_LWO_SMAN: { AI_LWO_VALIDATE_CHUNK_LENGTH(head.length,SMAN,4); - surf.mMaximumSmoothAngle = fabs( GetF4() ); + surf.mMaximumSmoothAngle = std::fabs( GetF4() ); break; } // vertex color channel to be applied to the surface diff --git a/code/SIBImporter.cpp b/code/SIBImporter.cpp index 8dfacc106..75a7ccf8e 100644 --- a/code/SIBImporter.cpp +++ b/code/SIBImporter.cpp @@ -710,8 +710,8 @@ static void ReadLightInfo(aiLight* light, StreamReaderLE* stream) // OpenGL: I = cos(angle)^E // Solving: angle = acos(I^(1/E)) ai_real E = 1.0 / std::max(spotExponent, (ai_real)0.00001); - ai_real inner = acos(pow((ai_real)0.99, E)); - ai_real outer = acos(pow((ai_real)0.01, E)); + ai_real inner = std::acos(std::pow((ai_real)0.99, E)); + ai_real outer = std::acos(std::pow((ai_real)0.01, E)); // Apply the cutoff. outer = std::min(outer, AI_DEG_TO_RAD(spotCutoff)); diff --git a/code/X3DImporter.cpp b/code/X3DImporter.cpp index 024eedb28..a14d87d80 100644 --- a/code/X3DImporter.cpp +++ b/code/X3DImporter.cpp @@ -796,7 +796,7 @@ void X3DImporter::GeometryHelper_Make_Arc2D(const float pStartAngle, const float } // calculate arc angle and check type of arc - float angle_full = fabs(pEndAngle - pStartAngle); + float angle_full = std::fabs(pEndAngle - pStartAngle); if ( ( angle_full > AI_MATH_TWO_PI_F ) || ( angle_full == 0.0f ) ) { angle_full = AI_MATH_TWO_PI_F; diff --git a/code/X3DImporter_Geometry2D.cpp b/code/X3DImporter_Geometry2D.cpp index 453313297..bfa1834ec 100644 --- a/code/X3DImporter_Geometry2D.cpp +++ b/code/X3DImporter_Geometry2D.cpp @@ -157,7 +157,7 @@ void X3DImporter::ParseNode_Geometry2D_ArcClose2D() // create point list of geometry object. GeometryHelper_Make_Arc2D(startAngle, endAngle, radius, 10, ((CX3DImporter_NodeElement_Geometry2D*)ne)->Vertices);///TODO: IME - AI_CONFIG for NumSeg // add chord or two radiuses only if not a circle was defined - if(!((fabs(endAngle - startAngle) >= AI_MATH_TWO_PI_F) || (endAngle == startAngle))) + if(!((std::fabs(endAngle - startAngle) >= AI_MATH_TWO_PI_F) || (endAngle == startAngle))) { std::list& vlist = ((CX3DImporter_NodeElement_Geometry2D*)ne)->Vertices;// just short alias. diff --git a/code/XGLLoader.cpp b/code/XGLLoader.cpp index 2df72849b..30f520097 100644 --- a/code/XGLLoader.cpp +++ b/code/XGLLoader.cpp @@ -501,7 +501,7 @@ aiMatrix4x4 XGLImporter::ReadTrafo() up.Normalize(); right = forward ^ up; - if (fabs(up * forward) > 1e-4) { + if (std::fabs(up * forward) > 1e-4) { // this is definitely wrong - a degenerate coordinate space ruins everything // so subtitute identity transform. LogError(" and vectors in are skewing, ignoring trafo"); diff --git a/include/assimp/matrix4x4.inl b/include/assimp/matrix4x4.inl index 2f579906e..a7977cd2c 100644 --- a/include/assimp/matrix4x4.inl +++ b/include/assimp/matrix4x4.inl @@ -367,21 +367,21 @@ inline void aiMatrix4x4t::Decompose(aiVector3t& pScaling, aiVector // Use a small epsilon to solve floating-point inaccuracies const TReal epsilon = 10e-3f; - pRotation.y = asin(vCols[2].x);// D. Angle around oY. + pRotation.y = std::asin(vCols[2].x);// D. Angle around oY. - TReal C = cos(pRotation.y); + TReal C = std::cos(pRotation.y); - if(fabs(C) > epsilon) + if(std::fabs(C) > epsilon) { // Finding angle around oX. TReal tan_x = vCols[2].z / C;// A TReal tan_y = -vCols[2].y / C;// B - pRotation.x = atan2(tan_y, tan_x); + pRotation.x = std::atan2(tan_y, tan_x); // Finding angle around oZ. tan_x = vCols[0].x / C;// E tan_y = -vCols[1].x / C;// F - pRotation.z = atan2(tan_y, tan_x); + pRotation.z = std::atan2(tan_y, tan_x); } else {// oY is fixed. @@ -391,7 +391,7 @@ inline void aiMatrix4x4t::Decompose(aiVector3t& pScaling, aiVector TReal tan_x = vCols[1].y;// -BDF+AE => E TReal tan_y = vCols[0].y;// BDE+AF => F - pRotation.z = atan2(tan_y, tan_x); + pRotation.z = std::atan2(tan_y, tan_x); } } @@ -407,14 +407,14 @@ aiQuaterniont pRotation; pRotation.Normalize(); TReal angle_cos = pRotation.w; - TReal angle_sin = sqrt(1.0f - angle_cos * angle_cos); + TReal angle_sin = std::sqrt(1.0f - angle_cos * angle_cos); - pRotationAngle = acos(angle_cos) * 2; + pRotationAngle = std::acos(angle_cos) * 2; // Use a small epsilon to solve floating-point inaccuracies const TReal epsilon = 10e-3f; - if(fabs(angle_sin) < epsilon) angle_sin = 1; + if(std::fabs(angle_sin) < epsilon) angle_sin = 1; pRotationAxis.x = pRotation.x / angle_sin; pRotationAxis.y = pRotation.y / angle_sin; diff --git a/include/assimp/types.h b/include/assimp/types.h index 465638675..0b48453c6 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Some runtime headers #include -#include #include #include #include