TerrainGen coverage


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

distribution/spliced.h
Line Branch Exec Source
1 /// @file
2 /// @brief Size-frequency distributions spliced from others over consecutive diameter intervals.
3 #pragma once
4
5 #include "terraingen/distribution/size_frequency.h"
6
7 #include <cstddef>
8 #include <memory>
9 #include <vector>
10
11 namespace terraingen {
12
13 /// One piece of a `SplicedSfd`: `distribution` applies from `start` metres up to the next
14 /// piece's start.
15 struct SfdPiece {
16 double start = 0.0; ///< First diameter, metres.
17 std::shared_ptr<const SizeFrequencyDistribution> distribution; ///< Applies from `start`.
18 };
19
20 /// A cumulative distribution made of other distributions over consecutive diameter
21 /// intervals, such as a production function extended below its fitted range by a power law.
22 ///
23 /// As in `PiecewisePowerLawSfd`, the lower piece applies at a join, and pieces must meet there
24 /// within a relative tolerance.
25 class SplicedSfd final : public SizeFrequencyDistribution {
26 public:
27 /// The distribution spliced from `pieces`.
28 /// @param pieces At least one piece, with strictly increasing `start`, the first `start` equal
29 /// to `range.min`, and each distribution valid (or extrapolating) over its interval.
30 /// @param range The valid range, in metres.
31 /// @param tolerance Relative mismatch allowed at a join.
32 /// @throws std::invalid_argument for malformed pieces, mixed kinds, a piece not valid over its
33 /// interval, or a join that rises or is discontinuous by more than `tolerance`.
34 SplicedSfd(std::vector<SfdPiece> pieces, DiameterRange range, double tolerance = 1e-3);
35
36 /// The pieces in increasing `start` order.
37 2 const std::vector<SfdPiece>& Pieces() const {
38 2 return pieces_;
39 }
40
41 protected:
42 double CumulativeAt(double diameter) const override;
43 double IncrementalAt(double diameter) const override;
44 double InvertCumulative(double target, double dMin, double dMax) const override;
45
46 private:
47 std::size_t PieceAt(double diameter) const;
48
49 std::vector<SfdPiece> pieces_;
50 };
51
52 } // namespace terraingen
53