src/layers/craters/degradation/freshness_degradation.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | #include "terraingen/layers/craters/degradation/freshness_degradation.h" | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <stdexcept> | ||
| 7 | #include <utility> | ||
| 8 | |||
| 9 | namespace terraingen { | ||
| 10 | |||
| 11 | 1169 | FreshnessDegradation::FreshnessDegradation(std::shared_ptr<const CraterAgeModel> ages, | |
| 12 | 1169 | FreshMorphometry fresh, double cutoffDepthRatio) | |
| 13 | 1169 | : m_ages(std::move(ages)), m_fresh(std::move(fresh)), m_cutoffDepthRatio(cutoffDepthRatio) { | |
| 14 | 1169 | if (!m_ages) { | |
| 15 | 1 | throw std::invalid_argument("Freshness degradation needs an age model"); | |
| 16 | } | ||
| 17 | 1168 | if (!m_fresh) { | |
| 18 | 1 | throw std::invalid_argument("Freshness degradation needs the fresh crater morphometry"); | |
| 19 | } | ||
| 20 | 1167 | if (!(m_cutoffDepthRatio > 0.0 && m_cutoffDepthRatio < 0.1)) { | |
| 21 | 3 | throw std::invalid_argument("Cutoff depth/diameter ratio must be in (0, 0.1)"); | |
| 22 | } | ||
| 23 | 1169 | } | |
| 24 | |||
| 25 | 18761 | CraterState FreshnessDegradation::State(const Crater& crater) const { | |
| 26 | 18761 | const CraterMorphometry fresh = m_fresh(crater.diameter); | |
| 27 | 18762 | const double floor = std::fmin(m_cutoffDepthRatio / fresh.depthRatio, 1.0); | |
| 28 | 18762 | const double erosion = | |
| 29 | 18762 | floor + (1.0 - floor) * m_ages->RemainingLifetime(crater.diameter, crater.ageGyr); | |
| 30 | 18761 | return {fresh, {erosion * fresh.depthRatio, erosion * fresh.rimHeightRatio}}; | |
| 31 | } | ||
| 32 | |||
| 33 | } // namespace terraingen | ||
| 34 |