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

src/layers/craters/degradation/freshness_degradation.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/craters/degradation/freshness_degradation.h"
4
5 #include <cmath>
6 #include <stdexcept>
7 #include <utility>
8
9 namespace terraingen {
10
11 1169 FreshnessDegradation::FreshnessDegradation(std::shared_ptr<const CraterAgeModel> ages,
12 1169 FreshMorphometry fresh, double cutoffDepthRatio)
13
2/2
✓ Branch 0 taken 1168 times.
✓ Branch 1 taken 1 time.
1169 : m_ages(std::move(ages)), m_fresh(std::move(fresh)), m_cutoffDepthRatio(cutoffDepthRatio) {
14
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1168 times.
1169 if (!m_ages) {
15
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Freshness degradation needs an age model");
16 }
17
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1167 times.
1168 if (!m_fresh) {
18
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Freshness degradation needs the fresh crater morphometry");
19 }
20
4/4
✓ Branch 0 taken 1166 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1164 times.
1167 if (!(m_cutoffDepthRatio > 0.0 && m_cutoffDepthRatio < 0.1)) {
21
1/1
✓ Branch 2 taken 3 times.
3 throw std::invalid_argument("Cutoff depth/diameter ratio must be in (0, 0.1)");
22 }
23
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 time.
1169 }
24
25 18761 CraterState FreshnessDegradation::State(const Crater& crater) const {
26 18761 const CraterMorphometry fresh = m_fresh(crater.diameter);
27 18762 const double floor = std::fmin(m_cutoffDepthRatio / fresh.depthRatio, 1.0);
28 18762 const double erosion =
29 18762 floor + (1.0 - floor) * m_ages->RemainingLifetime(crater.diameter, crater.ageGyr);
30 18761 return {fresh, {erosion * fresh.depthRatio, erosion * fresh.rimHeightRatio}};
31 }
32
33 } // namespace terraingen
34