./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
23 / 23
100.0%
Branches:
20 / 52
38.5%
Functions:
2 / 2, 5 excl
100.0%

include/terraingen/layers/craters/profiles/complex.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief `ComplexCraterProfile`: flat floors, concave walls and central peaks; `CraterTerraces`
5 /// steps the walls into slump terraces.
6 #pragma once
7
8 #include "terraingen/layers/craters/profiles/profile.h"
9
10 #include <memory>
11 #include <optional>
12
13 namespace terraingen {
14
15 /// y = `coefficient` * D^`exponent` with D and y in kilometers (km^3 for volumes), as
16 /// morphometric relations are published.
17 1 struct KilometerPowerLaw {
18 double coefficient = 0.0; ///< y of a 1 km crater, in km (or km^3).
19 double exponent = 0.0; ///< Power of the diameter.
20
21 /// y in meters (m^3 with `volume`) for a crater of `diameter` meters: `KilometerLaw` in single
22 /// precision.
23 double At(double diameter, bool volume = false) const;
24
25 /// Memberwise equality.
26 1 bool operator==(const KilometerPowerLaw& other) const {
27
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
1 return coefficient == other.coefficient && exponent == other.exponent;
28 }
29 bool operator!=(const KilometerPowerLaw& other) const {
30 return !(*this == other);
31 }
32 };
33
34 /// The flat floor and central peak of complex craters on a body, from the diameter they start
35 /// at; depth and rim height come from the crater's state.
36 1 struct ComplexCraterShape {
37 double transitionDiameter = 0.0; ///< Smallest complex crater (m).
38 KilometerPowerLaw floorDiameter; ///< Diameter of the flat floor.
39 KilometerPowerLaw peakHeight; ///< Height of the central peak above the floor.
40 KilometerPowerLaw peakVolume; ///< Volume of the central peak (km^3), with no `peakDiameter`.
41 /// Diameter of the central peak's base, when known; otherwise the base follows from the peak's
42 /// height and `peakVolume`.
43 std::optional<KilometerPowerLaw> peakDiameter;
44 /// Largest crater the peak relations were fitted to (m); larger craters keep this size's peak
45 /// height and a base in proportion to the diameter; unset applies the laws to every size.
46 std::optional<double> peakFitMaxDiameter{};
47 double ejectaExponent = 3.0; ///< The exterior falls off as (r / R)^-exponent.
48 double reachRadii = 3.0; ///< Radii from the center where the exterior reaches zero.
49
50 /// Memberwise equality.
51 bool operator==(const ComplexCraterShape& other) const {
52 return transitionDiameter == other.transitionDiameter &&
53 floorDiameter == other.floorDiameter && peakHeight == other.peakHeight &&
54 peakVolume == other.peakVolume && peakDiameter == other.peakDiameter &&
55 peakFitMaxDiameter == other.peakFitMaxDiameter &&
56 ejectaExponent == other.ejectaExponent && reachRadii == other.reachRadii;
57 }
58 bool operator!=(const ComplexCraterShape& other) const {
59 return !(*this == other);
60 }
61 };
62
63 /// Checks a complex crater shape.
64 /// @throws std::invalid_argument for a non-positive transition diameter, a power law with a
65 /// non-positive coefficient, a negative peak fit limit, a non-positive ejecta exponent, or a reach
66 /// of at most 1 radius.
67 void ValidateComplexCraterShape(const ComplexCraterShape& shape);
68
69 /// Sets the complex form of `shape` on kernel profile `p`, as `ComplexProfileHeight` reads it.
70 void SetKernelComplexShape(CraterProfileKernel& p, const ComplexCraterShape& shape);
71
72 /// Simple craters below a transition diameter, complex ones from it: a flat floor, a concave
73 /// wall, a central peak lowered as the crater wears, and a power-law exterior.
74
10/36
<unknown function 17>:
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
<unknown function 26>:
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
<unknown function 74>:
✓ Branch 0 taken 1 time.
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 time.
✗ Branch 15 not taken.
✓ Branch 15 taken 1 time.
✗ Branch 16 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
65 class ComplexCraterProfile final : public CraterProfile {
75 public:
76 /// @param simple The profile of simple craters.
77 /// @throws std::invalid_argument for a null `simple` or an invalid `shape`.
78 ComplexCraterProfile(std::shared_ptr<const CraterProfile> simple, ComplexCraterShape shape);
79
80 /// The simple profile below the transition, else `ComplexProfileHeight` in single precision.
81 double Height(double distance, double diameter, const CraterState& state) const override;
82
83 /// The larger of the simple profile's reach and `reachRadii`.
84 double ReachRadii() const override;
85
86 /// True from `transitionDiameter`.
87 8771775 bool IsComplex(double diameter) const override {
88
8/12
<unknown function 26>:
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
<unknown function 74>:
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
<unknown function 87>:
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 5 times.
terraingen::ComplexCraterProfile::IsComplex(double) const:
✓ Branch 0 taken 2882767 times.
✓ Branch 1 taken 3007580 times.
5890436 return diameter >= m_shape.transitionDiameter;
89 }
90
91 /// The shape the profile was made with.
92 31216 const ComplexCraterShape& Shape() const {
93 31216 return m_shape;
94 }
95
96 /// The profile of simple craters.
97 31295 const CraterProfile& Simple() const {
98 31295 return *m_simple;
99 }
100
101 private:
102 std::shared_ptr<const CraterProfile> m_simple;
103 ComplexCraterShape m_shape;
104 CraterProfileKernel m_kernel;
105 };
106
107 } // namespace terraingen
108