./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
100 / 100
100.0%
Branches:
73 / 79
92.4%
Functions:
13 / 13, 4 excl
100.0%

include/terraingen/geometry/radial_shape.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief `RadialShape`, a star-shaped body's radius along each direction from its center.
5 #pragma once
6
7 #include "terraingen/geometry/geometry.h"
8
9 #include <cstddef>
10 #include <functional>
11 #include <vector>
12
13 namespace terraingen {
14
15 /// The index of ICQ label (`i`, `j`, `face`) of a grid of `q` intervals per face edge, `face` from
16 /// 1 to 6: ICQ file order, face, then J, then I.
17 232303136 constexpr std::size_t IcqLabelIndex(std::size_t q, std::size_t i, std::size_t j, std::size_t face) {
18
5/5
✓ Branch 0 taken 402654 times.
✓ Branch 1 taken 1 time.
✓ Branch 1 taken 2013282 times.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
230669318 return ((face - 1) * (q + 1) + j) * (q + 1) + i;
19 }
20
21 /// Calls `visit(i, j, face, index)` for every label of a grid of `q` intervals per face edge, in
22 /// ICQ file order (`IcqLabelIndex`).
23 258 template <typename Visit> void ForEachIcqLabel(std::size_t q, const Visit& visit) {
24
14/14
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachIcqLabel<ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
void terraingen::ForEachIcqLabel<terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 20 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 681 times.
✓ Branch 1 taken 113 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 98 times.
void terraingen::ForEachIcqLabel<terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 9 times.
void terraingen::ForEachIcqLabel<terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 13 times.
1790 for (std::size_t face = 1; face <= 6; ++face) {
25
14/14
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 6 times.
void terraingen::ForEachIcqLabel<ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 6 times.
void terraingen::ForEachIcqLabel<terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 6708 times.
✓ Branch 1 taken 120 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 23893 times.
✓ Branch 1 taken 680 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 22706 times.
✓ Branch 1 taken 588 times.
void terraingen::ForEachIcqLabel<terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 726 times.
✓ Branch 1 taken 54 times.
void terraingen::ForEachIcqLabel<terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 966 times.
✓ Branch 1 taken 78 times.
56603 for (std::size_t j = 0; j <= q; ++j) {
26
14/14
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
void terraingen::ForEachIcqLabel<ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 486 times.
✓ Branch 1 taken 54 times.
void terraingen::ForEachIcqLabel<terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::BodyIcq(terraingen::Terrain const&, unsigned long, double, unsigned int)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 802776 times.
✓ Branch 1 taken 6708 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::CheckSharedLabels() const::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 1075993 times.
✓ Branch 1 taken 23892 times.
void terraingen::ForEachIcqLabel<terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::RadialShape::Sample(unsigned long, std::function<double (terraingen::Vec3d const&)> const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 1056494 times.
✓ Branch 1 taken 22704 times.
void terraingen::ForEachIcqLabel<terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToIcq(terraingen::RadialShape const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 10422 times.
✓ Branch 1 taken 726 times.
void terraingen::ForEachIcqLabel<terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, terraingen::ToRadialShape(terraingen::IcqModel const&)::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 12894 times.
✓ Branch 1 taken 966 times.
3014187 for (std::size_t i = 0; i <= q; ++i) {
27 2959119 visit(i, j, face, IcqLabelIndex(q, i, j, face));
28 }
29 }
30 }
31 255 }
32
33 /// The radius of a star-shaped body along each direction: the radius at every label of Gaskell's
34 /// ICQ grid (`LabelDirection`), interpolated bilinearly in equiangular coordinates within each
35 /// quadrilateral, so it is continuous and stays within the range of the label radii.
36
3/4
✓ Branch 6 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✓ Branch 10 taken 1 time.
183 class RadialShape {
37 public:
38 /// The shape of `q` intervals per face edge from a radius in meters along each unit direction,
39 /// evaluated at every label.
40 /// @throws std::invalid_argument for a `q` of 0, or a radius that is not positive and finite.
41 static RadialShape Sample(std::size_t q, const std::function<double(const Vec3d&)>& radius);
42
43 /// The shape of `q` intervals per face edge from 6 (q + 1)^2 label radii in meters, in ICQ
44 /// file order (`LabelIndex`).
45 /// @throws std::invalid_argument for a `q` of 0, the wrong count, a radius that is not
46 /// positive and finite, or labels shared between faces with different radii.
47 RadialShape(std::size_t q, std::vector<double> radii);
48
49 /// The unit direction of label (`i`, `j`, `face`) of a grid of `q` intervals per edge, at
50 /// equiangular coordinates with Gaskell's face orientation: on face 1 (+z) I runs along +x and
51 /// J along -y; on faces 2 to 5 (-y, -x, +y, +x) J runs along -z; on face 6 (-z) I runs along +x
52 /// and J along +y. Labels the format shares between faces get the same direction exactly.
53 /// @throws std::invalid_argument unless `q` > 0, `i` and `j` <= `q` and 1 <= `face` <= 6.
54 static Vec3d LabelDirection(std::size_t q, std::size_t i, std::size_t j, std::size_t face);
55
56 /// The index of label (`i`, `j`, `face`) in the label radii (`IcqLabelIndex`).
57 225312760 std::size_t LabelIndex(std::size_t i, std::size_t j, std::size_t face) const {
58 18554009 return IcqLabelIndex(m_q, i, j, face);
59 }
60
61 /// The radius in meters along a nonzero `direction`.
62 double At(const Vec3d& direction) const;
63
64 /// Q, the intervals per face edge.
65 98399 std::size_t Q() const {
66
9/9
<unknown function 17>:
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 1 time.
<unknown function 36>:
✓ Branch 1 taken 1 time.
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
void terraingen::ForEachIcqLabel<ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, ShapeModelSource_IsZeroAtEveryLabel_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 1 time.
98369 return m_q;
67 }
68
69 /// The label radii in meters, in the order of `LabelIndex`.
70 8 const std::vector<double>& Radii() const {
71
3/3
<unknown function 17>:
✓ Branch 1 taken 9 times.
<unknown function 36>:
✓ Branch 1 taken 1 time.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 1 time.
14448928 return m_radii;
72 }
73
74 /// The smallest label radius in meters, a lower bound of `At`.
75 601265 double MinRadius() const {
76
3/3
<unknown function 36>:
✓ Branch 1 taken 1 time.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 2000 times.
✓ Branch 4 taken 1 time.
601265 return m_min;
77 }
78
79 /// The largest label radius in meters, an upper bound of `At`.
80 40296 double MaxRadius() const {
81
4/7
<unknown function 36>:
✓ Branch 1 taken 1 time.
<unknown function 75>:
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 2000 times.
✓ Branch 4 taken 1 time.
40296 return m_max;
82 }
83
84 /// An upper bound in m^2 of the area per steradian, r^2 / (u . n), over the interpolated
85 /// surface: its largest value at any quadrilateral's corner with the quadrilateral's mean
86 /// normal (from the cross product of its diagonals), times a margin for the variation within
87 /// quadrilaterals.
88 5115 double MaxAreaPerSteradian() const {
89
2/2
<unknown function 36>:
✓ Branch 1 taken 96 times.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 1 taken 5000 times.
5115 return m_maxArea;
90 }
91
92 /// Whether two shapes have the same Q and label radii.
93 4 bool operator==(const RadialShape& other) const {
94
2/4
terraingen::RadialShape::MaxAreaPerSteradian() const:
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
void terraingen::ForEachIcqLabel<IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1}>(unsigned long, IcqLabels_AreIndexedAndVisitedInFileOrder_Test::TestBody()::{lambda(unsigned long, unsigned long, unsigned long, unsigned long)#1} const&):
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
4 return m_q == other.m_q && m_radii == other.m_radii;
95 }
96 bool operator!=(const RadialShape& other) const {
97 return !(*this == other);
98 }
99
100 private:
101 /// Checks that labels shared between faces have equal radii.
102 void CheckSharedLabels() const;
103 /// The largest area per steradian at any quadrilateral's corner, before the margin.
104 double CornerAreaBound() const;
105 /// The largest area per steradian at the corners of quadrilateral (`i`, `j`) of `face`.
106 double QuadAreaBound(std::size_t i, std::size_t j, std::size_t face) const;
107
108 std::size_t m_q = 0;
109 std::vector<double> m_radii;
110 double m_min = 0.0;
111 double m_max = 0.0;
112 double m_maxArea = 0.0;
113 };
114
115 } // namespace terraingen
116