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