include/terraingen/layers/craters/degradation/degradation_model.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief `DegradationModel`, which maps craters to their degradation state, and `NoDegradation`. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/craters/crater.h" | ||
| 8 | #include "terraingen/layers/craters/degradation/state.h" | ||
| 9 | |||
| 10 | #include <memory> | ||
| 11 | #include <optional> | ||
| 12 | |||
| 13 | namespace terraingen { | ||
| 14 | |||
| 15 | class CraterAgeModel; | ||
| 16 | class CraterProfile; | ||
| 17 | |||
| 18 | /// Maps each crater to its degradation state, from its diameter and age. | ||
| 19 | 3922 | class DegradationModel { | |
| 20 | public: | ||
| 21 | 293 | virtual ~DegradationModel() = default; | |
| 22 | |||
| 23 | /// A crater's fresh and current morphometry, from its diameter and age. | ||
| 24 | /// @throws std::domain_error if the crater's diameter is not positive and finite, or the model | ||
| 25 | /// is not defined for it. | ||
| 26 | virtual CraterState State(const Crater& crater) const = 0; | ||
| 27 | |||
| 28 | /// The crater's state had it worn `rate` times as fast as on level ground, as on a steep | ||
| 29 | /// regional slope. By default it is `State` of the crater `rate` times older, which suits | ||
| 30 | /// models whose wear follows age alone. | ||
| 31 | /// @param rate At least 1. | ||
| 32 | /// @throws std::domain_error as `State`. | ||
| 33 | virtual CraterState WornState(const Crater& crater, double rate) const; | ||
| 34 | |||
| 35 | /// The profile craters in this model's states must be shaped with; null when any will do. | ||
| 36 | 870 | virtual std::shared_ptr<const CraterProfile> RequiredProfile() const { | |
| 37 | 870 | return nullptr; | |
| 38 | } | ||
| 39 | |||
| 40 | /// The age model whose lifetimes this model's states follow, which a crater layer given no | ||
| 41 | /// ages draws from; null for none. | ||
| 42 | 5 | virtual std::shared_ptr<const CraterAgeModel> AgeModel() const { | |
| 43 | 5 | return nullptr; | |
| 44 | } | ||
| 45 | }; | ||
| 46 | |||
| 47 | /// The profile to shape craters under `degradation` with: `profile`, or when it is null the one | ||
| 48 | /// `degradation` requires, else Martin, Parkes and Dunstan's (`MartinParkesDunstanProfile`). | ||
| 49 | /// @throws std::invalid_argument if `profile` is set and is not the one `degradation` requires. | ||
| 50 | std::shared_ptr<const CraterProfile> MatchedProfile(std::shared_ptr<const CraterProfile> profile, | ||
| 51 | const DegradationModel& degradation); | ||
| 52 | |||
| 53 | /// Every crater stays as `fresh` makes it, optionally with one depth/diameter ratio for all. | ||
| 54 | 294 | class NoDegradation final : public DegradationModel { | |
| 55 | public: | ||
| 56 | /// @param depthRatio Depth over diameter for every crater, in place of the fresh one's. | ||
| 57 | /// @throws std::invalid_argument for an empty `fresh`, or a `depthRatio` that is not positive | ||
| 58 | /// and finite. | ||
| 59 | explicit NoDegradation(FreshMorphometry fresh, std::optional<double> depthRatio = std::nullopt); | ||
| 60 | |||
| 61 | /// The crater's fresh state, as both fresh and current. | ||
| 62 | CraterState State(const Crater& crater) const override; | ||
| 63 | |||
| 64 | private: | ||
| 65 | FreshMorphometry m_fresh; | ||
| 66 | std::optional<double> m_depthRatio; | ||
| 67 | }; | ||
| 68 | |||
| 69 | } // namespace terraingen | ||
| 70 |