./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
22 / 22
100.0%
Branches:
18 / 21
85.7%
Functions:
2 / 2
100.0%

src/layers/craters/rays.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/craters/rays.h"
4
5 #include "terraingen/geometry/geometry.h"
6 #include "terraingen/layers/craters/crater_fields.h"
7 #include "terraingen/random/stream.h"
8
9 #include <algorithm>
10 #include <cmath>
11 #include <stdexcept>
12
13 namespace terraingen {
14
15 67 void ValidateRayLayout(const RayLayout& layout) {
16 67 CheckRanges(layout);
17 67 ValidateValueDistribution(layout.count);
18 67 ValidateValueDistribution(layout.widthDegrees);
19
4/4
✓ Branch 1 taken 66 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 65 times.
67 if (layout.count.Lowest() < 0.0 || layout.count.Highest() > 64.0) {
20
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Craters must have 0 to 64 rays");
21 }
22
3/4
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 62 times.
✓ Branch 5 taken 3 times.
65 if (!(layout.widthDegrees.Lowest() > 0.0 && layout.widthDegrees.Highest() < 180.0)) {
23
1/1
✓ Branch 2 taken 3 times.
3 throw std::invalid_argument("Ray widths must be in (0, 180) degrees");
24 }
25 62 }
26
27 1767 std::vector<RayDirection> RayDirections(const Crater& crater, const RayLayout& layout) {
28 1767 const IdWords id = SplitId(crater.id);
29 1767 RandomStream random(layout.seed, kCraterRayStream, id.low, id.high);
30 1767 const auto count = static_cast<int>(std::lround(layout.count.Draw(random)));
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1767 times.
1767 std::vector<RayDirection> rays;
32
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1767 times.
✓ Branch 3 taken 1767 times.
1767 rays.reserve(static_cast<std::size_t>(std::max(count, 0)));
33
2/2
✓ Branch 0 taken 17220 times.
✓ Branch 1 taken 1767 times.
18987 for (int i = 0; i < count; ++i) {
34 17220 RayDirection ray;
35
1/1
✓ Branch 1 taken 17220 times.
17220 ray.azimuth = 2.0 * kPi * random.NextDouble();
36
1/1
✓ Branch 1 taken 17220 times.
17220 ray.sinHalfWidth = std::sin(0.5 * layout.widthDegrees.Draw(random) * kDegree);
37
1/1
✓ Branch 1 taken 17220 times.
17220 ray.key = random.NextU32();
38
1/1
✓ Branch 1 taken 17220 times.
17220 rays.push_back(ray);
39 }
40 1767 return rays;
41 }
42
43 } // namespace terraingen
44