src/distribution/sp8023.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/distribution/sp8023.h" | ||
| 4 | |||
| 5 | #include "terraingen/util/span.h" | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <cmath> | ||
| 9 | #include <stdexcept> | ||
| 10 | #include <utility> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | namespace terraingen { | ||
| 14 | |||
| 15 | namespace { | ||
| 16 | |||
| 17 | /// A point of a digitized curve: log10 of the diameter in meters and of N per m^2. | ||
| 18 | struct LogPoint { | ||
| 19 | double logDiameter; | ||
| 20 | double logCumulative; | ||
| 21 | }; | ||
| 22 | |||
| 23 | constexpr std::array<LogPoint, 4> kIntercraterFine{ | ||
| 24 | {{-4.5, 7.885}, {-3.839, 6.154}, {-3.194, 4.416}, {-2.749, 3.304}}}; | ||
| 25 | constexpr std::array<LogPoint, 11> kIntercraterMaximum{{{-2.293, 2.489}, | ||
| 26 | {-1.844, 1.713}, | ||
| 27 | {-1.409, 0.951}, | ||
| 28 | {-0.973, 0.164}, | ||
| 29 | {-0.744, -0.230}, | ||
| 30 | {-0.515, -0.819}, | ||
| 31 | {-0.286, -1.489}, | ||
| 32 | {-0.057, -2.153}, | ||
| 33 | {0.358, -3.469}, | ||
| 34 | {0.768, -4.777}, | ||
| 35 | {0.973, -5.426}}}; | ||
| 36 | constexpr std::array<LogPoint, 12> kIntercraterNominal{{{-2.293, 2.136}, | ||
| 37 | {-1.844, 1.220}, | ||
| 38 | {-1.409, 0.287}, | ||
| 39 | {-0.973, -0.615}, | ||
| 40 | {-0.744, -1.063}, | ||
| 41 | {-0.515, -1.515}, | ||
| 42 | {-0.286, -1.933}, | ||
| 43 | {-0.057, -2.455}, | ||
| 44 | {0.154, -3.184}, | ||
| 45 | {0.358, -3.769}, | ||
| 46 | {0.563, -4.481}, | ||
| 47 | {0.768, -5.196}}}; | ||
| 48 | constexpr std::array<LogPoint, 10> kIntercraterMinimum{{{-2.293, 2.136}, | ||
| 49 | {-1.844, 1.078}, | ||
| 50 | {-1.409, -0.044}, | ||
| 51 | {-0.973, -1.174}, | ||
| 52 | {-0.286, -2.825}, | ||
| 53 | {-0.057, -3.397}, | ||
| 54 | {0.154, -3.874}, | ||
| 55 | {0.358, -4.447}, | ||
| 56 | {0.563, -5.052}, | ||
| 57 | {0.768, -5.522}}}; | ||
| 58 | constexpr std::array<LogPoint, 11> kCraterMaximum{{{0.152, -2.022}, | ||
| 59 | {0.286, -2.299}, | ||
| 60 | {0.419, -2.608}, | ||
| 61 | {0.552, -2.927}, | ||
| 62 | {0.686, -3.271}, | ||
| 63 | {0.819, -3.651}, | ||
| 64 | {0.952, -4.093}, | ||
| 65 | {1.082, -4.608}, | ||
| 66 | {1.211, -5.170}, | ||
| 67 | {1.339, -5.748}, | ||
| 68 | {1.382, -5.940}}}; | ||
| 69 | constexpr std::array<LogPoint, 11> kCraterNominal{{{-0.071, -2.282}, | ||
| 70 | {0.063, -2.574}, | ||
| 71 | {0.197, -2.887}, | ||
| 72 | {0.330, -3.239}, | ||
| 73 | {0.463, -3.603}, | ||
| 74 | {0.597, -4.028}, | ||
| 75 | {0.730, -4.436}, | ||
| 76 | {0.863, -4.841}, | ||
| 77 | {0.997, -5.190}, | ||
| 78 | {1.125, -5.572}, | ||
| 79 | {1.254, -5.935}}}; | ||
| 80 | constexpr std::array<LogPoint, 8> kCraterMinimum{{{-0.071, -2.606}, | ||
| 81 | {0.063, -3.050}, | ||
| 82 | {0.197, -3.547}, | ||
| 83 | {0.330, -3.998}, | ||
| 84 | {0.463, -4.497}, | ||
| 85 | {0.597, -4.968}, | ||
| 86 | {0.730, -5.422}, | ||
| 87 | {0.863, -5.889}}}; | ||
| 88 | |||
| 89 | /// The table through the points of `first` then `second`, converted from log10. | ||
| 90 | 283 | TabulatedSfd Table(Span<const LogPoint> first, Span<const LogPoint> second = {}) { | |
| 91 | 283 | std::vector<double> diameters; | |
| 92 | 283 | std::vector<double> cumulative; | |
| 93 | 849 | for (const auto points : {first, second}) { | |
| 94 | 4982 | for (const LogPoint& point : points) { | |
| 95 | 4416 | diameters.push_back(std::pow(10.0, point.logDiameter)); | |
| 96 | 4416 | cumulative.push_back(std::pow(10.0, point.logCumulative)); | |
| 97 | } | ||
| 98 | } | ||
| 99 | 566 | return TabulatedSfd(std::move(diameters), std::move(cumulative)); | |
| 100 | 283 | } | |
| 101 | |||
| 102 | } // namespace | ||
| 103 | |||
| 104 | 266 | TabulatedSfd Sp8023IntercraterBlocks(SpecificationCurve curve) { | |
| 105 | 266 | switch (curve) { | |
| 106 | 2 | case SpecificationCurve::Minimum: | |
| 107 | 2 | return Table(kIntercraterFine, kIntercraterMinimum); | |
| 108 | 251 | case SpecificationCurve::Nominal: | |
| 109 | 251 | return Table(kIntercraterFine, kIntercraterNominal); | |
| 110 | 12 | case SpecificationCurve::Maximum: | |
| 111 | 12 | return Table(kIntercraterFine, kIntercraterMaximum); | |
| 112 | } | ||
| 113 | 1 | throw std::invalid_argument("Unknown specification curve"); | |
| 114 | } | ||
| 115 | |||
| 116 | 19 | TabulatedSfd Sp8023CraterBlocks(SpecificationCurve curve) { | |
| 117 | 19 | switch (curve) { | |
| 118 | 2 | case SpecificationCurve::Minimum: | |
| 119 | 2 | return Table(kCraterMinimum); | |
| 120 | 14 | case SpecificationCurve::Nominal: | |
| 121 | 14 | return Table(kCraterNominal); | |
| 122 | 2 | case SpecificationCurve::Maximum: | |
| 123 | 2 | return Table(kCraterMaximum); | |
| 124 | } | ||
| 125 | 1 | throw std::invalid_argument("Unknown specification curve"); | |
| 126 | } | ||
| 127 | |||
| 128 | } // namespace terraingen | ||
| 129 |