./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
7 / 7
100.0%
Branches:
5 / 6
83.3%
Functions:
-
-%

include/terraingen/layers/boulders/ejecta_index.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief `EjectaIndex`, craters bucketed by the discs their ejecta reach.
5 #pragma once
6
7 #include "terraingen/geometry/surface.h"
8 #include "terraingen/layers/craters/band_buckets.h"
9 #include "terraingen/layers/craters/crater.h"
10
11 #include <cstdint>
12 #include <functional>
13 #include <memory>
14 #include <optional>
15 #include <vector>
16
17 namespace terraingen {
18
19 /// Craters bucketed by the discs their ejecta reach (`BandBuckets`, one band per power of two of
20 /// reach), so the craters able to reach a point are found without visiting all of them.
21 class EjectaIndex {
22 public:
23
1/1
✓ Branch 4 taken 1 time.
2868259 EjectaIndex() = default;
24
25 /// Indexes `craters`, each reaching `reach(crater)` meters from its center.
26 /// @param sources The layer each crater comes from, by index; empty for one layer.
27 EjectaIndex(CraterList craters, const Surface& surface,
28 const std::function<double(const Crater&)>& reach,
29 std::vector<std::uint32_t> sources = {});
30
31 /// The indexed craters.
32 49172 const CraterList& Craters() const {
33
1/1
✓ Branch 1 taken 49172 times.
49172 return m_craters;
34 }
35 /// The layer crater `n` comes from, by index.
36 49172 std::uint32_t Source(std::size_t n) const {
37
1/2
✓ Branch 0 taken 49172 times.
✗ Branch 1 not taken.
49172 return m_sources.empty() ? 0u : m_sources[n];
38 }
39 /// Whether no craters are indexed.
40 3767488 bool Empty() const {
41
2/2
✓ Branch 0 taken 22278 times.
✓ Branch 1 taken 3745209 times.
3767488 return m_craters.Empty();
42 }
43
44 /// The craters whose reach may hold (`x`, `y`), in ascending order; a superset of those
45 /// that do.
46 std::vector<std::uint32_t> Near(double x, double y) const;
47
48 private:
49 CraterList m_craters;
50 std::vector<std::uint32_t> m_sources;
51 std::shared_ptr<const Surface> m_surface; ///< Held so moved indexes keep their buckets valid.
52 std::optional<BandBuckets> m_buckets;
53 };
54
55 } // namespace terraingen
56