TerrainGen coverage


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

layers/craters/degradation/freshness.cpp
Line Branch Exec Source
1 #include "terraingen/layers/craters/degradation/freshness.h"
2
3 #include <cmath>
4 #include <stdexcept>
5 #include <utility>
6
7 namespace terraingen {
8
9 816 FreshnessDegradation::FreshnessDegradation(std::shared_ptr<const CraterAgeModel> ages,
10 816 FreshMorphometry fresh, double cutoffDepthRatio)
11 816 : ages_(std::move(ages)), fresh_(std::move(fresh)), cutoffDepthRatio_(cutoffDepthRatio) {
12
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 815 times.
816 if (!ages_) {
13
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Freshness degradation needs an age model");
14 }
15
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 814 times.
815 if (!fresh_) {
16
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Freshness degradation needs the fresh crater morphometry");
17 }
18
4/4
✓ Branch 0 taken 813 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 810 times.
814 if (!(cutoffDepthRatio_ > 0.0 && cutoffDepthRatio_ < 0.1)) {
19
1/1
✓ Branch 2 taken 4 times.
4 throw std::invalid_argument("Cutoff depth/diameter ratio must be in (0, 0.1)");
20 }
21 828 }
22
23 485976 CraterState FreshnessDegradation::State(const Crater& crater) const {
24
1/1
✓ Branch 1 taken 485976 times.
485976 const CraterMorphometry fresh = fresh_(crater.diameter);
25 485976 const double floor = std::fmin(cutoffDepthRatio_ / fresh.depthRatio, 1.0);
26 const double erosion =
27
1/1
✓ Branch 2 taken 485976 times.
485976 floor + (1.0 - floor) * ages_->RemainingLifetime(crater.diameter, crater.ageGyr);
28 485976 return {fresh, {erosion * fresh.depthRatio, erosion * fresh.rimHeightRatio}};
29 }
30
31 } // namespace terraingen
32