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

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