diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index 447055082..775ba44d2 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -357,9 +357,9 @@ void ColladaLoader::BuildLightsForNode(const ColladaParser &pParser, const Node out->mAngleInnerCone = AI_DEG_TO_RAD(srcLight->mFalloffAngle); // ... some extension magic. - if (srcLight->mOuterAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - 1e-6f)) { + if (srcLight->mOuterAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - ai_epsilon)) { // ... some deprecation magic. - if (srcLight->mPenumbraAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - 1e-6f)) { + if (srcLight->mPenumbraAngle >= ASSIMP_COLLADA_LIGHT_ANGLE_NOT_SET * (1 - ai_epsilon)) { // Need to rely on falloff_exponent. I don't know how to interpret it, so I need to guess .... // epsilon chosen to be 0.1 float f = 1.0f; @@ -1065,7 +1065,7 @@ void insertMorphTimeValue(std::vector &values, float time, floa return; } for (unsigned int i = 0; i < values.size(); i++) { - if (std::abs(time - values[i].mTime) < 1e-6f) { + if (std::abs(time - values[i].mTime) < ai_epsilon) { values[i].mKeys.push_back(k); return; } else if (time > values[i].mTime && time < values[i + 1].mTime) { diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index d7b7e0ef3..39db79a3e 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -653,7 +653,7 @@ bool FBXConverter::NeedsComplexTransformationChain(const Model &model) { const PropertyTable &props = model.Props(); bool ok; - const float zero_epsilon = 1e-6f; + const float zero_epsilon = ai_epsilon; const aiVector3D all_ones(1.0f, 1.0f, 1.0f); for (size_t i = 0; i < TransformationComp_MAXIMUM; ++i) { const TransformationComp comp = static_cast(i); diff --git a/code/AssetLib/IFC/IFCBoolean.cpp b/code/AssetLib/IFC/IFCBoolean.cpp index ee255e612..36912a7d8 100644 --- a/code/AssetLib/IFC/IFCBoolean.cpp +++ b/code/AssetLib/IFC/IFCBoolean.cpp @@ -66,12 +66,12 @@ bool IntersectSegmentPlane(const IfcVector3 &p, const IfcVector3 &n, const IfcVe // if segment ends on plane, do not report a hit. We stay on that side until a following segment starting at this // point leaves the plane through the other side - if (std::abs(dotOne + dotTwo) < 1e-6) + if (std::abs(dotOne + dotTwo) < ai_epsilon) return false; // if segment starts on the plane, report a hit only if the end lies on the *other* side - if (std::abs(dotTwo) < 1e-6) { - if ((assumeStartOnWhiteSide && dotOne + dotTwo < 1e-6) || (!assumeStartOnWhiteSide && dotOne + dotTwo > -1e-6)) { + if (std::abs(dotTwo) < ai_epsilon) { + if ((assumeStartOnWhiteSide && dotOne + dotTwo < ai_epsilon) || (!assumeStartOnWhiteSide && dotOne + dotTwo > -ai_epsilon)) { out = e0; return true; } else { @@ -81,7 +81,7 @@ bool IntersectSegmentPlane(const IfcVector3 &p, const IfcVector3 &n, const IfcVe // ignore if segment is parallel to plane and far away from it on either side // Warning: if there's a few thousand of such segments which slowly accumulate beyond the epsilon, no hit would be registered - if (std::abs(dotOne) < 1e-6) + if (std::abs(dotOne) < ai_epsilon) return false; // t must be in [0..1] if the intersection point is within the given segment @@ -163,7 +163,7 @@ void ProcessBooleanHalfSpaceDifference(const Schema_2x3::IfcHalfSpaceSolid *hs, for (iit = begin; iit != end; vidx += *iit++) { unsigned int newcount = 0; - bool isAtWhiteSide = (in[vidx] - p) * n > -1e-6; + bool isAtWhiteSide = (in[vidx] - p) * n > -ai_epsilon; for (unsigned int i = 0; i < *iit; ++i) { const IfcVector3 &e0 = in[vidx + i], e1 = in[vidx + (i + 1) % *iit]; @@ -259,7 +259,7 @@ bool IntersectsBoundaryProfile(const IfcVector3 &e0, const IfcVector3 &e1, const // segment-segment intersection // solve b0 + b*s = e0 + e*t for (s,t) const IfcFloat det = (-b.x * e.y + e.x * b.y); - if (std::abs(det) < 1e-6) { + if (std::abs(det) < ai_epsilon) { // no solutions (parallel lines) continue; } @@ -316,7 +316,7 @@ bool IntersectsBoundaryProfile(const IfcVector3 &e0, const IfcVector3 &e1, const // for a valid intersection, s and t should be in range [0,1]. Including a bit of epsilon on s, potential double // hits on two consecutive boundary segments are filtered - if (s >= -1e-6 * b_sqlen_inv && s <= 1.0 + 1e-6 * b_sqlen_inv && t >= 0.0 && (t <= 1.0 || halfOpen)) { + if (s >= -ai_epsilon * b_sqlen_inv && s <= 1.0 + ai_epsilon * b_sqlen_inv && t >= 0.0 && (t <= 1.0 || halfOpen)) { // only insert the point into the list if it is sufficiently far away from the previous intersection point. // This way, we avoid duplicate detection if the intersection is directly on the vertex between two segments. if (!intersect_results.empty() && intersect_results.back().first == i - 1) { @@ -431,14 +431,14 @@ void ProcessPolygonalBoundedBooleanHalfSpaceDifference(const Schema_2x3::IfcPoly // if the poly is parallel to the plane, put it completely on the black or white side if (std::abs(polyNormal * n) > 0.9999) { - bool isOnWhiteSide = (srcVertices[0] - p) * n > -1e-6; + bool isOnWhiteSide = (srcVertices[0] - p) * n > -ai_epsilon; std::vector &targetSide = isOnWhiteSide ? whiteside : blackside; targetSide.insert(targetSide.end(), srcVertices, srcVertices + srcVtxCount); } else { // otherwise start building one polygon for each side. Whenever the current line segment intersects the plane // we put a point there as an end of the current segment. Then we switch to the other side, put a point there, too, // as a beginning of the current segment, and simply continue accumulating vertices. - bool isCurrentlyOnWhiteSide = ((srcVertices[0]) - p) * n > -1e-6; + bool isCurrentlyOnWhiteSide = ((srcVertices[0]) - p) * n > -ai_epsilon; for (size_t a = 0; a < srcVtxCount; ++a) { IfcVector3 e0 = srcVertices[a]; IfcVector3 e1 = srcVertices[(a + 1) % srcVtxCount]; diff --git a/code/AssetLib/IFC/IFCGeometry.cpp b/code/AssetLib/IFC/IFCGeometry.cpp index 4c088955f..401ff9de6 100644 --- a/code/AssetLib/IFC/IFCGeometry.cpp +++ b/code/AssetLib/IFC/IFCGeometry.cpp @@ -380,21 +380,19 @@ void ProcessSweptDiskSolid(const Schema_2x3::IfcSweptDiskSolid &solid, TempMesh& bool take_any = false; for (unsigned int j = 0; j < 2; ++j, take_any = true) { - if ((last_dir == 0 || take_any) && std::abs(d.x) > 1e-6) { + if ((last_dir == 0 || take_any) && std::abs(d.x) > ai_epsilon) { q.y = startvec.y; q.z = startvec.z; q.x = -(d.y * q.y + d.z * q.z) / d.x; last_dir = 0; break; - } - else if ((last_dir == 1 || take_any) && std::abs(d.y) > 1e-6) { + } else if ((last_dir == 1 || take_any) && std::abs(d.y) > ai_epsilon) { q.x = startvec.x; q.z = startvec.z; q.y = -(d.x * q.x + d.z * q.z) / d.y; last_dir = 1; break; - } - else if ((last_dir == 2 && std::abs(d.z) > 1e-6) || take_any) { + } else if ((last_dir == 2 && std::abs(d.z) > ai_epsilon) || take_any) { q.y = startvec.y; q.x = startvec.x; q.z = -(d.y * q.y + d.x * q.x) / d.z; @@ -529,7 +527,7 @@ IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh& curmesh, bool& ok, IfcVect return m; } -const auto closeDistance = 1e-6; +constexpr auto closeDistance = ai_epsilon; bool areClose(Schema_2x3::IfcCartesianPoint pt1,Schema_2x3::IfcCartesianPoint pt2) { if(pt1.Coordinates.size() != pt2.Coordinates.size()) @@ -561,7 +559,7 @@ void ProcessExtrudedArea(const Schema_2x3::IfcExtrudedAreaSolid& solid, const Te // Outline: 'curve' is now a list of vertex points forming the underlying profile, extrude along the given axis, // forming new triangles. const bool has_area = solid.SweptArea->ProfileType == "AREA" && curve.mVerts.size() > 2; - if( solid.Depth < 1e-6 ) { + if (solid.Depth < ai_epsilon) { if( has_area ) { result.Append(curve); } diff --git a/code/AssetLib/IFC/IFCOpenings.cpp b/code/AssetLib/IFC/IFCOpenings.cpp index c261a24b0..46cccd02c 100644 --- a/code/AssetLib/IFC/IFCOpenings.cpp +++ b/code/AssetLib/IFC/IFCOpenings.cpp @@ -1133,7 +1133,7 @@ IfcMatrix4 ProjectOntoPlane(std::vector& out_contour, const TempMesh } for(size_t i = 0; i < out_contour.size(); ++i) { - ai_assert((out_contour[i]-out_contour2[i]).SquareLength() < 1e-6); + ai_assert((out_contour[i] - out_contour2[i]).SquareLength() < ai_epsilon); } #endif @@ -1435,7 +1435,7 @@ std::vector GetContourInPlane2D(std::shared_ptr mesh,IfcMa const auto outernor = ((mesh->mVerts[2] - mesh->mVerts[0]) ^ (mesh->mVerts[1] - mesh->mVerts[0])).Normalize(); const IfcFloat dot = planeNor * outernor; - if(std::fabs(dot) < 1.f - 1e-6f) { + if (std::fabs(dot) < 1.f - ai_epsilon) { std::stringstream msg; msg << "Skipping: Unaligned opening (" << planeNor.x << ", " << planeNor.y << ", " << planeNor.z << ")"; msg << " . ( " << outernor.x << ", " << outernor.y << ", " << outernor.z << ") = " << dot; @@ -1476,7 +1476,7 @@ std::vector GetContourInPlane2D(std::shared_ptr mesh,IfcMa return contour; } -const float close { 1e-6f }; +constexpr float close{ ai_epsilon }; static bool isClose(IfcVector2 first,IfcVector2 second) { auto diff = (second - first); diff --git a/code/AssetLib/IFC/IFCUtil.cpp b/code/AssetLib/IFC/IFCUtil.cpp index 2ff0d6a58..6b378c1da 100644 --- a/code/AssetLib/IFC/IFCUtil.cpp +++ b/code/AssetLib/IFC/IFCUtil.cpp @@ -228,25 +228,24 @@ void TempMesh::ComputePolygonNormals(std::vector& normals, // ------------------------------------------------------------------------------------------------ // Compute the normal of the last polygon in the given mesh -IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const -{ +IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const { return ComputePolygonNormal(&mVerts[mVerts.size() - mVertcnt.back()], mVertcnt.back(), normalize); } -struct CompareVector -{ - bool operator () (const IfcVector3& a, const IfcVector3& b) const - { +struct CompareVector { + bool operator () (const IfcVector3& a, const IfcVector3& b) const { IfcVector3 d = a - b; - IfcFloat eps = 1e-6; + IfcFloat eps = ai_epsilon; return d.x < -eps || (std::abs(d.x) < eps && d.y < -eps) || (std::abs(d.x) < eps && std::abs(d.y) < eps && d.z < -eps); } }; -struct FindVector -{ + +struct FindVector { IfcVector3 v; FindVector(const IfcVector3& p) : v(p) { } - bool operator () (const IfcVector3& p) { return FuzzyVectorCompare(1e-6)(p, v); } + bool operator()(const IfcVector3 &p) { + return FuzzyVectorCompare(ai_epsilon)(p, v); + } }; // ------------------------------------------------------------------------------------------------ @@ -357,8 +356,7 @@ void TempMesh::FixupFaceOrientation() // to reverse the neighbour nb_vidx = (nb_vidx + 1) % nbvc; size_t oursideidx = (a + 1) % vc; - if( FuzzyVectorCompare(1e-6)(mVerts[vsi + oursideidx], mVerts[nbvsi + nb_vidx]) ) - { + if (FuzzyVectorCompare(ai_epsilon)(mVerts[vsi + oursideidx], mVerts[nbvsi + nb_vidx])) { std::reverse(mVerts.begin() + nbvsi, mVerts.begin() + nbvsi + nbvc); std::reverse(neighbour.begin() + nbvsi, neighbour.begin() + nbvsi + nbvc); for (size_t aa = 0; aa < nbvc - 1; ++aa) { @@ -564,7 +562,7 @@ void ConvertDirection(IfcVector3& out, const Schema_2x3::IfcDirection& in) out[static_cast(i)] = in.DirectionRatios[i]; } const IfcFloat len = out.Length(); - if (len<1e-6) { + if (len < ai_epsilon) { IFCImporter::LogWarn("direction vector magnitude too small, normalization would result in a division by zero"); return; } diff --git a/code/PostProcessing/FindDegenerates.cpp b/code/PostProcessing/FindDegenerates.cpp index de46d5630..0bbf421d2 100644 --- a/code/PostProcessing/FindDegenerates.cpp +++ b/code/PostProcessing/FindDegenerates.cpp @@ -221,7 +221,7 @@ bool FindDegeneratesProcess::ExecuteOnMesh( aiMesh* mesh) { if ( mConfigCheckAreaOfTriangle ) { if ( face.mNumIndices == 3 ) { ai_real area = calculateAreaOfTriangle( face, mesh ); - if ( area < 1e-6 ) { + if (area < ai_epsilon) { if ( mConfigRemoveDegenerates ) { remove_me[ a ] = true; ++deg; diff --git a/include/assimp/matrix3x3.h b/include/assimp/matrix3x3.h index 5ae31bbeb..74382e263 100644 --- a/include/assimp/matrix3x3.h +++ b/include/assimp/matrix3x3.h @@ -95,7 +95,7 @@ public: bool operator== (const aiMatrix3x3t& m) const; bool operator!= (const aiMatrix3x3t& m) const; - bool Equal(const aiMatrix3x3t& m, TReal epsilon = 1e-6) const; + bool Equal(const aiMatrix3x3t &m, TReal epsilon = ai_epsilon) const; template operator aiMatrix3x3t () const; diff --git a/include/assimp/matrix4x4.h b/include/assimp/matrix4x4.h index 07abf4711..67e0e356e 100644 --- a/include/assimp/matrix4x4.h +++ b/include/assimp/matrix4x4.h @@ -110,7 +110,7 @@ public: bool operator== (const aiMatrix4x4t& m) const; bool operator!= (const aiMatrix4x4t& m) const; - bool Equal(const aiMatrix4x4t& m, TReal epsilon = 1e-6) const; + bool Equal(const aiMatrix4x4t &m, TReal epsilon = ai_epsilon) const; // matrix multiplication. aiMatrix4x4t& operator *= (const aiMatrix4x4t& m); diff --git a/include/assimp/quaternion.h b/include/assimp/quaternion.h index aa92ea577..b6d0a5681 100644 --- a/include/assimp/quaternion.h +++ b/include/assimp/quaternion.h @@ -92,7 +92,7 @@ public: // transform vector by matrix aiQuaterniont& operator *= (const aiMatrix4x4t& mat); - bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const; + bool Equal(const aiQuaterniont &o, TReal epsilon = ai_epsilon) const; public: diff --git a/include/assimp/vector2.h b/include/assimp/vector2.h index 333c094d4..f06e9441d 100644 --- a/include/assimp/vector2.h +++ b/include/assimp/vector2.h @@ -85,7 +85,7 @@ public: bool operator== (const aiVector2t& other) const; bool operator!= (const aiVector2t& other) const; - bool Equal(const aiVector2t& other, TReal epsilon = 1e-6) const; + bool Equal(const aiVector2t &other, TReal epsilon = ai_epsilon) const; aiVector2t& operator= (TReal f); const aiVector2t SymMul(const aiVector2t& o); diff --git a/include/assimp/vector3.h b/include/assimp/vector3.h index c191e1ee7..a886def1d 100644 --- a/include/assimp/vector3.h +++ b/include/assimp/vector3.h @@ -114,7 +114,7 @@ public: bool operator < (const aiVector3t& other) const; /// @brief - bool Equal(const aiVector3t& other, TReal epsilon = 1e-6) const; + bool Equal(const aiVector3t &other, TReal epsilon = ai_epsilon) const; template operator aiVector3t () const; diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 84f940c66..00f76aa47 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -573,7 +573,7 @@ TEST_F(utglTF2ImportExport, export_normalized_normals) { scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals_out.glb", aiProcess_ValidateDataStructure); for ( auto i = 0u; i < scene->mMeshes[0]->mNumVertices; ++i ) { const auto length = scene->mMeshes[0]->mNormals[i].Length(); - EXPECT_TRUE(abs(length) < 1e-6 || abs(length - 1) < 1e-6); + EXPECT_TRUE(abs(length) < 1e-6 || abs(length - 1) < ai_epsilon); } }