diff options
| author | Kim Kulling <kimkulling@users.noreply.github.com> | 2025-06-26 00:09:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-26 00:09:02 +0200 |
| commit | d99f9bd2f73ea7fc30dae9863494d27559c05111 (patch) | |
| tree | a9c6bad4fd5380c4f2b887261e9b2ab9829a6a8d /code/Geometry/GeometryUtils.cpp | |
| parent | b2afe717d3640ac0379e3d50aeac9c81c4692281 (diff) | |
Refactoring: Add nupptr-checks (#6241)
Diffstat (limited to 'code/Geometry/GeometryUtils.cpp')
| -rw-r--r-- | code/Geometry/GeometryUtils.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/code/Geometry/GeometryUtils.cpp b/code/Geometry/GeometryUtils.cpp index 77a731e63..80197604a 100644 --- a/code/Geometry/GeometryUtils.cpp +++ b/code/Geometry/GeometryUtils.cpp @@ -47,8 +47,8 @@ namespace Assimp { // ------------------------------------------------------------------------------------------------ ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) { - const ai_real s = (a + b + c) / 2; - const ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), (ai_real)0.5 ); + const ai_real s = (a + b + c) * 0.5; + const ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), static_cast<ai_real>(0.5)); return area; } @@ -57,8 +57,8 @@ ai_real GeometryUtils::distance3D( const aiVector3D &vA, const aiVector3D &vB ) const ai_real lx = ( vB.x - vA.x ); const ai_real ly = ( vB.y - vA.y ); const ai_real lz = ( vB.z - vA.z ); - const ai_real a = lx*lx + ly*ly + lz*lz; - const ai_real d = pow( a, (ai_real)0.5 ); + const ai_real a = lx*lx + ly*ly + lz*lz; + const ai_real d = pow( a, static_cast<ai_real>(0.5)); return d; } @@ -66,6 +66,9 @@ ai_real GeometryUtils::distance3D( const aiVector3D &vA, const aiVector3D &vB ) // ------------------------------------------------------------------------------------------------ ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) { ai_real area = 0; + if (mesh == nullptr) { + return area; + } const aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] ); const aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] ); @@ -81,8 +84,7 @@ ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh // ------------------------------------------------------------------------------------------------ // Check whether a ray intersects a plane and find the intersection point -bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, - const aiVector3D& planeNormal, aiVector3D& pos) { +bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, const aiVector3D& planeNormal, aiVector3D& pos) { const ai_real b = planeNormal * (planePos - ray.pos); ai_real h = ray.dir * planeNormal; if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0) @@ -93,11 +95,14 @@ bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, } // ------------------------------------------------------------------------------------------------ -void GeometryUtils::normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, - size_t numVectors) { +void GeometryUtils::normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, size_t numVectors) { + if (vectorArrayIn == nullptr || vectorArrayOut == nullptr) { + return; + } + for (size_t i=0; i<numVectors; ++i) { - vectorArrayOut[i] = vectorArrayIn[i].Normalize(); - } + vectorArrayOut[i] = vectorArrayIn[i].Normalize(); + } } } // namespace Assimp |
