./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
21 / 21
100.0%
Branches:
16 / 18
88.9%
Functions:
3 / 3
100.0%

src/layers/boulders/ejecta_index.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/boulders/ejecta_index.h"
4
5 #include <algorithm>
6 #include <cmath>
7 #include <utility>
8
9 namespace terraingen {
10
11 namespace {
12
13 /// The shortest reach (m) bucketed apart, below which craters share the finest band.
14 constexpr double kFinestReach = 1e-3;
15
16 } // namespace
17
18 1065 EjectaIndex::EjectaIndex(CraterList craters, const Surface& surface,
19 const std::function<double(const Crater&)>& reach,
20 1065 std::vector<std::uint32_t> sources)
21
1/1
✓ Branch 2 taken 1065 times.
1065 : m_craters(std::move(craters)), m_sources(std::move(sources)),
22 1065 m_surface(std::make_shared<const Surface>(surface)) {
23 1065 m_buckets.emplace(*m_surface);
24
2/2
✓ Branch 0 taken 7695 times.
✓ Branch 1 taken 1065 times.
8760 for (std::size_t n = 0; n < m_craters.Size(); ++n) {
25
1/1
✓ Branch 1 taken 7695 times.
7695 const Crater crater = m_craters.At(n);
26 7695 const int band =
27
1/1
✓ Branch 1 taken 7695 times.
7695 static_cast<int>(std::ceil(std::log2(std::fmax(reach(crater), kFinestReach))));
28
1/1
✓ Branch 1 taken 7695 times.
7695 m_buckets->Add(band, std::ldexp(1.0, band), {crater.x, crater.y}, n);
29 }
30
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1065 }
31
32 28119 std::vector<std::uint32_t> EjectaIndex::Near(double x, double y) const {
33
2/2
✓ Branch 0 taken 28118 times.
✓ Branch 1 taken 1 time.
28119 std::vector<std::uint32_t> near;
34
2/2
✓ Branch 0 taken 28118 times.
✓ Branch 1 taken 1 time.
28119 if (!m_buckets) {
35 return near;
36 }
37
3/3
✓ Branch 1 taken 28118 times.
✓ Branch 3 taken 66064 times.
✓ Branch 4 taken 28118 times.
94182 for (const int band : m_buckets->Bands()) {
38
1/1
✓ Branch 1 taken 66064 times.
66064 m_buckets->ForEachAround(band, {x, y}, 1, [&](const std::vector<std::size_t>& indices) {
39
2/2
✓ Branch 0 taken 210353 times.
✓ Branch 1 taken 87600 times.
297953 for (const std::size_t n : indices) {
40 210353 near.push_back(static_cast<std::uint32_t>(n));
41 }
42 87600 });
43 28118 }
44 28118 std::sort(near.begin(), near.end());
45 return near;
46 }
47
48 } // namespace terraingen
49