./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
25 / 25
100.0%
Branches:
22 / 23
95.7%
Functions:
4 / 4
100.0%

src/layers/craters/degradation/degradation_model.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/layers/craters/degradation/degradation_model.h"
4
5 #include "terraingen/layers/craters/profiles/martin_parkes_dunstan.h"
6 #include "util/checks.h"
7
8 #include <cmath>
9 #include <stdexcept>
10 #include <utility>
11
12 namespace terraingen {
13
14 6 CraterState DegradationModel::WornState(const Crater& crater, double rate) const {
15 6 Crater older = crater;
16 6 older.ageGyr *= rate;
17 6 return State(older);
18 }
19
20 1043 std::shared_ptr<const CraterProfile> MatchedProfile(std::shared_ptr<const CraterProfile> profile,
21 const DegradationModel& degradation) {
22 1043 std::shared_ptr<const CraterProfile> required = degradation.RequiredProfile();
23
6/6
✓ Branch 0 taken 1029 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 169 times.
✓ Branch 3 taken 860 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 165 times.
1043 if (profile && required && profile != required) {
24 4 throw std::invalid_argument(
25
1/1
✓ Branch 2 taken 4 times.
4 "The degradation shapes craters with its own profile; pass that profile or none");
26 }
27
2/2
✓ Branch 0 taken 1025 times.
✓ Branch 1 taken 14 times.
1039 if (profile) {
28 1025 return profile;
29 }
30
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
32 return required ? required : std::make_shared<MartinParkesDunstanProfile>();
31 1039 }
32 2531 NoDegradation::NoDegradation(FreshMorphometry fresh, std::optional<double> depthRatio)
33
2/2
✓ Branch 0 taken 2530 times.
✓ Branch 1 taken 1 time.
2531 : m_fresh(std::move(fresh)), m_depthRatio(depthRatio) {
34
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2530 times.
2531 if (!m_fresh) {
35
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("No degradation needs the fresh crater morphometry");
36 }
37
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 2472 times.
2530 if (m_depthRatio) {
38
1/1
✓ Branch 1 taken 56 times.
58 RequirePositive(*m_depthRatio, "Depth/diameter ratio");
39 }
40 2531 }
41
42 31307 CraterState NoDegradation::State(const Crater& crater) const {
43 31307 CraterMorphometry fresh = m_fresh(crater.diameter);
44
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 31089 times.
31306 if (m_depthRatio) {
45 217 fresh.depthRatio = *m_depthRatio;
46 }
47 31306 return {fresh, fresh};
48 }
49
50 } // namespace terraingen
51