./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
6 / 6
100.0%
Branches:
14 / 25
56.0%
Functions:
1 / 1, 1 excl
100.0%

include/terraingen/layers/craters/shaping/slope.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 /// @file
4 /// @brief Craters formed on slopes: floors offset downslope and raised rims lowered upslope.
5 #pragma once
6
7 #include "terraingen/geometry/geometry.h"
8 #include "terraingen/layers/craters/crater.h"
9 #include "terraingen/random/value_distribution.h"
10
11 #include <cstdint>
12 #include <optional>
13
14 namespace terraingen {
15
16 /// How craters formed on a slope become asymmetric along it and wear faster, after Plescia et al.
17 /// (2019, https://www.hou.usra.edu/meetings/lpsc2019/pdf/2984.pdf); needs the `Plane` datum.
18
7/11
✓ Branch 4 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 18 taken 1 time.
✗ Branch 34 not taken.
✓ Branch 35 taken 1 time.
✗ Branch 37 not taken.
✓ Branch 38 taken 1 time.
✗ Branch 40 not taken.
✓ Branch 41 taken 1 time.
✗ Branch 45 not taken.
✓ Branch 46 taken 1 time.
324057 struct CraterSlopeResponse {
19 /// Shapes craters asymmetrically along the slope; off keeps their shape on any slope. The wear
20 /// that `criticalGradient` gives applies either way.
21 bool asymmetric = false;
22 /// Varies the floor offsets; unset follows the crater layer's `seed`, and is 0 outside a layer.
23 std::optional<std::uint32_t> seed{};
24 /// How far the deepest point lies downslope of the center, in diameters, drawn per crater;
25 /// below 0.23. The default is digitized from Plescia et al. (2019, Fig. 3).
26 ValueDistribution floorOffset{ValueDistribution::Kind::Uniform, 0.045, 0.194};
27 /// Share of the raised rim and ejecta kept straight upslope, in [0, 1]; the rest returns as
28 /// the squared cosine of the angle from upslope falls, all of it across the slope and
29 /// downslope.
30 double upslopeRim = 0.0;
31 /// Slope (degrees) at which the asymmetry is complete, rising from none on level ground along
32 /// a smoothstep; 5 degrees, the "few degrees" of Plescia et al. (2019).
33 double fullSlopeDegrees = 5.0;
34 /// The critical gradient Sc (rise over run): a crater on a regional gradient S wears
35 /// 1 / (1 - (S / Sc)^2) times as fast (Roering et al. 1999,
36 /// https://doi.org/10.1029/1998WR900090); unset wears craters alike on any slope. Applies
37 /// whether or not the craters are `asymmetric`.
38 std::optional<double> criticalGradient{};
39 /// The fastest a slope makes craters wear, over level ground; at least 1. It caps the rate as
40 /// S nears Sc, where the form grows without bound; a numerical limit, not a measured one.
41 double maxWearRate = 10.0;
42
43 /// Memberwise equality.
44 4 bool operator==(const CraterSlopeResponse& other) const {
45
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
8 return asymmetric == other.asymmetric && seed == other.seed &&
46
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
8 floorOffset == other.floorOffset && upslopeRim == other.upslopeRim &&
47
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 fullSlopeDegrees == other.fullSlopeDegrees &&
48
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
12 criticalGradient == other.criticalGradient && maxWearRate == other.maxWearRate;
49 }
50 bool operator!=(const CraterSlopeResponse& other) const {
51 return !(*this == other);
52 }
53 };
54
55 /// How many times as fast a crater wears on ground rising `east` and `north` meters per meter,
56 /// under `response`'s critical gradient; 1 without one.
57 double SlopeWearRate(const CraterSlopeResponse& response, double east, double north);
58
59 /// Checks slope response settings.
60 /// @throws std::invalid_argument for a field outside its range (`CheckRanges`), or an invalid
61 /// floor offset distribution or one outside [0, 0.23).
62 void ValidateCraterSlopeResponse(const CraterSlopeResponse& response);
63
64 /// One crater's asymmetry on its slope.
65 struct CraterSlopeShape {
66 Vec2d shift{}; ///< Where the deepest point moves, east and north of the center (m).
67 Vec2d upslope{}; ///< Upslope unit vector times the share of raised relief removed there.
68 };
69
70 /// The asymmetry `response` gives `crater` on ground rising `east` and `north` meters per meter,
71 /// its floor offset drawn from its ID; level when disabled or on level ground.
72 CraterSlopeShape SlopeShape(const Crater& crater, double east, double north,
73 const CraterSlopeResponse& response);
74
75 } // namespace terraingen
76