layers/craters/degradation/degradation_model.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief `DegradationModel`, which maps craters to their degradation state, and `NoDegradation`. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/layers/craters/crater.h" | ||
| 6 | #include "terraingen/layers/craters/degradation/state.h" | ||
| 7 | |||
| 8 | #include <optional> | ||
| 9 | |||
| 10 | namespace terraingen { | ||
| 11 | |||
| 12 | /// Maps each crater to its degradation state, from its diameter and age. | ||
| 13 | class DegradationModel { | ||
| 14 | public: | ||
| 15 | 1720 | virtual ~DegradationModel() = default; | |
| 16 | |||
| 17 | /// A crater's fresh and current morphometry, from its diameter and age. | ||
| 18 | /// @throws std::domain_error if the crater's diameter is not positive and finite, or the model | ||
| 19 | /// is not defined for it. | ||
| 20 | virtual CraterState State(const Crater& crater) const = 0; | ||
| 21 | |||
| 22 | /// The crater's state had it worn `rate` times as fast as on level ground, as on a steep | ||
| 23 | /// regional slope. By default it is `State` of the crater `rate` times older, which suits | ||
| 24 | /// models whose wear follows age alone. | ||
| 25 | /// @param rate At least 1. | ||
| 26 | /// @throws std::domain_error as `State`. | ||
| 27 | virtual CraterState WornState(const Crater& crater, double rate) const; | ||
| 28 | }; | ||
| 29 | |||
| 30 | /// Every crater stays as `fresh` makes it, optionally with one depth/diameter ratio for all. | ||
| 31 | class NoDegradation final : public DegradationModel { | ||
| 32 | public: | ||
| 33 | /// @param depthRatio Depth over diameter for every crater, in place of the fresh one's. | ||
| 34 | /// @throws std::invalid_argument for an empty `fresh`, or a `depthRatio` that is not positive | ||
| 35 | /// and finite. | ||
| 36 | explicit NoDegradation(FreshMorphometry fresh, std::optional<double> depthRatio = std::nullopt); | ||
| 37 | |||
| 38 | /// The crater's fresh state, as both fresh and current. | ||
| 39 | CraterState State(const Crater& crater) const override; | ||
| 40 | |||
| 41 | private: | ||
| 42 | FreshMorphometry fresh_; | ||
| 43 | std::optional<double> depthRatio_; | ||
| 44 | }; | ||
| 45 | |||
| 46 | } // namespace terraingen | ||
| 47 |