./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
77 / 77
100.0%
Branches:
44 / 50
88.0%
Functions:
11 / 11
100.0%

src/albedo/crater_albedo_options.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2
3 #include "terraingen/albedo/crater_albedo_options.h"
4
5 #include "albedo/bands.h"
6 #include "terraingen/albedo/albedo_fields.h"
7 #include "terraingen/layers/craters/secondary_model.h"
8
9 #include <cmath>
10 #include <stdexcept>
11
12 namespace terraingen {
13
14 519500 double RayRetention::Myr(double diameter) const {
15 519500 double myr = largeMyr;
16
2/2
✓ Branch 0 taken 50419 times.
✓ Branch 1 taken 469081 times.
519500 if (diameter <= smallDiameter) {
17 50419 myr = smallMyr;
18
2/2
✓ Branch 0 taken 469074 times.
✓ Branch 1 taken 7 times.
469081 } else if (diameter < midDiameter) {
19 469074 const double t = std::log(diameter / smallDiameter) / std::log(midDiameter / smallDiameter);
20 469074 myr = smallMyr * std::pow(midMyr / smallMyr, t);
21
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 time.
7 } else if (diameter <= largeDiameter) {
22 6 myr = midMyr;
23 }
24 519500 return scale * myr;
25 }
26
27 415 void ValidateRayRetention(const RayRetention& retention) {
28 415 CheckRanges(retention);
29
2/2
✓ Branch 0 taken 414 times.
✓ Branch 1 taken 1 time.
415 if (!(retention.smallDiameter < retention.midDiameter &&
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 414 times.
414 retention.midDiameter <= retention.largeDiameter)) {
31
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Ray retention diameters must be increasing");
32 }
33 414 }
34
35 34 double ObliqueImpacts::MaxStretch() const {
36
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1 time.
34 if (!enabled) {
37 return 1.0;
38 }
39 33 const double ratio = downrangeSpeedRatio.Highest();
40 33 const double a = (ratio - 1.0) / (ratio + 1.0);
41 33 return (1.0 + a) * (1.0 + a) / (1.0 + 0.5 * a * a);
42 }
43
44 422 void ValidateObliqueImpacts(const ObliqueImpacts& oblique) {
45 422 CheckRanges(oblique);
46 419 ValidateValueDistribution(oblique.downrangeSpeedRatio);
47
3/4
✓ Branch 1 taken 417 times.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 4 taken 417 times.
835 if (oblique.downrangeSpeedRatio.Lowest() < 1.0 ||
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 417 times.
417 !std::isfinite(oblique.downrangeSpeedRatio.Highest())) {
49
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("The downrange speed ratio must be at least 1 and bounded");
50 }
51
2/2
✓ Branch 0 taken 416 times.
✓ Branch 1 taken 1 time.
417 if (!(oblique.butterflyDegrees <= oblique.forbiddenDegrees &&
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 416 times.
416 oblique.forbiddenDegrees <= oblique.asymmetricDegrees)) {
53 1 throw std::invalid_argument(
54
1/1
✓ Branch 2 taken 1 time.
1 "Oblique impact angles must satisfy butterfly <= forbidden <= asymmetric");
55 }
56 416 }
57
58 479237 double CraterRays::MedianLength(double diameter) const {
59 479237 return ElliottMedianRayLength(diameter, lengthCoefficient, lengthExponent);
60 }
61
62 420 void ValidateCraterRays(const CraterRays& rays) {
63 420 CheckRanges(rays);
64 419 ValidateValueDistribution(rays.count);
65 419 ValidateValueDistribution(rays.lengthSpread);
66 419 ValidateValueDistribution(rays.widthDegrees);
67
4/4
✓ Branch 1 taken 418 times.
✓ Branch 2 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 417 times.
419 if (rays.count.Lowest() < 0.0 || rays.count.Highest() > 64.0) {
68
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("Craters must have 0 to 64 rays");
69 }
70
3/4
✓ Branch 1 taken 417 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 416 times.
✓ Branch 5 taken 1 time.
417 if (!(rays.widthDegrees.Lowest() > 0.0 && rays.widthDegrees.Highest() < 180.0)) {
71
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("Ray widths must be in (0, 180) degrees");
72 }
73 416 ValidateObliqueImpacts(rays.oblique);
74
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 414 times.
416 if (rays.layout) {
75 2 ValidateRayLayout(*rays.layout);
76 }
77 415 }
78
79 2 void ValidateCraterAlbedoTexture(const CraterAlbedoTexture& texture) {
80 2 CheckRanges(texture);
81 }
82
83 1701 void ValidateReflectanceZone(const ReflectanceZone& zone) {
84 1701 CheckRanges(zone);
85
1/1
✓ Branch 2 taken 1696 times.
3400 ValidateRelativeChange(zone.change, "A reflectance zone's change");
86 1696 ValidateValueDistribution(zone.scale);
87
3/4
✓ Branch 1 taken 1692 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1692 times.
1694 if (!(zone.scale.Lowest() > 0.0 && std::isfinite(zone.scale.Highest()))) {
88
1/1
✓ Branch 2 taken 2 times.
2 throw std::invalid_argument("A reflectance zone needs a positive, bounded reach scale");
89 }
90 1692 }
91
92 2352 double CraterReflectanceZones::MaxReach(double diameter) const {
93 2352 double reach = 0.0;
94
2/2
✓ Branch 0 taken 9408 times.
✓ Branch 1 taken 2352 times.
11760 for (const ReflectanceZone* zone : All()) {
95 9408 reach = std::fmax(reach, zone->coefficient * std::pow(diameter, zone->exponent) *
96 9408 zone->scale.Highest());
97 }
98 2352 return reach;
99 }
100
101 438 void ValidateCraterReflectanceZones(const CraterReflectanceZones& zones) {
102 438 CheckRanges(zones);
103
2/2
✓ Branch 0 taken 1700 times.
✓ Branch 1 taken 420 times.
2120 for (const ReflectanceZone* zone : zones.All()) {
104 1700 ValidateReflectanceZone(*zone);
105 }
106 420 }
107
108 451 void ValidateCraterAlbedoOptions(const CraterAlbedoOptions& options) {
109 451 CheckRanges(options);
110 423 ValidateCraterReflectanceZones(options.zones);
111 419 ValidateCraterRays(options.rays);
112 415 ValidateRayRetention(options.retention);
113 414 ValidateResolutionFade(options.fade);
114 413 ValidateCraterSelection(options.selection, "Crater albedo");
115
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 411 times.
412 if (!(options.maxMaturity >= options.backgroundMaturity)) {
116
1/1
✓ Branch 2 taken 1 time.
1 throw std::invalid_argument("The maturity cap must be at least the background maturity");
117 }
118 411 }
119
120 } // namespace terraingen
121