TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
13 / 13
100.0%
Branches:
7 / 7
100.0%
Functions:
5 / 5
100.0%

distribution/power_law.cpp
Line Branch Exec Source
1 #include "terraingen/distribution/power_law.h"
2
3 #include "terraingen/util/checks.h"
4
5 #include <cmath>
6 #include <stdexcept>
7
8 namespace terraingen {
9
10 3235 PowerLawSfd::PowerLawSfd(double coefficient, double exponent, SfdKind kind, DiameterRange range)
11 3235 : SizeFrequencyDistribution(kind, range), law_{range.min, coefficient, exponent} {
12
6/6
✓ Branch 1 taken 3230 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 3229 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 3229 times.
3232 if (!IsPositive(coefficient) || !IsPositive(exponent)) {
13 throw std::invalid_argument(
14
1/1
✓ Branch 2 taken 3 times.
3 "Power law coefficient and exponent must be positive and finite");
15 }
16 3232 }
17
18 25445132 double PowerLawSfd::CumulativeAt(double diameter) const {
19 25445132 return law_.Cumulative(diameter);
20 }
21
22 2285065 double PowerLawSfd::IncrementalAt(double diameter) const {
23 2285065 return law_.Incremental(diameter);
24 }
25
26 1491318 double PowerLawSfd::InvertCumulative(double target, double /*dMin*/, double /*dMax*/) const {
27 1491318 return law_.Invert(target);
28 }
29
30 15 double PowerLawCoefficientFromKilometres(double coefficient, double exponent) {
31 15 return coefficient * std::pow(1000.0, exponent) / 1e6;
32 }
33
34 } // namespace terraingen
35