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 | 519500 | if (diameter <= smallDiameter) { | |
| 17 | 50419 | myr = smallMyr; | |
| 18 | 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 | 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 | 415 | if (!(retention.smallDiameter < retention.midDiameter && | |
| 30 | 414 | retention.midDiameter <= retention.largeDiameter)) { | |
| 31 | 1 | throw std::invalid_argument("Ray retention diameters must be increasing"); | |
| 32 | } | ||
| 33 | 414 | } | |
| 34 | |||
| 35 | 34 | double ObliqueImpacts::MaxStretch() const { | |
| 36 | 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 | 835 | if (oblique.downrangeSpeedRatio.Lowest() < 1.0 || | |
| 48 | 417 | !std::isfinite(oblique.downrangeSpeedRatio.Highest())) { | |
| 49 | 1 | throw std::invalid_argument("The downrange speed ratio must be at least 1 and bounded"); | |
| 50 | } | ||
| 51 | 417 | if (!(oblique.butterflyDegrees <= oblique.forbiddenDegrees && | |
| 52 | 416 | oblique.forbiddenDegrees <= oblique.asymmetricDegrees)) { | |
| 53 | 1 | throw std::invalid_argument( | |
| 54 | 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 | 419 | if (rays.count.Lowest() < 0.0 || rays.count.Highest() > 64.0) { | |
| 68 | 2 | throw std::invalid_argument("Craters must have 0 to 64 rays"); | |
| 69 | } | ||
| 70 | 417 | if (!(rays.widthDegrees.Lowest() > 0.0 && rays.widthDegrees.Highest() < 180.0)) { | |
| 71 | 1 | throw std::invalid_argument("Ray widths must be in (0, 180) degrees"); | |
| 72 | } | ||
| 73 | 416 | ValidateObliqueImpacts(rays.oblique); | |
| 74 | 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 | 3400 | ValidateRelativeChange(zone.change, "A reflectance zone's change"); | |
| 86 | 1696 | ValidateValueDistribution(zone.scale); | |
| 87 | 1694 | if (!(zone.scale.Lowest() > 0.0 && std::isfinite(zone.scale.Highest()))) { | |
| 88 | 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 | 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 | 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 | 412 | if (!(options.maxMaturity >= options.backgroundMaturity)) { | |
| 116 | 1 | throw std::invalid_argument("The maturity cap must be at least the background maturity"); | |
| 117 | } | ||
| 118 | 411 | } | |
| 119 | |||
| 120 | } // namespace terraingen | ||
| 121 |