include/terraingen/layers/craters/secondaries.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief `SecondaryCraterLayer`, secondary craters around the craters of a `CraterLayer`. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/layers/craters/crater.h" | ||
| 8 | #include "terraingen/layers/craters/crater_layer.h" | ||
| 9 | #include "terraingen/layers/craters/crater_placer.h" | ||
| 10 | #include "terraingen/layers/craters/rays.h" | ||
| 11 | #include "terraingen/layers/craters/secondary_model.h" | ||
| 12 | #include "terraingen/layers/craters/shaping/apply.h" | ||
| 13 | #include "terraingen/layers/layer.h" | ||
| 14 | |||
| 15 | #include <cstdint> | ||
| 16 | #include <limits> | ||
| 17 | #include <memory> | ||
| 18 | #include <optional> | ||
| 19 | #include <unordered_map> | ||
| 20 | |||
| 21 | namespace terraingen { | ||
| 22 | |||
| 23 | /// The ellipse an elongated secondary is stretched to. | ||
| 24 | 1130 | struct SecondaryOutline { | |
| 25 | double ellipticity = 1.0; ///< Long over short axis. | ||
| 26 | double heading = 0.0; ///< Long axis, radians counter-clockwise from east, toward the primary. | ||
| 27 | }; | ||
| 28 | |||
| 29 | /// The farthest `shapes` stretch a secondary's rim, as a factor on its radius. | ||
| 30 | double SecondaryStretch(const SecondaryShapes& shapes); | ||
| 31 | |||
| 32 | /// Secondary craters around the craters of a `CraterLayer`, applied additively with | ||
| 33 | /// `ApplyCraters`. | ||
| 34 | /// | ||
| 35 | /// Drawn per primary in polar cells keyed to its ID, size band, ring and sector, so a tile holds | ||
| 36 | /// the same secondaries as any larger grid; bands too small for the spacing are skipped. | ||
| 37 | class SecondaryCraterLayer final : public Layer, public CraterPlacer { | ||
| 38 | public: | ||
| 39 | /// The secondaries of the craters of `primaries`. | ||
| 40 | /// @param apply How secondaries are applied; without a datum. | ||
| 41 | /// @param base The surface, which must be the primaries', and the source. | ||
| 42 | /// @throws std::invalid_argument for a null layer or degradation, a mismatched surface, a | ||
| 43 | /// rejected profile, invalid options, a datum, or options a density-mapped primary lacks. | ||
| 44 | SecondaryCraterLayer(std::shared_ptr<const CraterLayer> primaries, CraterShapeModels models, | ||
| 45 | SecondaryCraterOptions options, CraterApplyOptions apply = {}, | ||
| 46 | TerrainBase base = {}); | ||
| 47 | |||
| 48 | /// Secondaries shaped as the primaries are (`CraterModels::Shape`). | ||
| 49 | /// @throws std::invalid_argument as the other constructor. | ||
| 50 | SecondaryCraterLayer(std::shared_ptr<const CraterLayer> primaries, | ||
| 51 | SecondaryCraterOptions options, CraterApplyOptions apply = {}, | ||
| 52 | TerrainBase base = {}); | ||
| 53 | |||
| 54 | /// The largest secondary the layer places, in meters. | ||
| 55 | double MaxFeatureDiameter() const; | ||
| 56 | |||
| 57 | /// The secondaries a grid covering `region` (surface coordinates) gets: those centered in it or | ||
| 58 | /// within the profile's reach of it. | ||
| 59 | /// @param spacing Sample spacing in meters; 0 for every size. | ||
| 60 | /// @throws std::invalid_argument if more than `maxExpected` are expected. | ||
| 61 | CraterList Secondaries(const Bounds2d& region, double spacing = 0.0) const; | ||
| 62 | |||
| 63 | /// `Secondaries`, also filling `outlines` with the ellipses of the elongated ones by ID. | ||
| 64 | CraterList Secondaries(const Bounds2d& region, double spacing, | ||
| 65 | std::unordered_map<std::uint64_t, SecondaryOutline>& outlines) const; | ||
| 66 | |||
| 67 | /// The outer range from its center, in meters, of the secondaries of a primary of `diameter` | ||
| 68 | /// meters. | ||
| 69 | double OuterRange(double diameter) const; | ||
| 70 | |||
| 71 | CraterFeatures CratersOver(const RasterGrid& grid, double spacing) const override; | ||
| 72 | |||
| 73 | /// The options the layer was made with. | ||
| 74 | const SecondaryCraterOptions& Options() const { | ||
| 75 | return m_options; | ||
| 76 | } | ||
| 77 | |||
| 78 | 7 | std::optional<TerrainBase> LayerBase() const override { | |
| 79 | 7 | return TerrainBase{m_apply.surface, m_source}; | |
| 80 | } | ||
| 81 | |||
| 82 | /// The primaries, which must come before this layer. | ||
| 83 | 8 | std::vector<const Layer*> Dependencies() const override { | |
| 84 | 8 | return {m_primaries.get()}; | |
| 85 | } | ||
| 86 | |||
| 87 | /// The layer with its seed `ReseedWord(seed, 0)` and the apply seeds of the irregularity, | ||
| 88 | /// noise, texture, slope, terraces and peaks `ReseedWord(seed, 1)` to `ReseedWord(seed, 6)`. | ||
| 89 | LayerPtr Reseeded(std::uint64_t seed) const override; | ||
| 90 | |||
| 91 | /// A copy reading the replacement of its primaries; null when they are not replaced. | ||
| 92 | LayerPtr Rebound(const LayerReplacements& replaced) const override; | ||
| 93 | |||
| 94 | /// The layer built again from its models and options on `base`. | ||
| 95 | /// @throws std::invalid_argument as the constructor. | ||
| 96 | LayerPtr Rebased(const TerrainBase& base) const override; | ||
| 97 | |||
| 98 | protected: | ||
| 99 | /// Applies the secondaries reaching the samples. | ||
| 100 | /// @throws std::invalid_argument if more than `maxExpected` secondaries are expected. | ||
| 101 | void ApplySamples(SampleBlock& samples, const LayerContext& context) const override; | ||
| 102 | |||
| 103 | private: | ||
| 104 | std::shared_ptr<const CraterLayer> m_primaries; | ||
| 105 | CraterShapeModels m_models; | ||
| 106 | SecondaryCraterOptions m_options; | ||
| 107 | CraterApplyOptions m_apply; | ||
| 108 | std::shared_ptr<const Source> m_source; | ||
| 109 | std::shared_ptr<const SurfaceField> m_limit; | ||
| 110 | }; | ||
| 111 | |||
| 112 | } // namespace terraingen | ||
| 113 |