src/layers/craters/degradation/degradation_model.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/layers/craters/degradation/degradation_model.h" | ||
| 4 | |||
| 5 | #include "terraingen/layers/craters/profiles/martin_parkes_dunstan.h" | ||
| 6 | #include "util/checks.h" | ||
| 7 | |||
| 8 | #include <cmath> | ||
| 9 | #include <stdexcept> | ||
| 10 | #include <utility> | ||
| 11 | |||
| 12 | namespace terraingen { | ||
| 13 | |||
| 14 | 6 | CraterState DegradationModel::WornState(const Crater& crater, double rate) const { | |
| 15 | 6 | Crater older = crater; | |
| 16 | 6 | older.ageGyr *= rate; | |
| 17 | 6 | return State(older); | |
| 18 | } | ||
| 19 | |||
| 20 | 1043 | std::shared_ptr<const CraterProfile> MatchedProfile(std::shared_ptr<const CraterProfile> profile, | |
| 21 | const DegradationModel& degradation) { | ||
| 22 | 1043 | std::shared_ptr<const CraterProfile> required = degradation.RequiredProfile(); | |
| 23 | 1043 | if (profile && required && profile != required) { | |
| 24 | 4 | throw std::invalid_argument( | |
| 25 | 4 | "The degradation shapes craters with its own profile; pass that profile or none"); | |
| 26 | } | ||
| 27 | 1039 | if (profile) { | |
| 28 | 1025 | return profile; | |
| 29 | } | ||
| 30 | 32 | return required ? required : std::make_shared<MartinParkesDunstanProfile>(); | |
| 31 | 1039 | } | |
| 32 | 2531 | NoDegradation::NoDegradation(FreshMorphometry fresh, std::optional<double> depthRatio) | |
| 33 | 2531 | : m_fresh(std::move(fresh)), m_depthRatio(depthRatio) { | |
| 34 | 2531 | if (!m_fresh) { | |
| 35 | 1 | throw std::invalid_argument("No degradation needs the fresh crater morphometry"); | |
| 36 | } | ||
| 37 | 2530 | if (m_depthRatio) { | |
| 38 | 58 | RequirePositive(*m_depthRatio, "Depth/diameter ratio"); | |
| 39 | } | ||
| 40 | 2531 | } | |
| 41 | |||
| 42 | 31307 | CraterState NoDegradation::State(const Crater& crater) const { | |
| 43 | 31307 | CraterMorphometry fresh = m_fresh(crater.diameter); | |
| 44 | 31306 | if (m_depthRatio) { | |
| 45 | 217 | fresh.depthRatio = *m_depthRatio; | |
| 46 | } | ||
| 47 | 31306 | return {fresh, fresh}; | |
| 48 | } | ||
| 49 | |||
| 50 | } // namespace terraingen | ||
| 51 |