Coverage Report

Created: 2026-09-14 07:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/Geometry/GeometryUtils.cpp
Line
Count
Source
1
/*
2
Open Asset Import Library (assimp)
3
----------------------------------------------------------------------
4
5
Copyright (c) 2006-2026, assimp team
6
7
All rights reserved.
8
9
Redistribution and use of this software in source and binary forms,
10
with or without modification, are permitted provided that the
11
following conditions are met:
12
13
* Redistributions of source code must retain the above
14
  copyright notice, this list of conditions and the
15
  following disclaimer.
16
17
* Redistributions in binary form must reproduce the above
18
  copyright notice, this list of conditions and the
19
  following disclaimer in the documentation and/or other
20
  materials provided with the distribution.
21
22
* Neither the name of the assimp team, nor the names of its
23
  contributors may be used to endorse or promote products
24
  derived from this software without specific prior
25
  written permission of the assimp team.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39
----------------------------------------------------------------------
40
*/
41
42
#include "GeometryUtils.h"
43
44
#include <assimp/vector3.h>
45
46
namespace Assimp {
47
48
// ------------------------------------------------------------------------------------------------
49
76.5M
ai_real GeometryUtils::heron( ai_real a, ai_real b, ai_real c ) {
50
76.5M
    const ai_real s    = (a + b + c) * 0.5;
51
76.5M
    const ai_real area = pow((s * ( s - a ) * ( s - b ) * ( s - c ) ), static_cast<ai_real>(0.5));
52
76.5M
    return area;
53
76.5M
}
54
55
// ------------------------------------------------------------------------------------------------
56
229M
ai_real GeometryUtils::distance3D( const aiVector3D &vA, const aiVector3D &vB ) {
57
229M
    const ai_real lx = ( vB.x - vA.x );
58
229M
    const ai_real ly = ( vB.y - vA.y );
59
229M
    const ai_real lz = ( vB.z - vA.z );
60
229M
    const ai_real a  = lx*lx + ly*ly + lz*lz;
61
229M
    const ai_real d  = pow( a, static_cast<ai_real>(0.5));
62
63
229M
    return d;
64
229M
}
65
66
// ------------------------------------------------------------------------------------------------
67
76.5M
ai_real GeometryUtils::calculateAreaOfTriangle( const aiFace& face, aiMesh* mesh ) {
68
76.5M
    ai_real area = 0;
69
76.5M
    if (mesh == nullptr) {
70
0
        return area;
71
0
    }
72
73
76.5M
    const aiVector3D vA( mesh->mVertices[ face.mIndices[ 0 ] ] );
74
76.5M
    const aiVector3D vB( mesh->mVertices[ face.mIndices[ 1 ] ] );
75
76.5M
    const aiVector3D vC( mesh->mVertices[ face.mIndices[ 2 ] ] );
76
77
76.5M
    const ai_real a = distance3D( vA, vB );
78
76.5M
    const ai_real b = distance3D( vB, vC );
79
76.5M
    const ai_real c = distance3D( vC, vA );
80
76.5M
    area = heron( a, b, c );
81
82
76.5M
    return area;
83
76.5M
}
84
85
// ------------------------------------------------------------------------------------------------
86
// Check whether a ray intersects a plane and find the intersection point
87
0
bool GeometryUtils::PlaneIntersect(const aiRay& ray, const aiVector3D& planePos, const aiVector3D& planeNormal, aiVector3D& pos) {
88
0
    const ai_real b = planeNormal * (planePos - ray.pos);
89
0
    ai_real h = ray.dir * planeNormal;
90
0
    if ((h < 10e-5 && h > -10e-5) || (h = b/h) < 0)
91
0
        return false;
92
93
0
    pos = ray.pos + (ray.dir * h);
94
0
    return true;
95
0
}
96
97
// ------------------------------------------------------------------------------------------------
98
217
void GeometryUtils::normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, size_t numVectors) {
99
217
    if (vectorArrayIn == nullptr || vectorArrayOut == nullptr) {
100
0
        return;
101
0
    }
102
  
103
40.3k
    for (size_t i=0; i<numVectors; ++i) {
104
40.1k
  vectorArrayOut[i] = vectorArrayIn[i].Normalize();
105
40.1k
    }
106
217
}
107
108
} // namespace Assimp