./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
4 / 4
100.0%
Branches:
1 / 1
100.0%
Functions:
-
-%

include/terraingen/layers/boulders/boulder_abundance.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief How abundant a `BoulderLayer`'s boulders are: density maps, patches, crater blocks and
5 /// the candidates thinning starts from.
6 #pragma once
7
8 #include "terraingen/distribution/size_frequency.h"
9 #include "terraingen/layers/boulders/boulder_options.h"
10
11 #include <memory>
12 #include <optional>
13 #include <vector>
14
15 namespace terraingen {
16
17 /// How a density map sets a boulder layer's abundance between craters: the abundance at which the
18 /// boulder sizes measure what the map does, once the crater blocks there are taken out of it for a
19 /// `total` map. With Golombek-Rapp sizes it solves for the coverage, as rock abundance maps give.
20 class BoulderMapAbundance {
21 public:
22 /// @throws std::invalid_argument for no map, an invalid one, or one measuring none of the
23 /// sizes.
24 /// @throws std::domain_error as `MapMeasure`.
25 explicit BoulderMapAbundance(const BoulderLayerOptions& options);
26
27 /// The abundance where the map reads `value` (`MapValueAt`) and the crater blocks hold `ejecta`
28 /// of their full abundance: 1 where `value` is NaN, 0 where the blocks make up the whole map.
29 double At(double value, double ejecta) const;
30
31 /// The largest abundance the map gives anywhere, at least 1.
32 13 double Max() const {
33
1/1
✓ Branch 1 taken 1 time.
13 return m_max;
34 }
35
36 private:
37 /// The coverage at which Golombek-Rapp boulders measure `target`.
38 double Coverage(double target) const;
39
40 DensityMap m_map;
41 double m_coverage = 0.0;
42 double m_measure = 0.0;
43 double m_ejectaMeasure = 0.0;
44 std::vector<double> m_coverages;
45 std::vector<double> m_measures;
46 double m_max = 1.0;
47 };
48
49 /// The mean over the plane of the patches' abundance, `spread` to the power of `PatchNoise`,
50 /// which is above 1 for a spread above 1; under a density map the patches are divided by it so
51 /// they keep the map's mean. 1 without patches.
52 double MeanPatchAbundance(const BoulderPatches& patches);
53
54 /// The models of a layer's abundance between craters, each built once from valid options.
55 745 struct BoulderBackground {
56 /// @throws std::invalid_argument as `BoulderMapAbundance` for an invalid density map.
57 explicit BoulderBackground(const BoulderLayerOptions& options);
58
59 double patchMean = 1.0; ///< Under a map, what the patches are divided by.
60 std::optional<BoulderMapAbundance> map; ///< The density map's abundance, when there is one.
61 /// The largest background abundance (`MaxBackgroundAbundance`).
62 double max = 1.0;
63 };
64
65 /// The largest background abundance, on the richest patches on bedrock: the patch spread, times
66 /// the bedrock abundance (at least 1) when bedrock is enabled.
67 double MaxBackgroundAbundance(const BoulderLayerOptions& options);
68
69 /// The sizes of the crater blocks at a fresh crater's rim: the ejecta distribution, or
70 /// Golombek-Rapp blocks of the ejecta coverage.
71 std::shared_ptr<const SizeFrequencyDistribution> EjectaSizes(const BoulderLayerOptions& options);
72
73 /// The distribution per m^2 candidate boulders are drawn from before thinning: the boulders
74 /// between craters at their richest, with a size slope map the power laws at its bounding
75 /// exponents too, plus fresh crater blocks when enabled.
76 /// @throws std::invalid_argument as `ValidateBoulderLayerOptions`, or without `generateRandom`,
77 /// when no candidates are drawn.
78 std::shared_ptr<const SizeFrequencyDistribution>
79 BoulderCandidates(const BoulderLayerOptions& options);
80
81 /// `BoulderCandidates` of options already checked, whose `MaxBackgroundAbundance` is `richest`.
82 std::shared_ptr<const SizeFrequencyDistribution>
83 BoulderCandidates(const BoulderLayerOptions& options, double richest);
84
85 } // namespace terraingen
86