layers/craters/secondaries.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /// @file | ||
| 2 | /// @brief `SecondaryCraterLayer`, secondary craters around the craters of a `CraterLayer`. | ||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include "terraingen/layers/craters/crater.h" | ||
| 6 | #include "terraingen/layers/craters/crater_layer.h" | ||
| 7 | #include "terraingen/layers/craters/crater_placer.h" | ||
| 8 | #include "terraingen/layers/craters/rays.h" | ||
| 9 | #include "terraingen/layers/craters/secondary_model.h" | ||
| 10 | #include "terraingen/layers/craters/shaping/apply.h" | ||
| 11 | #include "terraingen/layers/layer.h" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | #include <limits> | ||
| 15 | #include <memory> | ||
| 16 | #include <optional> | ||
| 17 | #include <unordered_map> | ||
| 18 | |||
| 19 | namespace terraingen { | ||
| 20 | |||
| 21 | /// The ellipse an elongated secondary is stretched to. | ||
| 22 | struct SecondaryOutline { | ||
| 23 | double ellipticity = 1.0; ///< Long over short axis. | ||
| 24 | double heading = 0.0; ///< Long axis, radians counter-clockwise from east, toward the primary. | ||
| 25 | }; | ||
| 26 | |||
| 27 | /// The farthest `shapes` stretch a secondary's rim, as a factor on its radius. | ||
| 28 | double SecondaryStretch(const SecondaryShapes& shapes); | ||
| 29 | |||
| 30 | /// Secondary craters around the craters of a `CraterLayer`, applied additively with | ||
| 31 | /// `ApplyCraters`. | ||
| 32 | /// | ||
| 33 | /// Drawn per primary in polar cells keyed to its ID, size band, ring and sector, so a tile holds | ||
| 34 | /// the same secondaries as any larger grid; bands too small for the spacing are skipped. | ||
| 35 | class SecondaryCraterLayer final : public Layer, public CraterPlacer { | ||
| 36 | public: | ||
| 37 | /// @param primaries The layer whose craters throw secondaries. | ||
| 38 | /// @param apply How secondaries are applied; without a datum. | ||
| 39 | /// @throws std::invalid_argument for a null layer or model, invalid options, or apply options | ||
| 40 | /// with a datum. | ||
| 41 | SecondaryCraterLayer(std::shared_ptr<const CraterLayer> primaries, CraterShapeModels models, | ||
| 42 | SecondaryCraterOptions options, CraterApplyOptions apply = {}); | ||
| 43 | |||
| 44 | /// The largest secondary the layer places, in metres. | ||
| 45 | double MaxFeatureDiameter() const; | ||
| 46 | |||
| 47 | /// The secondaries a grid covering `region` (surface coordinates) gets: those centred in it or | ||
| 48 | /// within the profile's reach of it. | ||
| 49 | /// @param spacing Sample spacing in metres; 0 for every size. | ||
| 50 | /// @throws std::invalid_argument if more than `maxExpected` are expected. | ||
| 51 | CraterList Secondaries(const Bounds2d& region, double spacing = 0.0) const; | ||
| 52 | |||
| 53 | /// `Secondaries`, also filling `outlines` with the ellipses of the elongated ones by ID. | ||
| 54 | CraterList Secondaries(const Bounds2d& region, double spacing, | ||
| 55 | std::unordered_map<std::uint64_t, SecondaryOutline>& outlines) const; | ||
| 56 | |||
| 57 | /// The outer range from its centre, in metres, of the secondaries of a primary of `diameter` | ||
| 58 | /// metres. | ||
| 59 | double OuterRange(double diameter) const; | ||
| 60 | |||
| 61 | /// A secondary's attributes in the state the degradation model gives it. | ||
| 62 | /// @throws std::domain_error as `DegradationModel::State`. | ||
| 63 | CraterAttributes Attributes(const Crater& crater) const; | ||
| 64 | |||
| 65 | CraterFeatures CratersOver(const RasterGrid& grid, double spacing) const override; | ||
| 66 | |||
| 67 | /// The options the layer was made with. | ||
| 68 | 2154 | const SecondaryCraterOptions& Options() const { | |
| 69 | 2154 | return options_; | |
| 70 | } | ||
| 71 | |||
| 72 | protected: | ||
| 73 | /// Applies the secondaries reaching the samples. | ||
| 74 | /// @throws std::invalid_argument if more than `maxExpected` secondaries are expected. | ||
| 75 | void ApplySamples(SampleBlock& samples, const LayerContext& context) const override; | ||
| 76 | |||
| 77 | private: | ||
| 78 | std::shared_ptr<const CraterLayer> primaries_; | ||
| 79 | CraterShapeModels models_; | ||
| 80 | SecondaryCraterOptions options_; | ||
| 81 | CraterApplyOptions apply_; | ||
| 82 | }; | ||
| 83 | |||
| 84 | } // namespace terraingen | ||
| 85 |