GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
39 / 40
97.5%
Branches:
48 / 90
53.3%
Functions:
10 / 10
100.0%

scene/schema/planet.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file planet.cpp
3 /// @brief The planetary prims' registry entries and extents: terrains from their heights and
4 /// bodies, atmospheres from their bodies and tops.
5 #include "ernie/scene/schema/planet.h"
6
7 #include <algorithm>
8 #include <optional>
9 #include <vector>
10
11 namespace ernie {
12 namespace {
13
14 /// @return The lowest and highest of a host array's heights; none on a device or when empty.
15 2 std::optional<std::pair<double, double>> HeightRange(const Tensor& heights) {
16
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (heights.Empty() || !heights.OnHost()) {
17 ✗ return std::nullopt;
18 }
19 2 const std::vector<float> values = CopyFloats(heights, "heights");
20 2 const auto [low, high] = std::ranges::minmax_element(values);
21 2 return std::pair<double, double>(*low, *high);
22 2 }
23
24 /// A plane's footprint: x east from the origin, y south from it, a cell between heights.
25 1 Box PlaneFootprint(const Tensor& heights, glm::dvec2 origin, double cell, double low, double high) {
26 1 const double rows = static_cast<double>(heights.Shape()[0]);
27 1 const double columns = static_cast<double>(heights.Shape()[1]);
28 1 return {{origin.x, origin.y - (rows - 1.0) * cell, low},
29 1 {origin.x + (columns - 1.0) * cell, origin.y, high}};
30 }
31
32 2 void TerrainExtent(const ExtentRows& rows, RowRange range, std::span<Box> out) {
33 2 const auto heights = rows.Column<Tensor>(Terrain::kHeights);
34 2 const auto origin = rows.Column<glm::dvec2>(Terrain::kOrigin);
35 2 const auto cell = rows.Column<double>(Terrain::kCellSize);
36 2 const auto exaggeration = rows.Column<double>(Terrain::kExaggeration);
37 2 const auto authored = rows.Column<std::vector<float>>(Boundable::kExtent);
38 2 const auto bodies = rows.Column<Target>(Terrain::kBody);
39 2 ComputeRows(range, out, [&](std::uint32_t row) {
40 2 const std::optional<std::pair<double, double>> span = HeightRange(heights[row]);
41
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 const double low = span ? span->first * exaggeration[row] : 0.0;
42
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 const double high = span ? span->second * exaggeration[row] : 0.0;
43
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
2 if (const std::optional<Box> body = rows.TargetExtent(bodies[row], row)) {
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 return body->Grown(std::max(high, 0.0));
45 }
46
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 return span && heights[row].Rank() == 2
47
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
2 ? PlaneFootprint(heights[row], origin[row], cell[row], low, high)
48 1 : AuthoredExtent(authored[row]);
49 });
50 2 }
51
52 4 void AtmosphereExtent(const ExtentRows& rows, RowRange range, std::span<Box> out) {
53 4 const auto top = rows.Column<double>(Atmosphere::kTop);
54 4 const auto bodies = rows.Column<Target>(Atmosphere::kBody);
55 4 ComputeRows(range, out, [&](std::uint32_t row) {
56 4 const std::optional<Box> body = rows.TargetExtent(bodies[row], row);
57
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
4 return body ? body->Grown(top[row]) : Box();
58 });
59 4 }
60
61 } // namespace
62
63
12/26
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 146 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 146 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 146 times.
✗ Branch 17 not taken.
✓ Branch 26 taken 146 times.
✗ Branch 27 not taken.
✓ Branch 29 taken 146 times.
✗ Branch 30 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 146 times.
✓ Branch 38 taken 1898 times.
✓ Branch 39 taken 146 times.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
3946 ERNIE_DEFINE_SCHEMA(Terrain, Concrete, ComputedFromOtherPrims(TerrainExtent),
64 ERNIE_TERRAIN_ATTRIBUTES)
65
10/20
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 146 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 146 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 146 times.
✗ Branch 16 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 146 times.
✓ Branch 31 taken 1606 times.
✓ Branch 32 taken 146 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
3364 ERNIE_DEFINE_SCHEMA(Atmosphere, Concrete, ComputedFromOtherPrims(AtmosphereExtent),
66 ERNIE_ATMOSPHERE_ATTRIBUTES)
67
7/12
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 146 times.
✓ Branch 21 taken 1168 times.
✓ Branch 22 taken 146 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
2485 ERNIE_DEFINE_SCHEMA(StarField, Concrete, kInheritExtent, ERNIE_STAR_FIELD_ATTRIBUTES)
68
7/12
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 126 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 146 times.
✓ Branch 17 taken 584 times.
✓ Branch 18 taken 146 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
1440 ERNIE_DEFINE_SCHEMA(GroundPlane, Concrete, kUnbounded, ERNIE_GROUND_PLANE_ATTRIBUTES)
69
70 } // namespace ernie
71