TerrainGen coverage


terraingen/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
26 / 26
100.0%
Branches:
14 / 15
93.3%
Functions:
3 / 3
100.0%

layers/craters/profiles/fassett_thomson.cpp
Line Branch Exec Source
1 #include "terraingen/layers/craters/profiles/fassett_thomson.h"
2
3 #include <cmath>
4
5 namespace terraingen {
6
7 namespace {
8
9 /// The interior fit, in units of D at x = r / R.
10 3337762 double Interior(double x) {
11 3337762 return -0.228809953 + x * (0.227533882 + x * (0.083116795 - x * 0.039499407));
12 }
13
14 /// The exterior fit, in units of D at x = r / R.
15 1173986 double Exterior(double x) {
16 1173986 return 0.188253307 + x * (-0.187050452 + x * (0.01844746 + x * 0.01505647));
17 }
18
19 } // namespace
20
21 5199759 double FassettThomsonProfile::Height(double distance, double diameter,
22 const CraterState& state) const {
23 5199759 const double x = distance / (0.5 * diameter);
24
2/2
✓ Branch 0 taken 52174 times.
✓ Branch 1 taken 5147585 times.
5199759 if (x > 1.5) {
25 52174 return 0.0;
26 }
27 5147585 double h = 0.0;
28
2/3
✓ Branch 0 taken 5118366 times.
✓ Branch 1 taken 29219 times.
✗ Branch 2 not taken.
5147585 switch (rim_) {
29 5118366 case FassettThomsonRim::Original:
30 case FassettThomsonRim::AtOneRadius: {
31
2/2
✓ Branch 0 taken 5092773 times.
✓ Branch 1 taken 25593 times.
5118366 const double rim = rim_ == FassettThomsonRim::Original ? 0.98 : 1.0;
32
2/2
✓ Branch 0 taken 634592 times.
✓ Branch 1 taken 4483774 times.
5118366 if (x <= 0.2) {
33 634592 h = -0.181;
34
2/2
✓ Branch 0 taken 3320438 times.
✓ Branch 1 taken 1163336 times.
4483774 } else if (x <= rim) {
35 3320438 h = Interior(x);
36 } else {
37 1163336 h = Exterior(x);
38 }
39 5118366 break;
40 }
41 29219 case FassettThomsonRim::Plateau:
42
2/2
✓ Branch 0 taken 17324 times.
✓ Branch 1 taken 11895 times.
29219 if (x <= 0.98) {
43 17324 h = Interior(x);
44
2/2
✓ Branch 0 taken 1245 times.
✓ Branch 1 taken 10650 times.
11895 } else if (x <= 1.02) {
45 1245 h = state.fresh.rimHeightRatio;
46 } else {
47 10650 h = Exterior(x);
48 }
49 29219 break;
50 }
51 5147585 return std::fmax(h, state.fresh.rimHeightRatio - state.current.depthRatio) * diameter;
52 }
53
54 } // namespace terraingen
55