include/terraingen/layers/strata.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief `StrataLayer`, layered rock: the ground beneath terraced into benches and cliffs. | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "terraingen/geometry/geometry.h" | ||
| 8 | #include "terraingen/geometry/surface.h" | ||
| 9 | #include "terraingen/layers/layer.h" | ||
| 10 | #include "terraingen/layers/material.h" | ||
| 11 | #include "terraingen/random/stream.h" | ||
| 12 | |||
| 13 | #include <cstdint> | ||
| 14 | |||
| 15 | namespace terraingen { | ||
| 16 | |||
| 17 | /// The beds a `StrataLayer` cuts. Lengths are in meters, angles in degrees. | ||
| 18 | 2 | struct StrataOptions { | |
| 19 | double bedThickness = 2.0; ///< Mean thickness of a bed. | ||
| 20 | /// How far each bed boundary strays, in bed thicknesses, in [0, 1). | ||
| 21 | double thicknessVariation = 0.4; | ||
| 22 | double dipDegrees = 0.0; ///< Dip of the beds from horizontal, below 90 deg. | ||
| 23 | /// Direction the beds dip toward, degrees counter-clockwise from +x (local east on a body). | ||
| 24 | double dipAzimuthDegrees = 0.0; | ||
| 25 | /// How sharply each bed is cut into a flat bench and a cliff, at least 1: 1 leaves the ground | ||
| 26 | /// as it is, larger values flatten the benches and steepen the cliffs. | ||
| 27 | double sharpness = 4.0; | ||
| 28 | double strength = 1.0; ///< Share of the terracing applied, in [0, 1]. | ||
| 29 | /// Share of a bed's height, at its top, that counts as the cliff (bedrock) in the material map, | ||
| 30 | /// in (0, 1]. | ||
| 31 | double cliffShare = 0.3; | ||
| 32 | std::uint32_t seed = 1; ///< Varies the bed boundaries. | ||
| 33 | /// On a body, the surface point whose tangent frame the dip is measured in. | ||
| 34 | Vec2d anchor{}; | ||
| 35 | /// Share of the beds that are hard, resistant rock, in [0, 1]: a hard bed is cut at | ||
| 36 | /// `sharpness` into a bench and a cliff and lays bedrock there, a soft one at `softSharpness` | ||
| 37 | /// into a slope without bedrock. Each bed is drawn hard or soft by the seed. | ||
| 38 | double hardShare = 1.0; | ||
| 39 | double softSharpness = 1.0; ///< How sharply soft beds are cut, at least 1. | ||
| 40 | |||
| 41 | bool operator==(const StrataOptions& other) const { | ||
| 42 | return bedThickness == other.bedThickness && | ||
| 43 | thicknessVariation == other.thicknessVariation && dipDegrees == other.dipDegrees && | ||
| 44 | dipAzimuthDegrees == other.dipAzimuthDegrees && sharpness == other.sharpness && | ||
| 45 | strength == other.strength && cliffShare == other.cliffShare && seed == other.seed && | ||
| 46 | anchor == other.anchor && hardShare == other.hardShare && | ||
| 47 | softSharpness == other.softSharpness; | ||
| 48 | } | ||
| 49 | }; | ||
| 50 | |||
| 51 | /// Checks strata options. | ||
| 52 | /// @throws std::invalid_argument for a bed thickness that is not positive and finite, a thickness | ||
| 53 | /// variation outside [0, 1), a dip outside [0, 90) deg, a sharpness or soft sharpness below 1, a | ||
| 54 | /// strength or hard share outside [0, 1], a cliff share outside (0, 1], or a non-finite azimuth or | ||
| 55 | /// anchor. | ||
| 56 | void ValidateStrataOptions(const StrataOptions& options); | ||
| 57 | |||
| 58 | /// Layered rock: the ground beneath terraced into dipping beds, each a bench below a cliff, so | ||
| 59 | /// hills become buttes and mesas; it lays bedrock over the material map on the cliffs. | ||
| 60 | 127 | class StrataLayer final : public FormulaLayer, public MaterialSource { | |
| 61 | public: | ||
| 62 | /// On a body, the dip is measured in the tangent frame of `options.anchor`. | ||
| 63 | /// @throws std::invalid_argument as `ValidateStrataOptions`. | ||
| 64 | explicit StrataLayer(StrataOptions options); | ||
| 65 | |||
| 66 | /// The options the layer was made with. | ||
| 67 | ✗ | const StrataOptions& Options() const { | |
| 68 | ✗ | return m_options; | |
| 69 | } | ||
| 70 | |||
| 71 | /// The layer with its seed `ReseedWord(seed, 0)`. | ||
| 72 | LayerPtr Reseeded(std::uint64_t seed) const override; | ||
| 73 | |||
| 74 | 1 | MaterialClass Material() const override { | |
| 75 | 1 | return MaterialClass::Bedrock; | |
| 76 | } | ||
| 77 | /// 1 on the cliffs of hard beds, the top `cliffShare` of each, fading to 0 on the benches; 0 on | ||
| 78 | /// soft beds. | ||
| 79 | /// @throws std::invalid_argument without `context.ground`. | ||
| 80 | double MaterialCoverAt(double x, double y, const LayerContext& context) const override; | ||
| 81 | |||
| 82 | protected: | ||
| 83 | float HeightAt(float height, double x, double y, const LayerContext& context) const override; | ||
| 84 | |||
| 85 | private: | ||
| 86 | /// The bed holding stratigraphic level `level`: its bottom and top levels. | ||
| 87 | struct Bed { | ||
| 88 | double bottom = 0.0; | ||
| 89 | double top = 0.0; | ||
| 90 | bool hard = true; | ||
| 91 | }; | ||
| 92 | Bed BedAt(double level) const; | ||
| 93 | /// The terraced height of ground `height` meters high at world (x, y) on `surface` (m). | ||
| 94 | double TerracedAt(double height, double x, double y, const Surface& surface) const; | ||
| 95 | double BedBoundary(std::int64_t k) const; | ||
| 96 | /// The random stream `stream` of bed `k`. | ||
| 97 | RandomStream BedStream(std::uint32_t stream, std::int64_t k) const; | ||
| 98 | /// The stratigraphic level of ground `height` meters high at (x, y) on `surface`: its height | ||
| 99 | /// less the dipping bed plane. False on the far hemisphere of a body, where the layer does | ||
| 100 | /// nothing. | ||
| 101 | bool StratigraphicLevel(double height, double x, double y, const Surface& surface, | ||
| 102 | double& level) const; | ||
| 103 | |||
| 104 | StrataOptions m_options; | ||
| 105 | Vec2d m_dipDirection{1.0, 0.0}; | ||
| 106 | double m_dipSlope = 0.0; | ||
| 107 | }; | ||
| 108 | |||
| 109 | } // namespace terraingen | ||
| 110 |