./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
19 / 19
100.0%
Branches:
10 / 10
100.0%
Functions:
5 / 5
100.0%

src/distribution/summed.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/distribution/summed.h"
4
5 #include "distribution/composition.h"
6 #include "util/checks.h"
7
8 #include <utility>
9
10 namespace terraingen {
11
12 namespace {
13
14 /// The kind of `terms`, after checking them.
15 447 SfdKind CheckedKind(const std::vector<WeightedSfd>& terms) {
16
2/2
✓ Branch 2 taken 447 times.
✓ Branch 6 taken 444 times.
450 const SfdKind kind = detail::CommonKind(detail::Distributions(terms), "A summed distribution");
17
2/2
✓ Branch 0 taken 524 times.
✓ Branch 1 taken 443 times.
967 for (const WeightedSfd& term : terms) {
18 524 RequirePositive(term.weight, "Summed distribution weights");
19 }
20 443 return kind;
21 }
22
23 } // namespace
24
25 447 SummedSfd::SummedSfd(std::vector<WeightedSfd> terms)
26 447 : SummedSfd(CheckedKind(terms), std::move(terms)) {}
27
28 443 SummedSfd::SummedSfd(SfdKind kind, std::vector<WeightedSfd>&& terms)
29 : SizeFrequencyDistribution(
30 kind, detail::IntersectRanges(terms, detail::UsableRange,
31 "Summed terms must have overlapping valid ranges")),
32
2/2
✓ Branch 2 taken 442 times.
✓ Branch 5 taken 442 times.
885 m_terms(std::move(terms)) {}
33
34 11096829 double SummedSfd::CumulativeAt(double diameter) const {
35 11096829 double sum = 0.0;
36
2/2
✓ Branch 0 taken 13667343 times.
✓ Branch 1 taken 11096832 times.
24764175 for (const WeightedSfd& term : m_terms) {
37 13667343 sum += term.weight * UncheckedCumulative(*term.distribution, diameter);
38 }
39 11096832 return sum;
40 }
41
42 711409 double SummedSfd::IncrementalAt(double diameter) const {
43 711409 double sum = 0.0;
44
2/2
✓ Branch 0 taken 880505 times.
✓ Branch 1 taken 711409 times.
1591914 for (const WeightedSfd& term : m_terms) {
45 880505 sum += term.weight * UncheckedIncremental(*term.distribution, diameter);
46 }
47 711409 return sum;
48 }
49
50 } // namespace terraingen
51