TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
18 / 18
100.0%
Branches:
14 / 15
93.3%
Functions:
4 / 4
100.0%

distribution/golombek_rapp.cpp
Line Branch Exec Source
1 #include "terraingen/distribution/golombek_rapp.h"
2
3 #include "terraingen/util/checks.h"
4 #include "terraingen/util/special_functions.h"
5
6 #include <cmath>
7 #include <numbers>
8 #include <stdexcept>
9
10 namespace terraingen {
11
12 96475 GolombekRappSfd::GolombekRappSfd(double coverage, double qa, double qb, DiameterRange range)
13 96475 : SizeFrequencyDistribution(SfdKind::Density, range), coverage_(coverage) {
14
4/4
✓ Branch 0 taken 96474 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 96473 times.
96475 if (!(coverage_ > 0.0 && coverage_ < 1.0)) {
15
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Boulder coverage k must be between 0 and 1");
16 }
17
5/6
✓ Branch 1 taken 96471 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 96471 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 96471 times.
96473 if (!(IsNonNegative(qa) && IsNonNegative(qb))) {
18
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Golombek-Rapp qa and qb must be finite and not negative");
19 }
20 96471 q_ = qa + qb / coverage_;
21
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 96470 times.
96471 if (!(q_ > 0.0)) {
22
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Golombek-Rapp q must be positive");
23 }
24 96475 }
25
26 5649 double GolombekRappSfd::FractionalArea(double diameter) const {
27 5649 return coverage_ * std::exp(-q_ * diameter);
28 }
29
30 3915944 double GolombekRappSfd::CumulativeAt(double diameter) const {
31 3915944 return 4.0 * coverage_ * q_ / std::numbers::pi * ExponentialIntegral(2, q_ * diameter) /
32 3915944 diameter;
33 }
34
35 5044257 double GolombekRappSfd::IncrementalAt(double diameter) const {
36 5044257 return coverage_ * q_ * std::exp(-q_ * diameter) /
37 5044257 (std::numbers::pi * diameter * diameter / 4.0);
38 }
39
40 } // namespace terraingen
41