GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
21 / 21
100.0%
Branches:
24 / 30
80.0%
Functions:
1 / 1
100.0%

geometry/triangulation.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file triangulation.cpp
3 /// @brief Fan triangulation of USD polygons.
4 #include "ernie/geometry/triangulation.h"
5
6 #include <algorithm>
7 #include <stdexcept>
8
9 namespace ernie {
10
11 14 std::vector<std::uint32_t> TriangulateFaces(std::span<const std::int64_t> faceVertexCounts,
12 std::span<const std::int64_t> faceVertexIndices,
13 std::size_t points) {
14 14 std::vector<std::uint32_t> triangles;
15 14 std::size_t next = 0;
16
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 10 times.
27 for (const std::int64_t count : faceVertexCounts) {
17
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 16 times.
17 if (count < 3) {
18
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 throw std::invalid_argument("Every face needs at least 3 vertices");
19 }
20 16 const auto size = static_cast<std::size_t>(count);
21
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 15 times.
16 if (next + size > faceVertexIndices.size()) {
22
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 throw std::invalid_argument("faceVertexCounts add up to more than faceVertexIndices");
23 }
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 const std::span<const std::int64_t> face = faceVertexIndices.subspan(next, size);
25
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 13 times.
15 if (std::ranges::any_of(face, [&](std::int64_t index) {
26
4/4
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 1 time.
52 return index < 0 || static_cast<std::size_t>(index) >= points;
27 })) {
28
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 throw std::invalid_argument("faceVertexIndices has an index out of range");
29 }
30
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 13 times.
34 for (std::size_t k = 1; k + 1 < size; ++k) {
31
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 21 times.
84 for (const std::int64_t corner : {face[0], face[k], face[k + 1]}) {
32
1/2
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
63 triangles.push_back(static_cast<std::uint32_t>(corner));
33 }
34 }
35 13 next += size;
36 }
37
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 9 times.
10 if (next != faceVertexIndices.size()) {
38
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 throw std::invalid_argument("faceVertexCounts add up to fewer than faceVertexIndices");
39 }
40 9 return triangles;
41 5 }
42
43 } // namespace ernie
44