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

include/terraingen/distribution/summed.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Weighted sums of size-frequency distributions.
5 #pragma once
6
7 #include "terraingen/distribution/size_frequency.h"
8
9 #include <memory>
10 #include <vector>
11
12 namespace terraingen {
13
14 /// One term of a `SummedSfd`: `distribution` scaled by `weight`.
15
18/45
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 3 taken 138 times.
✗ Branch 4 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 5 taken 127 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 time.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 9 taken 8 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 time.
✓ Branch 12 taken 8 times.
✓ Branch 12 taken 1 time.
✗ Branch 13 not taken.
✓ Branch 14 taken 297 times.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 60 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
2199 struct WeightedSfd {
16 double weight = 1.0; ///< Positive, finite factor.
17 std::shared_ptr<const SizeFrequencyDistribution> distribution; ///< The scaled distribution.
18 };
19
20 /// The sum of weighted distributions of one kind, N(>=D) = sum of weight * N_i(>=D), such
21 /// as boulders between craters plus the blocks thrown out by them.
22 ///
23 /// It is valid where every term is: the intersection of their valid ranges, with a term that allows
24 /// extrapolation counting as valid everywhere.
25
1/2
✓ Branch 13 taken 1 time.
✗ Branch 14 not taken.
442 class SummedSfd final : public SizeFrequencyDistribution {
26 public:
27 /// The sum of `terms`, all of one kind.
28 /// @throws std::invalid_argument for no terms, a null term, mixed kinds, a weight that is not
29 /// positive and finite, or terms whose valid ranges do not overlap.
30 explicit SummedSfd(std::vector<WeightedSfd> terms);
31
32 /// The weighted terms of the sum.
33 1 const std::vector<WeightedSfd>& Terms() const {
34 1 return m_terms;
35 }
36
37 protected:
38 double CumulativeAt(double diameter) const override;
39 double IncrementalAt(double diameter) const override;
40
41 private:
42 /// The sum of `terms`, already checked to share `kind`.
43 SummedSfd(SfdKind kind, std::vector<WeightedSfd>&& terms);
44
45 std::vector<WeightedSfd> m_terms;
46 };
47
48 } // namespace terraingen
49