TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
6 / 6
100.0%
Branches:
3 / 6
50.0%
Functions:
2 / 2, 1 excl
100.0%

distribution/piecewise_uniform.h
Line Branch Exec Source
1 /// @file
2 /// @brief Size-frequency distributions made of bands with diameters spread uniformly.
3 #pragma once
4
5 #include "terraingen/distribution/size_frequency.h"
6
7 #include <vector>
8
9 namespace terraingen {
10
11 /// One band of a piecewise uniform distribution: `density` features with diameters spread
12 /// uniformly over [`min`, `max`) metres.
13 struct UniformBand {
14 4 double min = 1.0; ///< Smallest diameter, metres; positive.
15 4 double max = 2.0; ///< Largest diameter, metres; above `min`.
16 4 double density = 0.01; ///< Features per m^2 (or per m^2 per Gyr), or a relative weight; >= 0.
17
18
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 bool operator==(const UniformBand&) const = default;
19 };
20
21 /// A distribution made of diameter bands, each holding a number of features per m^2 with
22 /// diameters uniform across it, for scenes that set counts by size class instead of following a
23 /// power law.
24 ///
25 /// N(>=D) falls linearly across each band and is flat between bands; overlapping bands add. No
26 /// features are smaller than the smallest band or larger than the largest, so the valid range is
27 /// every diameter up to the largest band's `max`, and extrapolation beyond it, where N(>=D) is 0,
28 /// is allowed from the start.
29 class PiecewiseUniformSfd final : public SizeFrequencyDistribution {
30 public:
31 /// The distribution of `bands`.
32 /// @param total When positive, the features per m^2 (or per m^2 per Gyr) of all bands
33 /// together, shared in proportion to each band's `density`; 0 takes the densities as given.
34 /// @throws std::invalid_argument for no bands, a band whose diameters are not positive and
35 /// finite with `max` above `min`, a negative or non-finite density or total, or no features.
36 PiecewiseUniformSfd(std::vector<UniformBand> bands, SfdKind kind = SfdKind::Density,
37 double total = 0.0);
38
39 /// The bands, with densities per m^2 (or per m^2 per Gyr) after any `total` is applied.
40 7 const std::vector<UniformBand>& Bands() const {
41 7 return bands_;
42 }
43
44 protected:
45 double CumulativeAt(double diameter) const override;
46 double IncrementalAt(double diameter) const override;
47 double InvertCumulative(double target, double dMin, double dMax) const override;
48
49 private:
50 std::vector<UniformBand> bands_;
51 std::vector<double> edges_;
52 std::vector<double> edgeCumulative_;
53 };
54
55 } // namespace terraingen
56